public JsonResult Get(int id) { GastoModel gasto = new GastoModel(); using (Data.FinanzasPersonales DB = new Data.FinanzasPersonales()) { var fromDbGasto = DB.t_Gastos.Where(g => g.id_gasto == id).FirstOrDefault(); if (fromDbGasto == null) { Response.StatusCode = 404; return(Json(new ResponseResult() { Success = false, Data = "Not found" })); } else { gasto = new GastoModel() { id_gasto = fromDbGasto.id_gasto, categoria = fromDbGasto.id_cat, justificacion = fromDbGasto.justificacion, fecha = fromDbGasto.fecha, valor = fromDbGasto.valor }; } } return(Json(gasto)); }
public bool Ejecutar(GastoModel param) { using (AplicacionesEntities db = new AplicacionesEntities()) { var e = CrearEtiquetas(param.Etiquetas, db); if (param.Fecha == null) { param.Fecha = DateTime.UtcNow; } var aux = new Data.Gastos { Descorta = param.Descorta, Fecha = param.Fecha.Value, Importe = float.Parse(param.Importe.Replace('.', ',')), IdEtiqueta = e.IdEtiqueta }; db.Gastos.Add(aux); db.SaveChanges(); return(true); } }
static public List <GastoModel> GetGasto() { try { string strQuery = "SELECT * FROM [gas_gasto]"; List <GastoBD> lst = App.BDLocal.DBConnection.Query <GastoBD>(strQuery); if (lst.Count == 0) { return(null); } GastoModel novo; List <GastoModel> lstModel = new List <GastoModel>(); foreach (GastoBD g in lst) { novo = new GastoModel(g.Gas_Codigo, g.Gas_Descricao, g.Gas_DataHora, g.Gas_Valor, g.Gas_TigCodigo); lstModel.Add(novo); } // ordena a lista em ordem alfabética lstModel.Sort(); return(lstModel); } catch (Exception) { return(null); } }
public async Task <IActionResult> Insert(GastoModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var gasto = _mapper.Map <GastoDto>(model); await _gastoRepositorio.Insertar(gasto); return(Ok(model)); }
async void Agenda_ItemTapped(object sender, ItemTappedEventArgs e) { // obtem item selecionado GastoModel item = (GastoModel)e.Item; if (item == null) { return; } // abrir view para edição do item selecionado await Navigation.PushAsync(new GastoAdd(item)); }
public async Task <IActionResult> Edit(long id, GastoModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var gasto = _mapper.Map <GastoDto>(model); gasto.Id = id; await _gastoRepositorio.Modificar(gasto); return(Ok(model)); }
// POST: api/Gasto /// <summary> /// Metodo de inserção de gasto /// </summary> /// <param name="gasto"></param> public HttpStatusCode Post(GastoModel gasto) { try { gastoBLL.AddGasto(gasto); return(HttpStatusCode.OK); } catch (Exception ex) { var resp = new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent(string.Format(ex.Message)), ReasonPhrase = "Gasto não encontrado", StatusCode = HttpStatusCode.NotFound }; throw new HttpResponseException(resp); } }
// PUT: api/Gasto/5 /// <summary> /// Metodo de alteração de Gasto /// </summary> /// <param name="gasto"></param> public void Put(GastoModel gasto) { var item = gastoBLL.GetById(gasto.Id); if (item == null) { var resp = new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent(string.Format("Não existe um Gasto com o id = {0}", gasto.Id)), ReasonPhrase = "Gasto não encontrado", StatusCode = HttpStatusCode.NotFound }; throw new HttpResponseException(resp); } else { gastoBLL.Update(gasto); } }
public void Update(GastoModel gasto) { gastoRepository.Update(gasto); }
public void AddGasto(GastoModel gasto) { gastoRepository.Add(gasto); }
public JsonResult Edit(GastoModel model) { if (ModelState.IsValid) { //Save using (Data.FinanzasPersonales DB = new Data.FinanzasPersonales()) { var presInfo = (from p in DB.t_presupuesto join c in DB.t_cuenta_pres on p.id_pres equals c.id_pres where (p.Desde <= model.fecha && p.Hasta >= model.fecha) && c.id_cat == model.categoria select new { Desde = p.Desde, Hasta = p.Hasta, id_pres = p.id_pres, id_cuent = c.id_cuent, id_cat = c.id_cat, Limite = c.Limite }).FirstOrDefault(); if (presInfo is null) { return(Json(new ResponseResult() { Success = false, Data = new List <ValidationResult>() { new ValidationResult() { Key = "id_gasto", Errors = new ModelErrorCollection() { "No existe una cuenta presupuestaria con esta categoría de gasto que abarque esta fecha" } } } } )); } var gastosCat = DB.t_Gastos.Where(g => (g.fecha >= presInfo.Desde && g.fecha <= presInfo.Hasta) && g.id_cat == model.categoria && g.id_gasto != model.id_gasto).ToList(); decimal gastado = (gastosCat.Count == 0 ? 0 : gastosCat.Sum(g => g.valor)); decimal disponible = presInfo.Limite - gastado; if (model.valor > disponible) { return(Json(new ResponseResult() { Success = false, Data = new List <ValidationResult>() { new ValidationResult() { Key = "id_gasto", Errors = new ModelErrorCollection() { "El valor de este gasto excede el disponible de la cuenta presupuestaria" } } } } )); } Data.t_Gastos gasto = DB.t_Gastos.Where(g => g.id_gasto == model.id_gasto).FirstOrDefault(); gasto.id_cat = model.categoria; gasto.fecha = model.fecha; gasto.justificacion = model.justificacion; gasto.valor = model.valor; DB.SaveChanges(); } return(Json(new ResponseResult() { Success = true, Data = Validations.GetErrors(ModelState) })); } else { //Reject return(Json(new ResponseResult() { Success = false, Data = Validations.GetErrors(ModelState) })); } }