public ActionResult Estates_Update([DataSourceRequest]DataSourceRequest request, AdministerEstateViewModel estate) { if (ModelState.IsValid) { var entity = this.estates.GetById(estate.Id); entity.Name = estate.Name; entity.Address = estate.Address; entity.Size = estate.Size; this.estates.SaveChanges(); } var estateToDisplay = this.estates .All() .To<AdministerEstateViewModel>() .FirstOrDefault(x => x.Id == estate.Id); return Json(new[] { estateToDisplay }.ToDataSourceResult(request, ModelState)); }
public ActionResult Estates_Create([DataSourceRequest]DataSourceRequest request, AdministerEstateViewModel estate) { var newId = 0; if (ModelState.IsValid) { var entity = new Estate { Name = estate.Name, Address = estate.Address, Size = estate.Size, AuthorId = this.User.Identity.GetUserId() }; this.estates.Add(entity); this.estates.SaveChanges(); newId = entity.Id; } var estateToDisplay = this.estates .All() .To<AdministerEstateViewModel>() .FirstOrDefault(x => x.Id == newId); return Json(new[] { estateToDisplay }.ToDataSourceResult(request, ModelState)); }