public JsonResult Destroy([DataSourceRequest] DataSourceRequest request, TextAdvertisementViewModel model) { var dbModel = this.Data.TextAdvertisements.GetById(model.Id); this.Data.TextAdvertisements.Delete(dbModel); this.Data.SaveChanges(); return this.Json(new[] { model }, JsonRequestBehavior.AllowGet); }
public JsonResult Destroy([DataSourceRequest] DataSourceRequest request, TextAdvertisementViewModel model) { var dbModel = this.Data.TextAdvertisements.GetById(model.Id); this.Data.TextAdvertisements.Delete(dbModel); this.Data.SaveChanges(); return(this.Json(new[] { model }, JsonRequestBehavior.AllowGet)); }
public JsonResult Update([DataSourceRequest] DataSourceRequest request, TextAdvertisementViewModel model) { var dbModel = this.Data.TextAdvertisements.GetById(model.Id); if (model != null && this.ModelState.IsValid) { dbModel.Name = model.Name; dbModel.Content = model.Content; dbModel.AvailableClicks = model.AvailableClicks; dbModel.Url = model.Url; this.Data.TextAdvertisements.Update(dbModel); this.Data.SaveChanges(); } return(this.Json((new[] { model }.ToDataSourceResult(request, this.ModelState)), JsonRequestBehavior.AllowGet)); }
public JsonResult Update([DataSourceRequest] DataSourceRequest request, TextAdvertisementViewModel model) { var dbModel = this.Data.TextAdvertisements.GetById(model.Id); if (model != null && this.ModelState.IsValid) { dbModel.Name = model.Name; dbModel.Content = model.Content; dbModel.AvailableClicks = model.AvailableClicks; dbModel.Url = model.Url; this.Data.TextAdvertisements.Update(dbModel); this.Data.SaveChanges(); } return this.Json((new[] { model }.ToDataSourceResult(request, this.ModelState)), JsonRequestBehavior.AllowGet); }
public TextAdvertisementViewModel Create(TextAdvertisementViewModel model) { if (model != null && this.ModelState.IsValid) { var textAd = new TextAdvertisement() { Name = model.Name, Url = model.Url, Content = model.Content, AvailableClicks = model.AvailableClicks }; this.Data.TextAdvertisements.Add(textAd); this.Data.SaveChanges(); var mapped = Mapper.Map <TextAdvertisementViewModel>(textAd); mapped.Id = textAd.Id; return(mapped); } return(null); }
public TextAdvertisementViewModel Create(TextAdvertisementViewModel model) { if (model != null && this.ModelState.IsValid) { var textAd = new TextAdvertisement() { Name = model.Name, Url = model.Url, Content = model.Content, AvailableClicks = model.AvailableClicks }; this.Data.TextAdvertisements.Add(textAd); this.Data.SaveChanges(); var mapped = Mapper.Map<TextAdvertisementViewModel>(textAd); mapped.Id = textAd.Id; return mapped; } return null; }