Ejemplo n.º 1
0
        public ActionResult Create(SupplyCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateSupplyService();

            if (service.CreateSupply(model))
            {
                TempData["SaveResult"] = "Your item was created.";
                return(RedirectToAction("Create", "Roadblock"));
            }
            ;

            ModelState.AddModelError("", "Item could not be created.");
            return(View(model));
        }
Ejemplo n.º 2
0
        public bool CreateSupply(SupplyCreate model)
        {
            var entity = new Supply()
            {
                OwnerId     = _ownerId,
                Brand       = model.Brand,
                Color       = model.Color,
                Quantity    = model.Quantity,
                SupplyName  = model.SupplyName,
                TotalCost   = model.TotalCost,
                AlreadyHave = model.AlreadyHave
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Items.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }