Example #1
0
        public IActionResult EditCliente(ClienteRequest model)
        {
            Respuesta <object> oRespuesta = new Respuesta <object>();

            try
            {
                using (gdlimatContext db = new gdlimatContext())
                {
                    TblClientes oCliente = db.TblClientes.Find(model.NombreCliente);
                    oCliente.NombreCliente   = model.NombreCliente;
                    oCliente.Contacto        = model.Contacto;
                    oCliente.Direccion       = model.Direccion;
                    oCliente.Telefono        = model.Telefono;
                    oCliente.Email           = model.Email;
                    oCliente.Proyecto        = model.Proyecto;
                    db.Entry(oCliente).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                    db.SaveChanges();
                    oRespuesta.Exito = 1;
                }
            }
            catch (Exception ex)
            {
                oRespuesta.Mensaje = ex.Message;
            }

            return(Ok(oRespuesta));
        }
Example #2
0
        public async Task <ActionResult <ClienteDto> > Put(string idCli, [FromBody] ClienteDto clienteDto)
        {
            if (clienteDto == null)
            {
                BadRequest();
            }

            var cliente = new TblClientes()
            {
                IdCli           = clienteDto.IdCli,
                NumeroDocumento = clienteDto.NumeroDocumento,
                Nombre          = clienteDto.Nombre,
                Direccion       = clienteDto.Direccion,
                Telefono        = clienteDto.Telefono,
                Ciudad          = clienteDto.Ciudad
            };
            //var cuenta = _mapper.Map<Cuenta>(cuentaDto);
            var resultado = await _clienteRepository.Update(cliente);

            if (!resultado)
            {
                NotFound();
            }

            return(clienteDto);
        }
