예제 #1
0
        public int CreateShopHours(ShopHoursCreate model)
        {
            var entity =
                new ShopHours()
            {
                ShopID      = _userId,
                MonStart    = model.MonStart,
                MonEnd      = model.MonEnd,
                TeusStart   = model.TeusStart,
                TeusEnd     = model.TeusEnd,
                WedStart    = model.WedStart,
                WedEnd      = model.WedEnd,
                ThurStart   = model.ThurStart,
                ThurEnd     = model.ThurEnd,
                FriStart    = model.FriStart,
                FriEnd      = model.FriEnd,
                SatStart    = model.SatStart,
                SatEnd      = model.SatEnd,
                SunStart    = model.SunStart,
                SunEnd      = model.SunEnd,
                ModifiedUtc = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.ShopHours.Add(entity);
                ctx.SaveChanges(); //error when trying to save datetime object
                return(entity.HoursID);
            }
        }
예제 #2
0
        public ActionResult Create(ShopHoursCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = new ShopHoursServices(model.ShopID);

            if (service.CreateShopHours(model) != 0)
            {
                TempData["SaveResult"] = "Your shop hours were created.";
                return(RedirectToAction("Details", "Shop", new { id = model.ShopID }));
            }
            ;
            ModelState.AddModelError("", "Shop hours could not be created.");

            return(View(model));
        }