public ActionResult Agregar(FormCollection collection, Int64 Id_Item)
        {
            try
            {

                string Key = Request.Form["Key"];
                string Value = Request.Form["Value"];
                if (String.IsNullOrEmpty(Key) || String.IsNullOrEmpty(Value))
                {
                    Utils.UIWarnings.SetError("Campos vacios");
                    return RedirectToAction("Detalles", "Item", new { Id = Id_Item });
                }
                    var item = new Libros.Models.Item();
                item.Seleccionar(Id_Item);
                if(!item.Agregar(Key, Value))
                {
                    Utils.UIWarnings.SetError("Propiedad Existente");
                    return RedirectToAction("Detalles", "Item", new { Id = Id_Item });
                }
                Utils.UIWarnings.SetInfo("Propiedad Agregada");
                return RedirectToAction("Detalles","Item", new {Id = Id_Item});
            }
            catch
            {
                return RedirectToAction("Index","Home");
            }
        }
Ejemplo n.º 2
0
        public ActionResult Agregar(FormCollection collection, Int64 Id_Item)
        {
            try
            {
                string nombre = Request.Form["Nombre"];
                if (string.IsNullOrEmpty(nombre))
                {
                    Utils.UIWarnings.SetError("Campo vacío");
                    return(RedirectToAction("Detalles", "Item", new { Id = Id_Item }));
                }
                var autor = new Libros.Models.Autor();
                var item  = new Libros.Models.Item();
                item.Seleccionar(Id_Item);

                autor.Nombre = nombre;
                foreach (var a in item.Autores())
                {
                    if (a.Nombre.Equals(nombre))
                    {
                        Utils.UIWarnings.SetError("Este autor ya se encuentra en su item");
                        return(RedirectToAction("Detalles", "Item", new { Id = Id_Item }));
                    }
                }

                if (!autor.Crear())
                {
                    Utils.UIWarnings.SetError("Autor No Agregado");
                    return(RedirectToAction("Detalles", "Item", new { Id = Id_Item }));
                }
                item.Crear(autor);
                Utils.UIWarnings.SetInfo("Autor Nuevo Agregado");
                return(RedirectToAction("Detalles", "Item", new { Id = Id_Item }));
            }
            catch
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 3
0
 public ActionResult AgregarExistente(Libros.Models.Autor autor, Int64 Id_Item)
 {
     try
     {
         var item = new Libros.Models.Item();
         item.Seleccionar(Id_Item);
         autor.Seleccionar(autor.Id);
         foreach (var a in item.Autores())
         {
             if (a.Nombre.Equals(autor.Nombre))
             {
                 Utils.UIWarnings.SetError("Autor No Agregado");
                 return(RedirectToAction("Detalles", "Item", new { Id = Id_Item }));
             }
         }
         item.Crear(autor);
         Utils.UIWarnings.SetInfo("Autor Agregado");
         return(RedirectToAction("Detalles", "Item", new { Id = Id_Item }));
     }
     catch
     {
         return(RedirectToAction("Index", "Home"));
     }
 }