Ejemplo n.º 1
0
        public ActionResult Private(int id, string password)
        {
            var contest = DbContext.Contests.Find(id);

            if (string.IsNullOrEmpty(contest.Password))
            {
                return(RedirectToAction("Show", "Contest", new { id = id }));
            }
            var user     = (Entity.User)ViewBag.CurrentUser;
            var joinlogs = (from j in DbContext.JoinLogs
                            where j.UserID == user.ID &&
                            j.ContestID == id
                            select j).FirstOrDefault();

            if (joinlogs != null)
            {
                return(RedirectToAction("Show", "Contest", new { id = id }));
            }
            if (password == contest.Password)
            {
                joinlogs = new Entity.JoinLog
                {
                    UserID    = user.ID,
                    ContestID = id
                };
                DbContext.JoinLogs.Add(joinlogs);
                DbContext.SaveChanges();
                return(RedirectToAction("Show", "Contest", new { id = id }));
            }
            else
            {
                return(RedirectToAction("Message", "Shared", new { msg = "您输入的参赛密码不正确,请返回重试!" }));
            }
        }
Ejemplo n.º 2
0
        public ActionResult Private(int id)
        {
            var contest = DbContext.Contests.Find(id);

            if (string.IsNullOrEmpty(contest.Password))
            {
                return(RedirectToAction("Show", "Contest", new { id = id }));
            }
            var user     = (Entity.User)ViewBag.CurrentUser;
            var joinlogs = (from j in DbContext.JoinLogs
                            where j.UserID == user.ID &&
                            j.ContestID == id
                            select j).FirstOrDefault();

            if (joinlogs == null)
            {
                if (user.Role >= Entity.UserRole.Master || (from cm in contest.Managers select cm.UserID).Contains(user.ID))
                {
                    joinlogs = new Entity.JoinLog
                    {
                        UserID    = user.ID,
                        ContestID = id
                    };
                    DbContext.JoinLogs.Add(joinlogs);
                    DbContext.SaveChanges();
                    return(RedirectToAction("Show", "Contest", new { id = id }));
                }
                else
                {
                    ViewBag.ContestTitle = contest.Title;
                    return(View());
                }
            }
            else
            {
                return(RedirectToAction("Show", "Contest", new { id = id }));
            }
        }
Ejemplo n.º 3
0
 public ActionResult Private(int id, string password)
 {
     var contest = DbContext.Contests.Find(id);
     if (string.IsNullOrEmpty(contest.Password))
         return RedirectToAction("Show", "Contest", new { id = id });
     var user = (Entity.User)ViewBag.CurrentUser;
     var joinlogs = (from j in DbContext.JoinLogs
                     where j.UserID == user.ID
                     && j.ContestID == id
                     select j).FirstOrDefault();
     if (joinlogs != null)
         return RedirectToAction("Show", "Contest", new { id = id });
     if (password == contest.Password)
     {
         joinlogs = new Entity.JoinLog
         {
             UserID = user.ID,
             ContestID = id
         };
         DbContext.JoinLogs.Add(joinlogs);
         DbContext.SaveChanges();
         return RedirectToAction("Show", "Contest", new { id = id });
     }
     else
     {
         return RedirectToAction("Message", "Shared", new { msg="您输入的参赛密码不正确,请返回重试!"});
     }
 }
Ejemplo n.º 4
0
 public ActionResult Private(int id)
 {
     var contest = DbContext.Contests.Find(id);
     if (string.IsNullOrEmpty(contest.Password))
         return RedirectToAction("Show", "Contest", new { id = id });
     var user = (Entity.User)ViewBag.CurrentUser;
     var joinlogs = (from j in DbContext.JoinLogs
                     where j.UserID == user.ID
                     && j.ContestID == id
                     select j).FirstOrDefault();
     if (joinlogs == null)
     {
         if (user.Role >= Entity.UserRole.Master || (from cm in contest.Managers select cm.UserID).Contains(user.ID))
         {
             joinlogs = new Entity.JoinLog
             {
                 UserID = user.ID,
                 ContestID = id
             };
             DbContext.JoinLogs.Add(joinlogs);
             DbContext.SaveChanges();
             return RedirectToAction("Show", "Contest", new { id = id });
         }
         else
         {
             ViewBag.ContestTitle = contest.Title;
             return View();
         }
     }
     else
     {
         return RedirectToAction("Show", "Contest", new { id = id });
     }
 }