Example #3
0
        public IActionResult AddCliente(ClienteRequest model)
        {
            Respuesta <object> oRespuesta = new Respuesta <object>();

            try
            {
                using (gdlimatContext db = new gdlimatContext())
                {
                    TblClientes oCliente = new TblClientes();
                    oCliente.NombreCliente = model.NombreCliente;
                    oCliente.Contacto      = model.Contacto;
                    oCliente.Direccion     = model.Direccion;
                    oCliente.Telefono      = model.Telefono;
                    oCliente.Email         = model.Email;
                    oCliente.Proyecto      = model.Proyecto;
                    db.TblClientes.Add(oCliente);
                    db.SaveChanges();
                    oRespuesta.Exito = 1;
                }
            }
            catch (Exception ex)
            {
                oRespuesta.Mensaje = ex.Message;
            }

            return(Ok(oRespuesta));
        }
        private void registrarCliente(Cliente cli, Usuario usu)
        {
            try
            {
                TblClientes tblClientes = new TblClientes();
                TblUsuario  tblUsuario  = new TblUsuario();

                tblUsuario.nombreUsuario = usu.nombreUsuario;
                tblUsuario.pass          = usu.pass;
                tblUsuario.fechaRegistro = DateTime.Now;
                tblUsuario.rol           = "C";

                this.entidades.TblUsuario.Add(tblUsuario);
                this.entidades.SaveChanges();
                //----------------------------------------------//
                tblClientes.nombreCompleto = cli.nombreCompleto;
                tblClientes.cedula         = cli.cedula;
                tblClientes.telefono       = cli.telefono;
                tblClientes.email          = cli.email;
                tblClientes.direccion      = cli.direccion;
                tblClientes.idUsuario      = Consultar();

                this.entidades.TblClientes.Add(tblClientes);
                this.entidades.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }//Fin de registrarCliente.
Example #5
0
        /// <exception cref="MyException"></exception>
        public int Inserir(ICliente cliente)
        {
            int retorno;
            var sql = new StringBuilder();
            ITblClientes tblClientes = new TblClientes();

            sql.AppendFormat(" INSERT INTO {0} ({1},{2})", tblClientes.NomeTabela, tblClientes.Nome, tblClientes.StatusId);
            sql.Append(" VALUES (@nome,@status_id);");
            sql.Append(" SET @id=SCOPE_IDENTITY();");

            using (var dal = new DalHelperSqlServer())
            {
                try
                {
                    dal.CriarParametroDeEntrada("nome", SqlDbType.Char, cliente.Nome);
                    dal.CriarParametroDeEntrada("status_id", SqlDbType.SmallInt, cliente.Status.GetHashCode());
                    var parametroDeSaida = dal.CriarParametroDeSaida("id", SqlDbType.Int);

                    dal.ExecuteNonQuery(sql.ToString());
                    retorno = Convert.ToInt32(parametroDeSaida.Value);
                }
                catch (SqlException) { throw new MyException("Operação não realizada, por favor, tente novamente!"); }
            }

            return retorno;
        }
Example #6
0
        public async Task <ActionResult> Delete(TblClientes id)
        {
            await _clienteRepository.Remove(id);

            //if (tblClientes == null)
            //{
            //    return NotFound();
            //}

            //_context.TblClientes.Remove(tblClientes);
            //await _context.SaveChangesAsync();

            return(Ok());
        }
Example #7
0
        public IActionResult DeleteCliente(string NombreCliente)
        {
            Respuesta <object> oRespuesta = new Respuesta <object>();

            try
            {
                using (gdlimatContext db = new gdlimatContext())
                {
                    TblClientes oCliente = db.TblClientes.Find(NombreCliente);
                    db.Remove(oCliente);
                    db.SaveChanges();
                    oRespuesta.Exito = 1;
                }
            }
            catch (Exception ex)
            {
                oRespuesta.Mensaje = ex.Message;
            }

            return(Ok(oRespuesta));
        }
Example #8
0
        public async Task <ActionResult <ClienteDto> > Post(ClienteDto clienteDto)
        {
            if (clienteDto == null)
            {
                BadRequest();
            }

            var cliente = new TblClientes()
            {
                IdCli           = clienteDto.IdCli,
                NumeroDocumento = clienteDto.NumeroDocumento,
                Nombre          = clienteDto.Nombre,
                Direccion       = clienteDto.Direccion,
                Telefono        = clienteDto.Telefono,
                Ciudad          = clienteDto.Ciudad
            };

            var resultado = await _clienteRepository.Add(cliente);

            return(StatusCode(200, "Cliente creado"));
        }
Example #9
0
        /// <exception cref="MyException"></exception>
        public bool ExisteNomenclaturaInformada(ICliente cliente)
        {
            bool resultado;
            var sql = new StringBuilder();
            ITblClientes tblClientes = new TblClientes();

            sql.AppendFormat(" SELECT {0}", tblClientes.Id);
            sql.AppendFormat(" FROM {0}", tblClientes.NomeTabela);
            sql.AppendFormat(" WHERE {0}=@nome;", tblClientes.Nome);

            using (var dal = new DalHelperSqlServer())
            {
                try
                {
                    dal.CriarParametroDeEntrada("nome", SqlDbType.Char, cliente.Nome);

                    resultado = Convert.ToBoolean(dal.ExecuteScalar(sql.ToString()));//Null ou 0 (Zero) = False; > 0 (Zero) = True;
                }
                catch (SqlException)
                { throw new MyException("Operação não realizada, por favor, tente novamente!"); }
            }

            return resultado;
        }
Example #10
0
        /// <exception cref="MyException"></exception>
        public IList<ICliente> Listar(Status status)
        {
            var clientes = new List<ICliente>();
            var sql = new StringBuilder();
            ITblClientes tblClientes = new TblClientes();

            sql.AppendFormat(" SELECT DISTINCT {0}, {1}, {2}", tblClientes.Id, tblClientes.Nome, tblClientes.StatusId);
            sql.AppendFormat(" FROM {0}", tblClientes.NomeTabela);
            sql.AppendFormat(" WHERE {0}=@status_id", tblClientes.StatusId);
            sql.AppendFormat(" ORDER BY {0};", tblClientes.Nome);

            using (var dal = new DalHelperSqlServer())
            {
                try
                {
                    dal.CriarParametroDeEntrada("status_id", SqlDbType.SmallInt, status.GetHashCode());

                    using (var dr = dal.ExecuteReader(sql.ToString()))
                    {
                        while (dr.Read())
                        {
                            clientes.Add(FactoryCliente.Manufacture(
                                dr.GetInt32(0),
                                dr.GetString(1),
                                (Status)dr.GetInt16(2)));
                        }
                        dr.Close();
                    }
                }
                catch (SqlException) { throw new MyException("Operação não realizada, por favor, tente novamente!"); }
            }

            return clientes;
        }