예제 #1
0
 public bool add(CategoriaItmDTO CategoriaItm)
 {
     using (var context = getContext())
     {
         try
         {
             CategoriaItm nuevo = new CategoriaItm();
             nuevo.Nombre = CategoriaItm.Nombre;
             nuevo.Estado = true;
             nuevo.IdEmpresa = CategoriaItm.IdEmpresa;
             context.CategoriaItm.Add(nuevo);
             context.SaveChanges();
             return true;
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
예제 #2
0
 public bool update(CategoriaItmDTO CategoriaItm)
 {
     using (var context = getContext())
     {
         try
         {
             var row = context.CategoriaItm.Where(x => x.IdCategoriaItm == CategoriaItm.IdCategoriaItm).SingleOrDefault();
             row.Nombre = CategoriaItm.Nombre;
             row.Estado = CategoriaItm.Estado;
             row.IdEmpresa = CategoriaItm.IdEmpresa;
             context.SaveChanges();
             return true;
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
예제 #3
0
        public ActionResult AddCategoriaItm(CategoriaItmDTO dto)
        {
            if (!this.currentUser()) { return RedirectToAction("Ingresar"); }
            if (!this.isAdministrator()) { return RedirectToAction("Index"); }
            try
            {
                CategoriaItmBL objBL = new CategoriaItmBL();
                if (dto.IdCategoriaItm == 0)
                {
                    if (objBL.add(dto))
                    {
                        createResponseMessage(CONSTANTES.SUCCESS);
                        return RedirectToAction("CategoriaItms");
                    }
                }
                else if (dto.IdCategoriaItm != 0)
                {
                    if (objBL.update(dto))
                    {
                        createResponseMessage(CONSTANTES.SUCCESS);
                        return RedirectToAction("CategoriaItms");
                    }
                    else
                    {
                        createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_UPDATE_MESSAGE);
                    }

                }
                else
                {
                    createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_INSERT_MESSAGE);
                }
            }
            catch (Exception e)
            {
                if (dto.IdCategoriaItm != 0)
                    createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_UPDATE_MESSAGE);
                else createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_INSERT_MESSAGE);
            }
            TempData["CategoriaItm"] = dto;
            return RedirectToAction("CategoriaItm");
        }
예제 #4
0
        public ActionResult CategoriaItm(int? id = null)
        {
            if (!this.currentUser()) { return RedirectToAction("Ingresar"); }
            if (!this.isAdministrator()) { return RedirectToAction("Index"); }
            ViewBag.Title = "Categoría de Items";
            MenuNavBarSelected(10, 1);

            UsuarioDTO user = getCurrentUser();

            CategoriaItmBL objBL = new CategoriaItmBL();

            var objSent = TempData["CategoriaItm"];
            if (objSent != null) { TempData["CategoriaItm"] = null; return View(objSent); }

            CategoriaItmDTO obj;
            if (id != null && id != 0)
            {
                obj = objBL.getCategoriaItmEnEmpresa((int)user.IdEmpresa, (int)id);
                if (obj == null) return RedirectToAction("CategoriaItms");
                if (obj.IdEmpresa != user.IdEmpresa) return RedirectToAction("CategoriaItms");
                return View(obj);
            }
            obj = new CategoriaItmDTO();
            obj.IdEmpresa = user.IdEmpresa;

            return View(obj);
        }