Example #1
0
        public int Edit(ClientesViewModel vm)
        {
            var obj = new Clientes();

            if (vm.Id != null || vm.Id != 0)
            {
                obj = _rep.Get(vm.Id);
            }
            else
            {
                obj = _rep.GetClienteByIdUsuario();
            }

            obj.Nome               = vm.Nome;
            obj.Logradouro         = vm.Logradouro;
            obj.Numero             = vm.Numero;
            obj.Cidade             = vm.Cidade;
            obj.Bairro             = vm.Bairro;
            obj.Telefone           = vm.Telefone;
            obj.CEP                = vm.CEP;
            obj.ParametroSanguineo = vm.ParametroSanguineo;
            BeginTransaction();
            _rep.Update(obj);
            return(Commit());
        }
Example #2
0
        public List <ClientesDTO> GetByNome(ClientesModel model)
        {
            var user = _repository.Get(model.NomeCliente);

            if (user == null)
            {
                throw new Exception(Errors.UserNotFound);
            }

            return(user);
        }
Example #3
0
        public async Task <IActionResult> ObterById(int Id)
        {
            if (Id == 0)
            {
                return(BadRequest());
            }

            try
            {
                var response = await clientesRepository.Get(Id);

                if (response == null)
                {
                    var resultNotFound = new
                    {
                        code        = 20000,
                        totalRecord = 0,
                        data        = ""
                    };
                    return(Ok(resultNotFound));
                }
                else
                {
                    var result = new
                    {
                        code = 20000,
                        data = response
                    };

                    return(Ok(result));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
Example #4
0
        public object GetAll()
        {
            var queryValues = Request.RequestUri.ParseQueryString();

            int page  = Convert.ToInt32(queryValues["page"]);
            int start = Convert.ToInt32(queryValues["start"]);
            int limit = Convert.ToInt32(queryValues["limit"]);
            int id    = Convert.ToInt32(queryValues["id"]);

            string query = !string.IsNullOrWhiteSpace(queryValues["query"]) ? queryValues["query"] : "";

            #region Configuramos el orden de la consulta si se obtuvo como parametro
            string strOrder = !string.IsNullOrWhiteSpace(queryValues["sort"]) ? queryValues["sort"] : "";
            strOrder = strOrder.Replace('[', ' ');
            strOrder = strOrder.Replace(']', ' ');

            Sort sort;

            if (!string.IsNullOrWhiteSpace(strOrder))
            {
                sort = JsonConvert.DeserializeObject <Sort>(strOrder);
            }
            else
            {
                sort = new Sort();
            }
            #endregion

            int totalRecords = 0;

            try
            {
                if (id == 0)
                {
                    object          json;
                    IList <Cliente> lista;

                    lista = repository.GetWithQuery(query, sort, page, start, limit, ref totalRecords);

                    json = new
                    {
                        total   = totalRecords,
                        data    = lista,
                        success = true
                    };

                    return(json);
                }
                else
                {
                    Cliente cliente = repository.Get(id);

                    object json = new
                    {
                        total   = totalRecords,
                        data    = cliente,
                        success = true
                    };

                    return(json);
                }
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);

                object error = new { message = ex.Message };

                object json = new
                {
                    message = ex.Message,
                    success = false
                };

                return(json);
            }
        }
 public IHttpActionResult Get()
 {
     return(Ok(_ClientesRepository.Get()));
 }