Пример #1
0
        public ActionResult Create(PlatingCreate model)
        {
            if ((!ModelState.IsValid) ||
                (SaveCreate(model) == false))
            {
                return(View(model));
            }

            return(RedirectToAction("Index"));
        }
Пример #2
0
        private bool SaveCreate(PlatingCreate model)
        {
            var service = CreatePlatingService();

            if (service.CreatePlating(model))
            {
                TempData["SaveResult"] = "Your Plating was created.";
                return(true);
            }
            else
            {
                ModelState.AddModelError("", "Plating could not be created.");
                return(false);
            }
        }
Пример #3
0
        public bool CreatePlating(PlatingCreate model)
        {
            var entity = new Plating()
            {
                AuthorID    = userId,
                Name        = model.Name,
                Description = model.Description,
                DateCreated = DateTimeOffset.UtcNow,
            };

            using (var context = new CookbookContext())
            {
                context.Platings.Add(entity);
                return(context.SaveChanges() == 1);
            }
        }