public ActionResult Create(CouponTypeViewModel model) { //if (model.FileUpload.Images.Count() <= 0) //{ // ModelState.AddModelError("Image", "上传图片"); //} if (string.IsNullOrWhiteSpace(model.Name)) { ModelState.AddModelError("Name", "填写名称"); } //if (string.IsNullOrWhiteSpace(model.Keyword)) //{ // ModelState.AddModelError("Keyword", "填写关键字"); //} if (ModelState.IsValid) { var type = new CouponType() { Image = model.FileUpload.Images.FirstOrDefault(), Keyword = model.Keyword?.Replace(" ", "") ?? "", Name = model.Name, Sort = model.Sort, ParentID = model.ParentID, Platform = model.Platform, }; couponType.Add(type); return(RedirectToAction("Index", new { pid = model.ParentID, platform = model.Platform })); } Sidebar(); return(View(model)); }
public ActionResult Edit(CouponTypeViewModel model) { //if (model.FileUpload.Images.Count() <= 0) //{ // ModelState.AddModelError("Image", "上传图片"); //} if (string.IsNullOrWhiteSpace(model.Name)) { ModelState.AddModelError("Name", "填写名称"); } //if (string.IsNullOrWhiteSpace(model.Keyword)) //{ // ModelState.AddModelError("Keyword", "填写关键字"); //} if (ModelState.IsValid) { var type = couponType.FirstOrDefault(s => s.ID == model.ID); var index = couponType.IndexOf(type); type.Image = model.FileUpload.Images.FirstOrDefault(); type.Keyword = model.Keyword?.Replace(" ", "") ?? ""; type.Name = model.Name; type.Sort = model.Sort; type.Platform = model.Platform; couponType[index] = type; return(RedirectToAction("Index", new { pid = model.ParentID, platform = model.Platform })); } return(View(model)); }
public ActionResult Create(int pid = 0, Enums.CouponPlatform platform = Enums.CouponPlatform.TaoBao) { Sidebar(); var model = new CouponTypeViewModel() { FileUpload = new FileUpload() { Max = 1, Type = FileType.Image, Name = "CouponTypeViewModelImage" }, ParentID = pid, Platform = platform, }; return(View(model)); }
public ActionResult DeleteConfirm(int id) { var type = couponType.FirstOrDefault(s => s.ID == id); if (couponType.Any(s => s.ParentID == id)) { ModelState.AddModelError("", "先删除他的二级分类"); } if (type == null) { ModelState.AddModelError("", "没有这个类型"); } if (ModelState.IsValid) { couponType.Remove(type); return(RedirectToAction("Index", new { pid = type.ParentID, platform = type.Platform })); } var model = new CouponTypeViewModel() { FileUpload = new FileUpload() { Max = 1, Type = FileType.Image, Name = "CouponTypeViewModelImage", Images = string.IsNullOrWhiteSpace(type.Image) ? new string[] { } : new string[] { type.Image } }, ParentID = type.ParentID, ID = type.ID, Image = type.Image, Keyword = type.Keyword, Name = type.Name, Sort = type.Sort, }; return(View(model)); }
public ActionResult Delete(int id) { Sidebar(); var type = couponType.FirstOrDefault(s => s.ID == id); var model = new CouponTypeViewModel() { FileUpload = new FileUpload() { Max = 1, Type = FileType.Image, Name = "CouponTypeViewModelImage", Images = string.IsNullOrWhiteSpace(type.Image) ? new string[] { } : new string[] { type.Image } }, ParentID = type.ParentID, ID = type.ID, Image = type.Image, Keyword = type.Keyword, Name = type.Name, Sort = type.Sort, Platform = type.Platform, }; return(View(model)); }