public ActionResult Update(SlidersModel model) { if (!ModelState.IsValid) { return(new AjaxResult().Alert(T(Constants.Messages.InvalidModel))); } var service = WorkContext.Resolve <ISlidersService>(); var listDelete = service.GetRecords(x => x.Type == model.Type); service.DeleteMany(listDelete); foreach (var image in model.UploadPhotos) { var row = new SliderInfo { Id = 0, LanguageCode = "", CategoryId = 0, Type = model.Type, ImageUrl = image.ImageUrl, Caption = image.Caption, SortOrder = image.SortOrder, Url = image.Url, IsDeleted = false }; service.Save(row); } return(new AjaxResult().NotifyMessage("UPDATE_ENTITY_COMPLETE").Alert(T("Đã cập nhật thành công.")).Redirect(Url.Action("Index"))); }
/************** SLIDER **************/ public ActionResult Sliders() { using (db_informaticsEntities _db = new db_informaticsEntities()){ SlidersModel model = new SlidersModel(); model.sliderList = _db.slider_information.ToList(); return(PartialView(model)); } }
public ActionResult Edit(int id) { WorkContext.Breadcrumbs.Add(new Breadcrumb { Text = T("Quản lý banner"), Url = "#" }); WorkContext.Breadcrumbs.Add(new Breadcrumb { Text = T("Thông tin banner"), Url = Url.Action("Index") }); var model = new SlidersModel(); if (id > 0) { var service = WorkContext.Resolve <ISlidersService>(); var item = service.GetById(id); if (item != null) { model.Type = item.Type; var list = service.GetRecords(x => x.Type == item.Type); var listModel = list.Select(image => new UploadImageModel { ImageUrl = image.ImageUrl, Caption = image.Caption, SortOrder = image.SortOrder }).ToList(); model.UploadPhotos = listModel; } } var result = new ControlFormResult <SlidersModel>(model); result.Title = this.T("Thông tin banner"); result.FormMethod = FormMethod.Post; result.UpdateActionName = "Update"; result.ShowCancelButton = false; result.ShowBoxHeader = false; result.FormWrapperStartHtml = Constants.Form.FormWrapperStartHtml; result.FormWrapperEndHtml = Constants.Form.FormWrapperEndHtml; //result.RegisterExternalDataSource(x => x.CategoryId, BindCategories()); result.RegisterExternalDataSource(x => x.Type, y => BindSliderType()); result.AddAction().HasText(this.T("Thêm mới")).HasUrl(this.Url.Action("Edit", RouteData.Values.Merge(new { id = 0 }))).HasButtonStyle(ButtonStyle.Success); result.AddAction().HasText(this.T("Back")).HasUrl(this.Url.Action("Index")).HasButtonStyle(ButtonStyle.Danger); return(result); }