public bool add(UbicacionDTO Ubicacion) { using (var context = getContext()) { try { Ubicacion nuevo = new Ubicacion(); nuevo.Nombre = Ubicacion.Nombre; nuevo.Estado = true; nuevo.IdEmpresa = Ubicacion.IdEmpresa; context.Ubicacion.Add(nuevo); context.SaveChanges(); return true; } catch (Exception e) { throw e; } } }
public ActionResult AddUbicacion(UbicacionDTO dto) { if (!this.currentUser()) { return RedirectToAction("Ingresar"); } if (!this.isAdministrator()) { return RedirectToAction("Index"); } try { UbicacionBL objBL = new UbicacionBL(); if (dto.IdUbicacion == 0) { if (objBL.add(dto)) { createResponseMessage(CONSTANTES.SUCCESS); return RedirectToAction("Ubicaciones"); } } else if (dto.IdUbicacion != 0) { if (objBL.update(dto)) { createResponseMessage(CONSTANTES.SUCCESS); return RedirectToAction("Ubicaciones"); } else { createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_UPDATE_MESSAGE); } } else { createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_INSERT_MESSAGE); } } catch (Exception e) { if (dto.IdUbicacion != 0) createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_UPDATE_MESSAGE); else createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_INSERT_MESSAGE); } TempData["Ubicacion"] = dto; return RedirectToAction("Ubicacion"); }
public ActionResult Ubicacion(int? id = null) { if (!this.currentUser()) { return RedirectToAction("Ingresar"); } if (!this.isAdministrator()) { return RedirectToAction("Index"); } ViewBag.Title = "Ubicacion"; MenuNavBarSelected(10, 2); UsuarioDTO currentUser = getCurrentUser(); UbicacionBL objBL = new UbicacionBL(); var objSent = TempData["Ubicacion"]; if (objSent != null) { TempData["Ubicacion"] = null; return View(objSent); } UbicacionDTO obj; if (id != null && id != 0) { obj = objBL.getUbicacionEnEmpresa((int)currentUser.IdEmpresa, (int)id); if (obj == null) return RedirectToAction("Ubicaciones"); if (obj.IdEmpresa != currentUser.IdEmpresa) return RedirectToAction("Ubicaciones"); return View(obj); } obj = new UbicacionDTO(); obj.IdEmpresa = currentUser.IdEmpresa; return View(obj); }
public bool update(UbicacionDTO Ubicacion) { using (var context = getContext()) { try { var row = context.Ubicacion.Where(x => x.IdUbicacion == Ubicacion.IdUbicacion).SingleOrDefault(); row.Nombre = Ubicacion.Nombre; row.Estado = Ubicacion.Estado; row.IdEmpresa = Ubicacion.IdEmpresa; context.SaveChanges(); return true; } catch (Exception e) { throw e; } } }