public ActionResult AddServicio(ServicioDTO dto) { if (!this.currentUser()) { return RedirectToAction("Ingresar"); } if (!this.isAdministrator()) { return RedirectToAction("Index"); } try { ServicioBL objBL = new ServicioBL(); if (dto.IdServicio == 0) { if (objBL.add(dto)) { createResponseMessage(CONSTANTES.SUCCESS); return RedirectToAction("Servicios"); } } else if (dto.IdServicio != 0) { if (objBL.update(dto)) { createResponseMessage(CONSTANTES.SUCCESS); return RedirectToAction("Servicios"); } else { createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_UPDATE_MESSAGE); } } else { createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_INSERT_MESSAGE); } } catch (Exception e) { if (dto.IdServicio != 0) createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_UPDATE_MESSAGE); else createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_INSERT_MESSAGE); } TempData["Servicio"] = dto; return RedirectToAction("Servicio"); }
public bool add(ServicioDTO Servicio) { using (var context = getContext()) { try { Servicio nuevo = new Servicio(); nuevo.IdMoneda = Servicio.IdMoneda; nuevo.Codigo = Servicio.Codigo; nuevo.Nombre = Servicio.Nombre; nuevo.Precio = Servicio.Precio; nuevo.Descripcion = Servicio.Descripcion; nuevo.Estado = true; nuevo.IdEmpresa = Servicio.IdEmpresa; context.Servicio.Add(nuevo); context.SaveChanges(); return true; } catch (Exception e) { throw e; } } }
public ActionResult Servicio(int? id = null) { if (!this.currentUser()) { return RedirectToAction("Ingresar"); } if (!this.isAdministrator()) { return RedirectToAction("Index"); } ViewBag.Title = "Servicio"; MenuNavBarSelected(11); UsuarioDTO user = getCurrentUser(); ServicioBL objBL = new ServicioBL(); MonedaBL monedaBL = new MonedaBL(); ViewBag.lstMonedas = monedaBL.getListaMonedas(); var objSent = TempData["Servicio"]; if (objSent != null) { TempData["Servicio"] = null; return View(objSent); } ServicioDTO obj; if (id != null && id != 0) { obj = objBL.getServicioEnEmpresa((int)user.IdEmpresa, (int)id); if (obj == null) return RedirectToAction("Servicios"); if (obj.IdEmpresa != user.IdEmpresa) return RedirectToAction("Servicios"); return View(obj); } obj = new ServicioDTO(); obj.IdEmpresa = user.IdEmpresa; return View(obj); }
public bool update(ServicioDTO Servicio) { using (var context = getContext()) { try { var row = context.Servicio.Where(x => x.IdServicio == Servicio.IdServicio).SingleOrDefault(); row.IdMoneda = Servicio.IdMoneda; row.Codigo = Servicio.Codigo; row.Nombre = Servicio.Nombre; row.Precio = Servicio.Precio; row.Descripcion = Servicio.Descripcion; row.Estado = Servicio.Estado; row.IdEmpresa = Servicio.IdEmpresa; context.SaveChanges(); return true; } catch (Exception e) { throw e; } } }