Exemplo n.º 1
0
 public bool add(ItemDTO Item)
 {
     using (var context = getContext())
     {
         try
         {
             Item nuevo = new Item();
             nuevo.IdCategoriaItm = Item.IdCategoriaItm;
             nuevo.IdMoneda = Item.IdMoneda;
             nuevo.Codigo = Item.Codigo;
             nuevo.Nombre = Item.Nombre;
             nuevo.Precio = Item.Precio;
             nuevo.Descripcion = Item.Descripcion;
             nuevo.UnidadMedida = Item.UnidadMedida;
             nuevo.Estado = true;
             nuevo.IdEmpresa = Item.IdEmpresa;
             context.Item.Add(nuevo);
             context.SaveChanges();
             return true;
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Exemplo n.º 2
0
        public ActionResult AddItem(ItemDTO dto)
        {
            if (!this.currentUser()) { return RedirectToAction("Ingresar"); }
            if (!this.isAdministrator()) { return RedirectToAction("Index"); }
            try
            {
                ItemBL objBL = new ItemBL();
                if (dto.IdItem == 0)
                {
                    if (objBL.add(dto))
                    {
                        createResponseMessage(CONSTANTES.SUCCESS);
                        return RedirectToAction("Items");
                    }
                }
                else if (dto.IdItem != 0)
                {
                    if (objBL.update(dto))
                    {
                        createResponseMessage(CONSTANTES.SUCCESS);
                        return RedirectToAction("Items");
                    }
                    else
                    {
                        createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_UPDATE_MESSAGE);
                    }

                }
                else
                {
                    createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_INSERT_MESSAGE);
                }
            }
            catch (Exception e)
            {
                if (dto.IdItem != 0)
                    createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_UPDATE_MESSAGE);
                else createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_INSERT_MESSAGE);
            }
            TempData["Item"] = dto;
            return RedirectToAction("Item");
        }
Exemplo n.º 3
0
 public bool update(ItemDTO Item)
 {
     using (var context = getContext())
     {
         try
         {
             var row = context.Item.Where(x => x.IdItem == Item.IdItem).SingleOrDefault();
             row.IdCategoriaItm = Item.IdCategoriaItm;
             row.IdMoneda = Item.IdMoneda;
             row.Codigo = Item.Codigo;
             row.Nombre = Item.Nombre;
             row.Precio = Item.Precio;
             row.Descripcion = Item.Descripcion;
             row.UnidadMedida = Item.UnidadMedida;
             row.Estado = Item.Estado;
             row.IdEmpresa = Item.IdEmpresa;
             context.SaveChanges();
             return true;
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Exemplo n.º 4
0
        public ActionResult Item(int? id = null)
        {
            if (!this.currentUser()) { return RedirectToAction("Ingresar"); }
            if (!this.isAdministrator()) { return RedirectToAction("Index"); }
            ViewBag.Title = "Item";
            MenuNavBarSelected(10, 0);

            UsuarioDTO user = getCurrentUser();

            ItemBL objBL = new ItemBL();
            ViewBag.lstCategoriaItm = objBL.getCategoriasEnEmpresa(user.IdEmpresa);

            MonedaBL monedaBL = new MonedaBL();
            ViewBag.lstMonedas = monedaBL.getListaMonedas();

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

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

            return View(obj);
        }