コード例 #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  = commonModelService.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 = DateTime.Now;
         commonModel.Status      = 99;
         commonModel             = commomModelService.Add(commonModel);
         if (commonModel.ModelID > 0)
         {
             //附件处理
             InterfaceAttachmentService attachmentService = new AttachmentService();
             //查询相关附件
             var attachment = attachmentService.FindList(null, User.Identity.Name, string.Empty).ToList();
             //遍历附件
             foreach (var att in attachment)
             {
                 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("AddSucess", commonModel));
         }
     }
     return(View(commonModel));
 }