예제 #1
0
 public ActionResult Add(CommonModel commonModel)
 {
     if (ModelState.IsValid)
     {
         InterfaceUserService _userService = new UserService();
         var _user = _userService.Find(User.Identity.Name);
         if (commonModel.Article != null)
         {
             commonModel.Article = null;
         }
         if (commonModel.Attachment != null)
         {
             commonModel.Attachment = null;
         }
         if (commonModel.DefaultPicUrl != null)
         {
             commonModel.DefaultPicUrl = null;
         }
         commonModel.Hits              = 0;
         commonModel.Inputer           = User.Identity.Name;
         commonModel.Model             = "Consultation";
         commonModel.ReleaseDate       = System.DateTime.Now;
         commonModel.Status            = 20;
         commonModel.Consultation.Name = _user.DisplayName;
         _user        = null;
         _userService = null;
         commonModel  = commentModelService.Add(commonModel);
         if (commonModel.ModelID > 0)
         {
             return(View("AddSuccess", commonModel));
         }
     }
     return(View(commonModel));
 }
예제 #2
0
 public ActionResult Add(CommonModel commonModel)
 {
     if (ModelState.IsValid)
     {
         //设置固定值
         commonModel.Hits        = 0;
         commonModel.Inputer     = User.Identity.Name;
         commonModel.Model       = "Article";
         commonModel.ReleaseDate = System.DateTime.Now;
         commonModel.Status      = 29;
         commonModel             = commentModelService.Add(commonModel);
         if (commonModel.Article.ArticleID > 0)
         {
             //附件处理
             interfaceAttachmentService _attachmentService = new AttachmentService();
             //查询相关附件
             var _attachments = _attachmentService.FindList(null, User.Identity.Name, string.Empty).ToList();
             //遍历所有附件
             foreach (var _att in _attachments)
             {
                 var _filePath = Url.Content(_att.FileParth);
                 //文章首页图片或内容中使用了该附件则更改ModelID为文章保存后的ModelID
                 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("AddSuccess", commonModel));
         }
     }
     return(View(commonModel));
 }