public bool update(ProyectoDTO Proyecto) { using (var context = getContext()) { try { var row = context.Proyecto.Where(x => x.IdProyecto == Proyecto.IdProyecto).SingleOrDefault(); row.IdEntidadResponsable = Proyecto.IdEntidadResponsable; row.IdResponsable = Proyecto.IdResponsable; row.Nombre = Proyecto.Nombre; row.Descripcion = Proyecto.Descripcion; row.Estado = Proyecto.Estado; context.SaveChanges(); return true; } catch (Exception e) { throw e; } } }
public bool add(ProyectoDTO Proyecto) { using (var context = getContext()) { try { Proyecto nuevo = new Proyecto(); nuevo.Nombre = Proyecto.Nombre; nuevo.IdEntidadResponsable = Proyecto.IdEntidadResponsable; nuevo.IdResponsable = Proyecto.IdResponsable; nuevo.Estado = true; nuevo.Descripcion = Proyecto.Descripcion; context.Proyecto.Add(nuevo); context.SaveChanges(); return true; } catch (Exception e) { throw e; } } }
public ActionResult AddProyecto(ProyectoDTO dto) { if (!this.currentUser()) { return RedirectToAction("Ingresar"); } try { ProyectoBL objBL = new ProyectoBL(); if (dto.IdProyecto == 0) { if (objBL.add(dto)) { //objBL.ActualizarSaldos(dto.IdCuentaBancaria); createResponseMessage(CONSTANTES.SUCCESS); return RedirectToAction("Entidad", new { id = dto.IdEntidadResponsable }); } } else if (dto.IdProyecto != 0) { if (objBL.update(dto)) { //objBL.ActualizarSaldos(dto.IdCuentaBancaria); createResponseMessage(CONSTANTES.SUCCESS); return RedirectToAction("Entidad", new { id = dto.IdEntidadResponsable }); } else { createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_UPDATE_MESSAGE); } } else { createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_INSERT_MESSAGE); } } catch (Exception e) { if (dto.IdProyecto != 0) createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_UPDATE_MESSAGE); else createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_INSERT_MESSAGE); } TempData["Proyecto"] = dto; return RedirectToAction("Proyecto"); }
public ActionResult Proyecto(int? id = null, int? idEntidad = null) { if (!this.currentUser()) { return RedirectToAction("Ingresar"); } //if (!this.isAdministrator()) { return RedirectToAction("Index"); } ViewBag.Title = "Proyecto"; MenuNavBarSelected(6); UsuarioDTO user = getCurrentUser(); ProyectoBL objBL = new ProyectoBL(); ViewBag.IdProyecto = id; ViewBag.lstComprobantes = objBL.getComprobantes_ConProyecto(user.IdEmpresa, id.GetValueOrDefault()); ResponsableBL resBL = new ResponsableBL(); ViewBag.lstResponsables = resBL.getResponsablesActivosEnEmpresa(user.IdEmpresa); EntidadResponsableBL objEntidadBL = new EntidadResponsableBL(); EntidadResponsableDTO objEntidad = objEntidadBL.getEntidadResponsableEnEmpresa(user.IdEmpresa, idEntidad.GetValueOrDefault()); if (objEntidad == null) { return RedirectToAction("EntidadesClientes", "Admin"); } var objSent = TempData["Proyecto"]; if (objSent != null) { TempData["Proyecto"] = null; return View(objSent); } if (id == 0 && idEntidad != null) { ProyectoDTO nuevo = new ProyectoDTO(); nuevo.IdEntidadResponsable = (int)idEntidad; nuevo.Estado = true; return View(nuevo); } else { if (id != null) { ProyectoDTO obj = objBL.getProyecto((int)id); if (obj == null) return RedirectToAction("Entidad", "Admin", new { id = objEntidad.IdEntidadResponsable }); if (obj.IdEntidadResponsable != objEntidad.IdEntidadResponsable) return RedirectToAction("Entidad", "Admin", new { id = objEntidad.IdEntidadResponsable }); EntidadResponsableDTO objEntidadProy = objEntidadBL.getEntidadResponsableEnEmpresa(user.IdEmpresa, obj.IdEntidadResponsable); if (objEntidadProy == null) return RedirectToAction("Entidades", "Admin"); if (objEntidadProy.IdEmpresa != user.IdEmpresa) return RedirectToAction("Entidades", "Admin"); return View(obj); } } return View(); }