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))); }