public IActionResult UpdateStore(CreateStoreView model, int id) { if (HttpContext.Session.GetString("CurrentUserFirstName") == null) { return(RedirectToAction("Index", "Home")); } if (ModelState.IsValid) { Store currentStore = _context.Stores.SingleOrDefault(store => store.id == id); currentStore.Name = model.Name; currentStore.Address1 = model.Address1; currentStore.Address2 = model.Address2; currentStore.City = model.City; currentStore.State = model.State; currentStore.Zip = model.Zip; currentStore.Description = model.Description; currentStore.updated_at = DateTime.Now; _context.Stores.Update(currentStore); _context.SaveChanges(); return(RedirectToAction("StoreDetails", new { id = id })); } else { ViewBag.StoreId = id; return(View(model)); } }
public IActionResult CreateStore(CreateStoreView model) { if (HttpContext.Session.GetString("CurrentUserFirstName") == null) { return(RedirectToAction("Index", "Home")); } if (ModelState.IsValid) { Store newStore = new Store { Name = model.Name, Address1 = model.Address1, Address2 = model.Address2, City = model.City, State = model.State, Zip = model.Zip, Description = model.Description, CreatedByUserId = (int)HttpContext.Session.GetInt32("CurrentUserId") }; _context.Stores.Add(newStore); _context.SaveChanges(); newStore = _context.Stores.Last(); return(RedirectToAction("StoreDetails", new { id = newStore.id })); } else { return(View(model)); } }
public IActionResult UpdateStore(int id) { if (HttpContext.Session.GetString("CurrentUserFirstName") == null) { return(RedirectToAction("Index", "Home")); } Store currentStore = _context.Stores.SingleOrDefault(store => store.id == id); CreateStoreView storeViewModel = new CreateStoreView { Name = currentStore.Name, Address1 = currentStore.Address1, Address2 = currentStore.Address2, City = currentStore.City, State = currentStore.State, Zip = currentStore.Zip, Description = currentStore.Description }; ViewBag.StoreId = id; return(View(storeViewModel)); }