public ActionResult Create(ShopFormModel model, [DataSourceRequest] DataSourceRequest request) { Contract.Requires(model != null); if (this.ModelState.IsValid) { var shop = this.ShopRepository.Create(); var address = this.AddressRepository.Create(); ShopFormModel.ToData(shop, model, address); address.Shop = shop; shop.Adresses = new List <Address>(); shop.Adresses.Add(address); this.ShopRepository.Insert(shop); this.UnityOfWork.Save(); model.Id = shop.Id; } return(this.JsonNet(new[] { model }.ToDataSourceResult(request, this.ModelState))); }
public ActionResult Update([DataSourceRequest] DataSourceRequest request, ShopFormModel model) { Contract.Requires(model != null); if (this.ModelState.IsValid) { var shop = this.ShopRepository.GetById(model.Id); if (shop == null) { throw new Exception("Zaměstnanec nenalezen."); } var address = this.AddressRepository.GetQueryable().SingleOrDefault(s => s.ShopId == model.Id); ShopFormModel.ToData(shop, model, address); this.AddressRepository.Update(address); this.ShopRepository.Update(shop); this.UnityOfWork.Save(); } return(this.JsonNet(new[] { model }.ToDataSourceResult(request, this.ModelState))); }
public ActionResult Delete([DataSourceRequest] DataSourceRequest request, ShopFormModel model) { Contract.Requires(model != null); var product = this.ShopRepository.GetQueryable().SingleOrDefault(s => s.Id == model.Id); if (product == null) { throw new NullReferenceException("Zaměstnanec nenalezen."); } this.ShopRepository.Delete(product); this.UnityOfWork.Save(); return(this.JsonNet(new[] { model }.ToDataSourceResult(request, this.ModelState))); }
public ActionResult Save(ShopFormModel form) { ViewBag.ShopCats = GetShopCats(); if (ModelState.IsValid) { Shop shop; if (form.ID == 0) { //检验shopname是否已经存在 if (_shopService.GetShopByShopName(form.ShopName).IsNotNull()) { Error("该店铺已经存在,请确认!"); return(View("Create", form)); } shop = new Shop(); shop = shop.SettingDefault(shop); } else { shop = _shopService.GetShop(form.ID); } shop.ShopName = form.ShopName; shop.MainBiz = form.MainBiz; shop.Photo = form.Photo; shop.ShopTags = form.ShopTags ?? string.Empty; shop.ShortDesc = form.ShortDesc; shop.CatId = form.CatId; shop.ShopUrl = form.ShopUrl; shop.LastModifyDate = DateTime.Now; shop.PromoteURL = form.PromoteURL.IsNullOrEmpty() ? string.Empty : form.PromoteURL; if (ModelState.IsValid) { _shopService.CreateOrUpdate(shop); } Success("操作成功"); } return(View(form.ID == 0 ? "Create" : "Edit", form)); }