コード例 #1
0
        public ActionResult Create(ShopServiceCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = new ShopServicesService(model.ShopID);

            if (service.CreateShopService(model))
            {
                TempData["SaveResult"] = "Your service was created.";
                return(RedirectToAction("Details", "Shop", new { ShopID = model.ShopID }));
            }
            ;
            ModelState.AddModelError("", "Service could not be created.");

            return(View(model));
        }
コード例 #2
0
        public bool CreateShopService(ShopServiceCreate model)
        {
            var entity =
                new ShopServices()
            {
                ShopID      = _userId,
                ServiceName = model.ServiceName,
                Description = model.Description,
                Duration    = model.Duration,
                Price       = model.Price,
                CreatedUtc  = DateTimeOffset.Now
            };

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