public JsonResult SaveBanner(BannerEditDto editModel) { bool status = false; string msg = ""; CheckModelState(); try { BannerListDto oldBanner = new BannerListDto(); if (editModel.Id.HasValue && editModel.Id > 0) { oldBanner = _bannerAppService.GetBannerByIdAsync(new EntityDto(editModel.Id.Value)).Result; } if (oldBanner != null) { editModel.Img = oldBanner.Img; ImgUploadHelpers uploadHelpers = new ImgUploadHelpers(Request.Files, Server.MapPath("/")); var uploadResult = uploadHelpers.UploadImg(); if (uploadResult.Item1 == ImageUploadStatus.Success) { editModel.Img = uploadResult.Item2; _bannerAppService.CreateOrUpdateBannerAsync( new CreateOrUpdateBannerInput() { BannerEditDto = editModel }); status = true; } else if (uploadResult.Item1 == ImageUploadStatus.NoFile) { _bannerAppService.CreateOrUpdateBannerAsync( new CreateOrUpdateBannerInput() { BannerEditDto = editModel }); status = true; } else { msg = "图片上传失败,原因可能为图片格式不匹配,图片过大,请检查重新上传"; status = false; } } } catch (Exception e) { msg = e.Message; status = false; } return(Json(new { success = status, message = msg })); }
public ActionResult Save(BannerEditDto dto) { try { bannerservice.CreateOrUpdateBannerAsync(new CreateOrUpdateBannerInput { BannerEditDto = dto }); return(RedirectToAction("/Index")); } catch { return(View()); } }