public ActionResult Edit() { int _id = int.Parse(ControllerContext.RouteData.GetRequiredString("id")); var _commonModel = commomModelService.Find(_id); TryUpdateModel(_commonModel, new string[] { "CategoryID", "Title", "DefaultPicUrl" }); TryUpdateModel(_commonModel.Article, "Article", new string[] { "Author", "Source", "Intro", "Content" }); if (ModelState.IsValid) { if (commomModelService.Update(_commonModel)) { //附件处理 InterfaceAttachmentService _attachmentService = new AttachmentService(); var _attachments = _attachmentService.FindList(_commonModel.ModelID, User.Identity.Name, string.Empty, true).ToList(); foreach (var _att in _attachments) { var _filePath = Url.Content(_att.FileParth); if (_commonModel.DefaultPicUrl != null && _commonModel.DefaultPicUrl.IndexOf(_filePath) >= 0 || _commonModel.Article.Content.IndexOf(_filePath) > 0) { _att.ModelID = _commonModel.ModelID; _attachmentService.Update(_att); } else { System.IO.File.Delete(Server.MapPath(_att.FileParth)); _attachmentService.Delete(_att); } } return(View("EditSucess", _commonModel)); } } return(View(_commonModel)); }
public ActionResult Reply() { CommonModel _commonModel = null; if (RouteData.Values.ContainsKey("id")) { int _modelId = int.Parse(RouteData.Values["id"].ToString()); _commonModel = commonModelService.Find(_modelId); if (string.IsNullOrEmpty(Request.Form["ReplyContent"])) { ModelState.AddModelError("ReplyContent", "必须输入回复内容!"); } else { _commonModel.Consultation.ReplyContent = Request.Form["ReplyContent"]; _commonModel.Consultation.ReplyTime = DateTime.Now; _commonModel.Status = 29; commonModelService.Update(_commonModel); } } return(View(_commonModel.Consultation)); }