public ActionResult Edit(int id) { var service = new ShopHoursServices(id); var detail = service.GetShopHoursById(id); var model = new ShopHoursEdit { ShopID = detail.ShopID, MonStart = detail.MonStart, MonEnd = detail.MonEnd, TeusStart = detail.TeusStart, TeusEnd = detail.TeusEnd, WedStart = detail.WedStart, WedEnd = detail.WedEnd.Value, ThurStart = detail.ThurStart, ThurEnd = detail.ThurEnd, FriStart = detail.FriStart, FriEnd = detail.FriEnd, SatStart = detail.SatStart, SatEnd = detail.SatEnd, SunStart = detail.SunStart, SunEnd = detail.SunEnd, ModifiedUtc = detail.ModifiedUtc }; return(View(model)); }
public ActionResult Edit(int ShopID, ShopHoursEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.ShopID != ShopID) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = new ShopHoursServices(ShopID); if (service.UpdateShopHours(model)) { TempData["SaveResult"] = "Your shop hours were updated."; return(RedirectToAction("Details", "Shop", new { ShopID = model.ShopID })); } ModelState.AddModelError("", "Your shop hours could not be updated."); return(View(model)); }
public bool UpdateShopHours(ShopHoursEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .ShopHours .Single(e => e.ShopID == model.ShopID); entity.MonStart = model.MonStart; entity.MonEnd = model.MonEnd; entity.TeusStart = model.TeusStart; entity.TeusEnd = model.TeusEnd; entity.WedStart = model.WedStart; entity.WedEnd = model.WedEnd; entity.ThurStart = model.ThurStart; entity.ThurEnd = model.ThurEnd; entity.FriStart = model.FriStart; entity.FriEnd = model.FriEnd; entity.SatStart = model.SatStart; entity.SatEnd = model.SatEnd; entity.SunStart = model.SunStart; entity.SunEnd = model.SunEnd; entity.ModifiedUtc = DateTimeOffset.Now; return(ctx.SaveChanges() == 1); } }