public ActionResult Edit(StoreEditViewModel model) { if (ModelState.IsValid) { var store = db.Stores .Include(m => m.Address) .FirstOrDefault(m => m.Id == model.Id); if (store == null) { return(View("Error")); } store.Name = model.Name; store.Address.Line1 = model.Line1; store.Address.Line2 = model.Line2; store.Address.Line3 = model.Line3; store.Address.Zip = model.Zip; store.Address.StateId = model.State; store.Address.CountryId = model.Country; store.Address.PlaceId = model.City; store.Address.MarketId = model.Market; store.Address.Landmark = model.Landmark; store.DefaultCurrencyType = model.CurrencyType; db.Entry(store).State = EntityState.Modified; db.Entry(store.Address).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(RedirectToAction("Edit", new { id = model.Id })); }
public async Task <ResponseViewModel <bool> > Save([FromBody] StoreEditViewModel data) { Store store; if (String.IsNullOrEmpty(data.Id)) { store = new Store(); } else { store = await StoreRepository.GetById(data.Id); } store.Name = data.Name; store.Url = data.Url; await StoreRepository.Save(store); return(new ResponseViewModel <bool>(true)); }