private Store EditModelToStore(StoreEditModel model) { Store store = StoreRepository.Get(s => s.Id.Equals(model.Id)).SingleOrDefault(); if (store != null) { store.ImagePath = model.ImagePath; store.Name = model.Name; store.HtmlBanner = Server.HtmlEncode(string.Format(_storeTemplate, model.Id, model.ImagePath, model.Name, model.Description)); store.Description = model.Description; store.Products = model.Products; } return store; }
private StoreEditModel StoreToEditModel(int id) { Store store = StoreRepository.Get(s => s.Id.Equals(id)).SingleOrDefault(); StoreEditModel model = new StoreEditModel() { Id = store.Id, ImagePath = store.ImagePath, Name = store.Name, HtmlBanner = store.HtmlBanner, Description = store.Description, Products = store.Products }; return model; }
public ActionResult Edit(StoreEditModel model) { User user = UserRepository.Get(u => u.UserName == User.Identity.Name).SingleOrDefault(); if (ModelState.IsValid && user != null && user.Role.IsAdmin) { try { Store store = EditModelToStore(model); StoreRepository.SaveOrUpdate(store); return RedirectToAction("Index"); } catch { return null; } } else { return null; } }