public bool guardarDB(ro_empleado_proyeccion_gastos_Info info) { try { using (Entities_rrhh Context = new Entities_rrhh()) { ro_empleado_proyeccion_gastos Entity = new ro_empleado_proyeccion_gastos { IdEmpresa = info.IdEmpresa, IdTransaccion = info.IdTransaccion = get_id(info.IdEmpresa), IdEmpleado = info.IdEmpleado, AnioFiscal = info.AnioFiscal, Observacion = info.Observacion, estado = true, Fecha_Transac = DateTime.Now }; Context.ro_empleado_proyeccion_gastos.Add(Entity); foreach (var item in info.list_proyeciones) { ro_empleado_proyeccion_gastos_det Entity_det = new ro_empleado_proyeccion_gastos_det { IdEmpresa = info.IdEmpresa, IdTransaccion = info.IdTransaccion, IdTipoGasto = item.IdTipoGasto, Valor = item.Valor, Observacion = item.Observacion, Secuencia = item.Secuencia }; Context.ro_empleado_proyeccion_gastos_det.Add(Entity_det); } Context.SaveChanges(); } return(true); } catch (Exception) { throw; } }
public bool modificarDB(ro_empleado_proyeccion_gastos_Info info) { try { using (Entities_rrhh Context = new Entities_rrhh()) { ro_empleado_proyeccion_gastos Entity = Context.ro_empleado_proyeccion_gastos.FirstOrDefault(q => q.IdEmpresa == info.IdEmpresa && q.IdTransaccion == info.IdTransaccion); if (Entity == null) { return(false); } Entity.Observacion = info.Observacion; Entity.IdEmpleado = info.IdEmpleado; Entity.AnioFiscal = info.AnioFiscal; var select = Context.ro_empleado_proyeccion_gastos_det.Where(q => q.IdEmpresa == info.IdEmpresa && q.IdTransaccion == info.IdTransaccion); Context.ro_empleado_proyeccion_gastos_det.RemoveRange(select); foreach (var item in info.list_proyeciones) { ro_empleado_proyeccion_gastos_det Entity_det = new ro_empleado_proyeccion_gastos_det { IdEmpresa = info.IdEmpresa, IdTransaccion = info.IdTransaccion, IdTipoGasto = item.IdTipoGasto, Valor = item.Valor, Observacion = item.Observacion, Secuencia = item.Secuencia }; Context.ro_empleado_proyeccion_gastos_det.Add(Entity_det); } Context.SaveChanges(); } return(true); } catch (Exception) { throw; } }