Beispiel #1
0
        public ActionResult AddItems(DefaultItemCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(ModelState));
            }

            var context = new ApplicationDbContext();
            var entity  = context.Defaults.Find(model.Id);

            if (entity is null)
            {
                return(RedirectToAction(nameof(Index)));
            }

            entity.Items.AddRange(model.Items.Select(i => new ItemEntity {
                Name = i.Name, Number = i.Number
            }));
            if (context.SaveChanges() != model.Items?.Count)
            {
                return(View(model));
            }

            return(RedirectToAction(nameof(Detail), new { id = model.Id }));
        }
Beispiel #2
0
        public ActionResult AddItems(int?id)
        {
            if (id is null)
            {
                return(RedirectToAction(nameof(Index)));
            }

            var context = new ApplicationDbContext();
            var entity  = context.Defaults.Find(id);

            if (entity is null)
            {
                return(RedirectToAction(nameof(Index)));
            }

            var model = new DefaultItemCreate
            {
                Id   = entity.Id,
                Name = entity.Name
            };

            return(View(model));
        }