コード例 #1
0
ファイル: UserController.cs プロジェクト: Weej1/geekinside
 public ActionResult addFavorite(int docid,string returnURL)
 {
     string employeeNumber = User.Identity.Name;
     UserEmployeeModel empModel = new BLLUserAccount().GetUserByEmpNumber(Convert.ToInt32(employeeNumber));
     //这里要先判断是否已经收藏过
     if (new BLLFavorite().isFavorite(Convert.ToInt32(employeeNumber),docid))
     {
         TempData["errorMsg"] = "您已经收藏过此文档了。";
         return RedirectToAction(returnURL, "User");
     }
     BLLDocument bllDocument = new BLLDocument();
     DocumentModel docModel = bllDocument.getDocumentById(docid);
     if (employeeNumber == "" || docModel == null )
     {
         TempData["errorMsg"] = "您无权进行添加收藏操作,请重新登录。";
         return RedirectToAction(returnURL, "User");
     }
     if (docModel.PublisherNumber == Convert.ToInt32(employeeNumber))
     {
         TempData["errorMsg"] = "您不能收藏自己发布的文档。";
         return RedirectToAction(returnURL, "User");
     }
     BLLFavorite bllFavorite = new BLLFavorite();
     if (bllFavorite.addToMyFavorite(Convert.ToInt32(employeeNumber), docid))
     {
         TempData["successMsg"] = "添加成功。";
     }
     else
     {
         TempData["errorMsg"] = "添加失败。";
     }
     return RedirectToAction(returnURL, "User");
 }