public async Task <IActionResult> EditGastoPersonal(GastoPersonal gastoPersonal) { Response response = new Response(); try { if (ObtenerGastoPersonal().IdEmpleado > 0) { gastoPersonal.IdEmpleado = ObtenerGastoPersonal().IdEmpleado; response = await apiServicio.EditarAsync <Response>(gastoPersonal, new Uri(WebApp.BaseAddress), "api/GastoPersonal/EditarGastoPersonal"); if (response.IsSuccess) { return(this.Redireccionar("GastoPersonal", "GastoPersonalIndex", new { id = ObtenerGastoPersonal().IdEmpleado }, $"{Mensaje.Informacion}|{Mensaje.Satisfactorio}")); } this.TempData["Mensaje"] = $"{Mensaje.Error}|{response.Message}"; await CargarCombox(); return(View(gastoPersonal)); } return(this.Redireccionar($"{Mensaje.Error}|{Mensaje.ErrorCargarDatos}")); } catch (Exception) { return(this.Redireccionar($"{Mensaje.Error}|{Mensaje.ErrorCargarDatos}")); } }
public async Task <Response> ObtenerGastoPersonal([FromBody] GastoPersonal GastoPersonal) { try { var gastoPersonal = await db.GastoPersonal.SingleOrDefaultAsync(m => m.IdGastoPersonal == GastoPersonal.IdGastoPersonal); if (gastoPersonal == null) { return(new Response { IsSuccess = false, Message = Mensaje.RegistroNoEncontrado, }); } return(new Response { IsSuccess = true, Message = Mensaje.Satisfactorio, Resultado = gastoPersonal, }); } catch (Exception) { return(new Response { IsSuccess = false, Message = Mensaje.Error, }); } }
public async Task <IActionResult> EditGastoPersonal(string id) { try { if (!string.IsNullOrEmpty(id)) { var gastoPersonal = new GastoPersonal { IdGastoPersonal = Convert.ToInt32(id) }; var respuesta = await apiServicio.ObtenerElementoAsync1 <Response>(gastoPersonal, new Uri(WebApp.BaseAddress), "api/GastoPersonal/ObtenerGastoPersonal"); if (respuesta.IsSuccess) { var vista = JsonConvert.DeserializeObject <GastoPersonal>(respuesta.Resultado.ToString()); await CargarCombox(); return(View(vista)); } } return(this.Redireccionar($"{Mensaje.Error}|{Mensaje.ErrorCargarDatos}")); } catch (Exception) { return(this.Redireccionar($"{Mensaje.Error}|{Mensaje.ErrorCargarDatos}")); } }
public async Task <IActionResult> DeleteConceptoConjunto(string id) { try { if (string.IsNullOrEmpty(id)) { return(this.Redireccionar($"{Mensaje.Error}|{Mensaje.RegistroNoExiste}")); } var gastoPersonal = new GastoPersonal { IdGastoPersonal = Convert.ToInt32(id) }; var response = await apiServicio.EliminarAsync(gastoPersonal, new Uri(WebApp.BaseAddress) , "api/GastoPersonal/EliminarGastoPersonal"); if (response.IsSuccess) { return(this.Redireccionar("GastoPersonal", "GastoPersonalIndex", new { id = ObtenerGastoPersonal().IdEmpleado }, $"{Mensaje.Informacion}|{Mensaje.Satisfactorio}")); } return(this.Redireccionar($"{Mensaje.Error}|{Mensaje.BorradoNoSatisfactorio}")); } catch (Exception) { return(this.Redireccionar($"{Mensaje.Error}|{Mensaje.ErrorEliminar}")); } }
public async Task <Response> EliminarGastoPersonal([FromBody] GastoPersonal GastoPersonal) { try { var respuesta = await db.GastoPersonal.Where(m => m.IdGastoPersonal == GastoPersonal.IdGastoPersonal).FirstOrDefaultAsync(); if (respuesta == null) { return(new Response { IsSuccess = false, Message = Mensaje.RegistroNoEncontrado, }); } db.GastoPersonal.Remove(respuesta); await db.SaveChangesAsync(); return(new Response { IsSuccess = true, Message = Mensaje.Satisfactorio, }); } catch (Exception ex) { return(new Response { IsSuccess = false, Message = Mensaje.BorradoNoSatisfactorio, }); } }
public async Task <Response> PostGastoPersonal([FromBody] GastoPersonal GastoPersonal) { try { if (!await Existe(GastoPersonal)) { db.GastoPersonal.Add(GastoPersonal); await db.SaveChangesAsync(); return(new Response { IsSuccess = true, Message = Mensaje.Satisfactorio, Resultado = GastoPersonal, }); } return(new Response { IsSuccess = false, Message = Mensaje.ExisteRegistro }); } catch (Exception ex) { return(new Response { IsSuccess = false, Message = Mensaje.Error, }); } }
public GastoPersonal ObtenerGastoPersonal() { var gastoPersonal = new GastoPersonal { IdEmpleado = Convert.ToInt32(HttpContext.Session.GetInt32(Constantes.IdEmpleadoGastoPersonal)), }; return(gastoPersonal); }
public List <GastoPersonal> ListarAnosGastoPersonal([FromBody] GastoPersonal gastoPersonal) { try { return(db.GastoPersonal.Where(x => x.IdEmpleado == gastoPersonal.IdEmpleado).DistinctBy(x => x.Ano).OrderBy(x => x.Ano).ToList()); } catch (Exception ex) { return(new List <GastoPersonal>()); } }
public async Task <List <GastoPersonal> > BuscarHistorico([FromBody] GastoPersonal gastoPersonal) { try { return(await db.GastoPersonal.Where(x => x.IdEmpleado == gastoPersonal.IdEmpleado && x.Ano == gastoPersonal.Ano).Include(x => x.TipoDeGastoPersonal).ToListAsync()); } catch (Exception ex) { return(new List <GastoPersonal>()); } }
public async Task <List <GastoPersonal> > ListarGastoPersonal([FromBody] GastoPersonal gastoPersonal) { try { var a = await db.GastoPersonal.Where(x => x.Ano == gastoPersonal.Ano && x.IdEmpleado == gastoPersonal.IdEmpleado).OrderBy(x => x.TipoDeGastoPersonal.Descripcion).Include(x => x.TipoDeGastoPersonal).ToListAsync(); return(a); } catch (Exception ex) { return(new List <GastoPersonal>()); } }
private async Task <bool> Existe(GastoPersonal GastoPersonal) { var tipoGasto = GastoPersonal.IdTipoGastoPersonal; var ano = GastoPersonal.Ano; var GastoPersonalrespuesta = await db.GastoPersonal.Where(p => p.IdTipoGastoPersonal == tipoGasto && p.Ano == ano && p.IdEmpleado == GastoPersonal.IdEmpleado).FirstOrDefaultAsync(); if (GastoPersonalrespuesta == null || GastoPersonalrespuesta.IdGastoPersonal == GastoPersonal.IdGastoPersonal) { return(false); } else { return(true); } }
public async Task <Response> EditarGastoPersonal([FromBody] GastoPersonal GastoPersonal) { try { if (await Existe(GastoPersonal)) { return(new Response { IsSuccess = false, Message = Mensaje.ExisteRegistro, }); } var GastoPersonalActualizar = await db.GastoPersonal.Where(x => x.IdGastoPersonal == GastoPersonal.IdGastoPersonal).FirstOrDefaultAsync(); if (GastoPersonalActualizar == null) { return(new Response { IsSuccess = false, }); } GastoPersonalActualizar.Valor = GastoPersonal.Valor; GastoPersonalActualizar.IdTipoGastoPersonal = GastoPersonal.IdTipoGastoPersonal; db.GastoPersonal.Update(GastoPersonalActualizar); await db.SaveChangesAsync(); return(new Response { IsSuccess = true, Resultado = GastoPersonalActualizar }); } catch (Exception) { return(new Response { IsSuccess = false, Message = Mensaje.Excepcion }); } }