﻿
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Data;
    using System.Linq;
    using System.Data.SqlClient;
    using Softv.Entities;
    using Softv.Providers;
    using SoftvConfiguration;
    using Globals;

    namespace Softv.DAO
    {
    /// <summary>
    /// Class                   : Softv.DAO.ClienteNoContestoData
    /// Generated by            : Class Generator (c) 2014
    /// Description             : ClienteNoContesto Data Access Object
    /// File                    : ClienteNoContestoDAO.cs
    /// Creation date           : 18/08/2016
    /// Creation time           : 10:58 a. m.
    ///</summary>
    public class ClienteNoContestoData : ClienteNoContestoProvider
    {
    /// <summary>
    ///</summary>
    /// <param name="ClienteNoContesto"> Object ClienteNoContesto added to List</param>
    public override int AddClienteNoContesto(ClienteNoContestoEntity entity_ClienteNoContesto)
    {
    int result=0;
    using(SqlConnection connection = new SqlConnection(SoftvSettings.Settings.ClienteNoContesto.ConnectionString))
    {
    
    SqlCommand comandoSql = CreateCommand("Softv_ClienteNoContestoAdd", connection);
    
        AssingParameter(comandoSql, "@IdNoContesto", null, pd: ParameterDirection.Output, IsKey: true);
      
            AssingParameter(comandoSql,"@IdProcesoEnc",entity_ClienteNoContesto.IdProcesoEnc);
          
            AssingParameter(comandoSql,"@IdEncuesta",entity_ClienteNoContesto.IdEncuesta);
          
            AssingParameter(comandoSql,"@Contrato",entity_ClienteNoContesto.Contrato);
          
            AssingParameter(comandoSql,"@FechaApli",entity_ClienteNoContesto.FechaApli);
          
            AssingParameter(comandoSql,"@IdPlaza",entity_ClienteNoContesto.IdPlaza);
          
    try
    {
    if (connection.State == ConnectionState.Closed)
    connection.Open();
    result = ExecuteNonQuery(comandoSql);
    }
    catch (Exception ex)
    {
    throw new Exception("Error adding ClienteNoContesto " + ex.Message, ex);
    }
    finally
    {
    connection.Close();
    }
    result = (int)comandoSql.Parameters["@IdNoContesto"].Value;
    }
    return result;
    }

    /// <summary>
    /// Deletes a ClienteNoContesto
    ///</summary>
    /// <param name="">  IdNoContesto to delete </param>
    public override int DeleteClienteNoContesto(int? IdNoContesto)
    {
    int result=0;
    using(SqlConnection connection = new SqlConnection(SoftvSettings.Settings.ClienteNoContesto.ConnectionString))
    {
    
    SqlCommand comandoSql = CreateCommand("Softv_ClienteNoContestoDelete", connection);
    
            AssingParameter(comandoSql,"@IdNoContesto",IdNoContesto);
          
    try
    {
    if (connection.State == ConnectionState.Closed)
    connection.Open();
    result = ExecuteNonQuery(comandoSql);
    }
    catch (Exception ex)
    {
    throw new Exception("Error deleting ClienteNoContesto " + ex.Message, ex);
    }
    finally
    {
    if(connection != null)
    connection.Close();
    }
    }
    return result;
    }

    /// <summary>
    /// Edits a ClienteNoContesto
    ///</summary>
    /// <param name="ClienteNoContesto"> Objeto ClienteNoContesto a editar </param>
    public override int EditClienteNoContesto(ClienteNoContestoEntity entity_ClienteNoContesto)
    {
    int result=0;
    using(SqlConnection connection = new SqlConnection(SoftvSettings.Settings.ClienteNoContesto.ConnectionString))
    {
    
    SqlCommand comandoSql = CreateCommand("Softv_ClienteNoContestoEdit", connection);
    
            AssingParameter(comandoSql,"@IdNoContesto",entity_ClienteNoContesto.IdNoContesto);
          
            AssingParameter(comandoSql,"@IdProcesoEnc",entity_ClienteNoContesto.IdProcesoEnc);
          
            AssingParameter(comandoSql,"@IdEncuesta",entity_ClienteNoContesto.IdEncuesta);
          
            AssingParameter(comandoSql,"@Contrato",entity_ClienteNoContesto.Contrato);
          
            AssingParameter(comandoSql,"@FechaApli",entity_ClienteNoContesto.FechaApli);
          
            AssingParameter(comandoSql,"@IdPlaza",entity_ClienteNoContesto.IdPlaza);
          
    try
    {
    if (connection.State == ConnectionState.Closed)
    connection.Open();
    
        result = int.Parse(ExecuteNonQuery(comandoSql).ToString());
          
    }
    catch (Exception ex)
    {
    throw new Exception("Error updating ClienteNoContesto " + ex.Message, ex);
    }
    finally
    {
    if(connection != null)
    connection.Close();
    }
    }
    return result;
    }

    /// <summary>
    /// Gets all ClienteNoContesto
    ///</summary>
    public override List<ClienteNoContestoEntity> GetClienteNoContesto()
    {
    List<ClienteNoContestoEntity> ClienteNoContestoList = new List<ClienteNoContestoEntity>();
    using(SqlConnection connection = new SqlConnection(SoftvSettings.Settings.ClienteNoContesto.ConnectionString))
    {
    
    SqlCommand comandoSql = CreateCommand("Softv_ClienteNoContestoGet", connection);
    IDataReader rd = null;
    try
    {
    if (connection.State == ConnectionState.Closed)
    connection.Open();
    rd = ExecuteReader(comandoSql);

    while (rd.Read())
    {
    ClienteNoContestoList.Add(GetClienteNoContestoFromReader(rd));
    }
    }
    catch (Exception ex)
    {
    throw new Exception("Error getting data ClienteNoContesto "  + ex.Message, ex);
    }
    finally
    {
    if(connection!=null)
    connection.Close();
    if(rd != null)
    rd.Close();
    }
    }
    return ClienteNoContestoList;
    }

    /// <summary>
    /// Gets all ClienteNoContesto by List<int>
    ///</summary>
    public override List<ClienteNoContestoEntity> GetClienteNoContesto(List<int> lid)
    {
    List<ClienteNoContestoEntity> ClienteNoContestoList = new List<ClienteNoContestoEntity>();
    using(SqlConnection connection = new SqlConnection(SoftvSettings.Settings.ClienteNoContesto.ConnectionString))
    {
    DataTable IdDT = BuildTableID(lid);
    
    SqlCommand comandoSql = CreateCommand("Softv_ClienteNoContestoGetByIds", connection);
    AssingParameter(comandoSql, "@IdTable", IdDT);
    
    IDataReader rd = null;
    try
    {
    if (connection.State == ConnectionState.Closed)
    connection.Open();
    rd = ExecuteReader(comandoSql);

    while (rd.Read())
    {
    ClienteNoContestoList.Add(GetClienteNoContestoFromReader(rd));
    }
    }
    catch (Exception ex)
    {
    throw new Exception("Error getting data ClienteNoContesto "  + ex.Message, ex);
    }
    finally
    {
    if(connection!=null)
    connection.Close();
    if(rd != null)
    rd.Close();
    }
    }
    return ClienteNoContestoList;
    }

    /// <summary>
    /// Gets ClienteNoContesto by
    ///</summary>
    public override ClienteNoContestoEntity GetClienteNoContestoById(int? IdNoContesto)
    {
    using(SqlConnection connection = new SqlConnection(SoftvSettings.Settings.ClienteNoContesto.ConnectionString))
    {
    
    SqlCommand comandoSql = CreateCommand("Softv_ClienteNoContestoGetById", connection);
    ClienteNoContestoEntity entity_ClienteNoContesto = null;

    
            AssingParameter(comandoSql,"@IdNoContesto", IdNoContesto);
          
    IDataReader rd = null;
    try
    {
    if (connection.State == ConnectionState.Closed)
    connection.Open();
    rd = ExecuteReader(comandoSql, CommandBehavior.SingleRow);
    if (rd.Read())
    entity_ClienteNoContesto = GetClienteNoContestoFromReader(rd);
    }
    catch (Exception ex)
    {
    throw new Exception("Error getting data ClienteNoContesto "  + ex.Message, ex);
    }
    finally
    {
    if(connection!=null)
    connection.Close();
    if(rd != null)
    rd.Close();
    }
    return entity_ClienteNoContesto;
    }

    }

    

    /// <summary>
    ///Get ClienteNoContesto
    ///</summary>
    public override SoftvList<ClienteNoContestoEntity> GetPagedList(int pageIndex, int pageSize)
    {
    SoftvList<ClienteNoContestoEntity> entities = new SoftvList<ClienteNoContestoEntity>();
    using (SqlConnection connection = new SqlConnection(SoftvSettings.Settings.ClienteNoContesto.ConnectionString))
    {
    
    SqlCommand comandoSql = CreateCommand("Softv_ClienteNoContestoGetPaged", connection);
    
    AssingParameter(comandoSql,"@pageIndex", pageIndex);
    AssingParameter(comandoSql,"@pageSize", pageSize);
    IDataReader rd = null;
    try
    {
    if (connection.State == ConnectionState.Closed)
    connection.Open();
    rd = ExecuteReader(comandoSql);
    while (rd.Read())
    {
    entities.Add(GetClienteNoContestoFromReader(rd));
    }
    }
    catch (Exception ex)
    {
    throw new Exception("Error getting data ClienteNoContesto " + ex.Message, ex);
    }
    finally
    {
    if (connection != null)
    connection.Close();
    if (rd != null)
    rd.Close();
    }
    entities.totalCount = GetClienteNoContestoCount();
    return entities ?? new SoftvList<ClienteNoContestoEntity>();
    }
    }

    /// <summary>
    ///Get ClienteNoContesto
    ///</summary>
    public override SoftvList<ClienteNoContestoEntity> GetPagedList(int pageIndex, int pageSize,String xml)
    {
    SoftvList<ClienteNoContestoEntity> entities = new SoftvList<ClienteNoContestoEntity>();
    using (SqlConnection connection = new SqlConnection(SoftvSettings.Settings.ClienteNoContesto.ConnectionString))
    {
    
    SqlCommand comandoSql = CreateCommand("Softv_ClienteNoContestoGetPagedXml", connection);
    
    AssingParameter(comandoSql,"@pageSize", pageSize);
    AssingParameter(comandoSql,"@pageIndex", pageIndex);
    AssingParameter(comandoSql,"@xml", xml);
    IDataReader rd = null;
    try
    {
    if (connection.State == ConnectionState.Closed)
    connection.Open();
    rd = ExecuteReader(comandoSql);
    while (rd.Read())
    {
    entities.Add(GetClienteNoContestoFromReader(rd));
    }
    }
    catch (Exception ex)
    {
    throw new Exception("Error getting data ClienteNoContesto " + ex.Message, ex);
    }
    finally
    {
    if (connection != null)
    connection.Close();
    if (rd != null)
    rd.Close();
    }
    entities.totalCount = GetClienteNoContestoCount(xml);
    return entities ?? new SoftvList<ClienteNoContestoEntity>();
    }
    }

    /// <summary>
    ///Get Count ClienteNoContesto
    ///</summary>
    public int GetClienteNoContestoCount()
    {
    int result = 0;
    using (SqlConnection connection = new SqlConnection(SoftvSettings.Settings.ClienteNoContesto.ConnectionString))
    {
    
    SqlCommand comandoSql = CreateCommand("Softv_ClienteNoContestoGetCount", connection);
    try
    {
    if (connection.State == ConnectionState.Closed)
    connection.Open();
    result = (int)ExecuteScalar(comandoSql);


    }
    catch (Exception ex)
    {
    throw new Exception("Error getting data ClienteNoContesto " + ex.Message, ex);
    }
    finally
    {
    if (connection != null)
    connection.Close();
    }
    }
    return result;
    }


    /// <summary>
    ///Get Count ClienteNoContesto
    ///</summary>
    public int GetClienteNoContestoCount(String xml)
    {
    int result = 0;
    using (SqlConnection connection = new SqlConnection(SoftvSettings.Settings.ClienteNoContesto.ConnectionString))
    {
    
    SqlCommand comandoSql = CreateCommand("Softv_ClienteNoContestoGetCountXml", connection);
    
    AssingParameter(comandoSql,"@xml", xml);
    try
    {
    if (connection.State == ConnectionState.Closed)
    connection.Open();
    result = (int)ExecuteScalar(comandoSql);


    }
    catch (Exception ex)
    {
    throw new Exception("Error getting data ClienteNoContesto " + ex.Message, ex);
    }
    finally
    {
    if (connection != null)
    connection.Close();
    }
    }
    return result;
    }

    #region Customs Methods
    
    #endregion
    }
    }
  