예제 #1
0
 public ActionResult Upload()
 {
     foreach (string upload in Request.Files)
     {
         if (!Request.Files[upload].HasFile())
         {
             continue;
         }
         string mimetype = Request.Files[upload].ContentType;
         string path     = AppDomain.CurrentDomain.BaseDirectory + "uploads/";
         if (!Directory.Exists(path))
         {
             Directory.CreateDirectory(path);
         }
         string filename = Path.GetFileName(Request.Files[upload].FileName);
         Request.Files[upload].SaveAs(Path.Combine(path, filename));
         MyFileDB.Insert(new MyFile(0, filename, mimetype, filename, 1));
     }
     return(View());
 }
예제 #2
0
        public ActionResult playground()
        {
            ViewBag.message = true;
            List <WeikeData> weikes = WeikeDB.GetAllWeikeOrderByDate();

            foreach (WeikeData wd in weikes)
            {
                wd.attachment = MyFileDB.FindByWeikeId(wd.weike.weike_id);
            }
            ViewBag.data = weikes;
            if (Session["user"] != null)
            {
                User user = (User)Session["user"];
                ViewBag.user = user;
                List <FavoriteData>          fdList = FavoriteDB.FindFavoriteWeikeByUserId(user.id);
                Dictionary <WeikeData, bool> weikeDataWithFavorite = new Dictionary <WeikeData, bool>();
                bool hasFavorite = false;
                foreach (WeikeData wdata in weikes)
                {
                    hasFavorite = false;
                    foreach (FavoriteData fdata in fdList)
                    {
                        if (wdata.weike.weike_id == fdata.weike.weike_id)
                        {
                            hasFavorite = true;
                            break;
                        }
                    }
                    weikeDataWithFavorite.Add(wdata, hasFavorite);
                }
                ViewBag.weikeDataWithFavorite = weikeDataWithFavorite;

                ViewBag.followNoticeNum  = NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "follow").Count + NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "unfollow").Count;
                ViewBag.likeNoticeNum    = NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "like").Count + NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "dislike").Count;
                ViewBag.commentNoticeNum = NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "comment").Count;
                ViewBag.replyNoticeNum   = NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "reply").Count;
            }
            return(View());
        }