public ActionResult Edit(int id) { ViewBag.Error = "none"; MldApplicationArea model = dal.Query(id); return(View(model)); }
public ActionResult Edit(int id, string name, HttpPostedFileBase homebg, HttpPostedFileBase icon, string subhead, string content, int homeshowflag) { ViewBag.Error = "none"; MldApplicationArea model = dal.Query(id); string imgUrl1 = model.HomeBg; if (homebg != null && homebg.ContentLength > 0) { UploadFileResult result = homebg.FileUpLoad("img", 1024 * 1024 * 4, "applicationarea"); if (!result.Ok) { ViewBag.Error = result.Data; } else { imgUrl1 = result.Data; } } string imgUrl2 = model.Icon; if (icon != null && icon.ContentLength > 0) { UploadFileResult result = icon.FileUpLoad("img", 1024 * 1024 * 4, "applicationarea"); if (!result.Ok) { ViewBag.Error = result.Data; } else { imgUrl2 = result.Data; } } model.Content = content; model.HomeBg = imgUrl1; model.Icon = imgUrl2; model.Name = name; model.SubHead = subhead; model.HomeShowFlag = homeshowflag; if (dal.Update(model)) { ViewBag.Success = "ok"; } else { ViewBag.Error = "Error"; } model = dal.Query(id); return(View(model)); }
public ActionResult Index(string name, HttpPostedFileBase homebg, HttpPostedFileBase icon, string subhead, string content, int homeshowflag) { ViewBag.Error = "none"; if (homebg != null && homebg.ContentLength > 0 && icon != null && icon.ContentLength > 0) { UploadFileResult result1 = homebg.FileUpLoad("img", 1024 * 1024 * 4, "applicationarea"); UploadFileResult result2 = icon.FileUpLoad("img", 1024 * 1024 * 4, "applicationarea"); if (!result1.Ok || !result2.Ok) { ViewBag.Error = "图片上传错误"; } else { MldApplicationArea model = new MldApplicationArea(); model.AddTime = DateTime.Now; model.Content = content; model.HomeBg = result1.Data; model.Icon = result2.Data; model.Name = name; model.SubHead = subhead; model.HomeShowFlag = homeshowflag; int id = dal.Add(model); if (id > 0) { ViewBag.Success = "ok"; } else { ViewBag.Error = "Error"; } } } else { ViewBag.Error = "请选择要上传的背景图和图标"; } return(View()); }