Exemplo n.º 1
0
        public ActionResult ApproveDeny(string userName)
        {
            JsonResponse response = new JsonResponse();

            //MembershipUser user = membershipService.GetUser(userName);

            try
            {
                //user.IsApproved = !user.IsApproved;
                //membershipService.UpdateUser(user);

                //string approvedMsg = (user.IsApproved) ? "Approved" : "Denied";

                //response.Success = true;
                //response.Message = "User " + approvedMsg + " successfully!";
                //response.Approved = user.IsApproved;
                //response.ApprovedStatus = (user.IsApproved) ? "Approved" : "Not approved";
            }
            catch (Exception)
            {
                response.Success = false;
                response.Message = "User unlocked failed.";
            }

            return Json(response);
        }
Exemplo n.º 2
0
        public JsonResult CheckForUniqueTeam(string Name, int TeamID = -1)
        {
            Team team = repository.Teams.FirstOrDefault(t => t.Name == Name && t.TeamID != TeamID);
            JsonResponse response = new JsonResponse();
            response.Exists = (team == null) ? false : true;

            return Json(response, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 3
0
        public JsonResult CheckForUniqueEmail(string Email)
        {
            UserProfile user = repository.Users.Where(u => u.Email == Email).FirstOrDefault();
            JsonResponse response = new JsonResponse();
            response.Exists = (user == null) ? false : true;

            return Json(response, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 4
0
        public ActionResult CreateRole(string roleName)
        {
            JsonResponse response = new JsonResponse();

            if (string.IsNullOrEmpty(roleName))
            {
                response.Success = false;
                response.Message = "Пожалуйста, введите имя роли.";
                response.CssClass = "red";

                return Json(response);
            }

            try
            {
                Roles.CreateRole(roleName);

                if (Request.IsAjaxRequest())
                {
                    response.Success = true;
                    response.Message = "Роль успешно создана!";
                    response.CssClass = "green";

                    logger.Info("User " + WebSecurity.GetUserId(User.Identity.Name) +
                        " \"" + User.Identity.Name + "\" created role \"" + roleName + "\"");

                    return Json(response);
                }

                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                if (Request.IsAjaxRequest())
                {
                    response.Success = false;
                    response.Message = "Произошла ошибка при создании роли";
                    response.CssClass = "red";

                    logger.Warn("Error occurred on user " + WebSecurity.GetUserId(User.Identity.Name) +
                        " \"" + User.Identity.Name + "\" creating role \"" + roleName + "\": ", ex);

                    return Json(response);
                }

                ModelState.AddModelError("", "Произошла ошибка при создании роли");
            }

            return RedirectToAction("Index");
        }
Exemplo n.º 5
0
        public ActionResult CheckForUniqueProblemName(string ProblemName, int ProblemID = -1)
        {
            Problem problem = repository
                .Problems
                .FirstOrDefault(p => p.Name == ProblemName && p.ProblemID != ProblemID);
            JsonResponse response = new JsonResponse();
            response.Exists = (problem == null) ? false : true;

            return Json(response, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 6
0
        public JsonResult MarkCommentAsRead(int CommentID)
        {
            Comment comment = repository.Comments.FirstOrDefault(c => c.CommentID == CommentID);

            if (comment == null)
            {
                logger.Warn("Comment with id = " + CommentID + " not found");
                throw new HttpException(404, "Comment with id = " + CommentID + " not found");
            }

            JsonResponse response = new JsonResponse();
            response.Success = true;

            try
            {

                logger.Info("User " + WebSecurity.GetUserId(User.Identity.Name) +
                    " \"" + User.Identity.Name + "\" mark comment " + CommentID + " as read");

                comment.IsRead = 1;
                repository.AddComment(comment);
            }
            catch (Exception ex)
            {
                logger.Warn("Error occurred on marking comment as read: Comment with id = " + CommentID, ex);

                response.Success = false;
                response.Message = ex.Message;
            }

            return Json(response, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 7
0
        public JsonResult MakeCommentPrivate(int CommentID)
        {
            Comment comment = repository.Comments.FirstOrDefault(c => c.CommentID == CommentID);

            if (comment == null)
            {
                logger.Warn("Comment with id = " + CommentID + " not found");
                throw new HttpException(404, "Comment with id = " + CommentID + " not found");
            }

            JsonResponse response = new JsonResponse();
            response.Success = true;

            try
            {

                logger.Info("User " + WebSecurity.GetUserId(User.Identity.Name) +
                    " \"" + User.Identity.Name + "\" make comment " + CommentID + " private");

                Stack<Comment> stack = new Stack<Comment>();
                stack.Push(comment);

                while (stack.Count > 0)
                {
                    comment = stack.Pop();
                    comment.ChildComments.Each(c => stack.Push(c));
                    comment.Public = 0;
                    repository.AddComment(comment);
                }
            }
            catch (Exception ex)
            {
                logger.Warn("Error occurred on making comment private: Comment with id = " + CommentID, ex);

                response.Success = false;
                response.Message = ex.Message;
            }

            return Json(response, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 8
0
        public JsonResult ChangeSolutionStatus(int SolutionID, TestResults Result)
        {
            Solution solution = repository.Solutions.FirstOrDefault(s => s.SolutionID == SolutionID);

            if (solution == null)
            {
                logger.Warn("Solution with id = " + SolutionID + " not found");
                throw new HttpException(404, "Solution with id = " + SolutionID + " not found");
            }

            JsonResponse response = new JsonResponse();
            response.Success = true;

            if (Result == TestResults.Waiting)
            {
                TestersSingleton.Instance.RecheckSolution(solution.SolutionID);
            }
            else if (Result == TestResults.Disqualified)
            {
                solution.Result = Result;
                if (!solution.User.SolvedProblems.Contains(solution.Problem))
                {
                    solution.User.NotSolvedProblems.Add(solution.Problem);
                }
                repository.SaveSolution(solution);
            }
            else if (Result == TestResults.OK)
            {
                try
                {
                    logger.Info("User " + WebSecurity.GetUserId(User.Identity.Name) +
                        " \"" + User.Identity.Name + "\" change status " + solution.Result + " -> " + Result +
                        " for solution " + SolutionID);

                    solution.Result = Result;
                    if (solution.Tournament.Format == TournamentFormats.IOI && Result == TestResults.OK)
                    {
                        solution.Score = 100;
                    }

                    if (solution.Result == TestResults.OK)
                    {
                        solution.User.NotSolvedProblems.Remove(solution.Problem);
                        solution.User.SolvedProblems.Add(solution.Problem);
                    }
                    else
                    {
                        if (!solution.User.SolvedProblems.Contains(solution.Problem))
                        {
                            solution.User.NotSolvedProblems.Add(solution.Problem);
                        }
                    }

                    repository.SaveSolution(solution);
                }
                catch (Exception ex)
                {
                    logger.Warn("Error occurred on solution status changing: Solution with id = " + SolutionID, ex);

                    response.Success = false;
                    response.Message = ex.Message;
                }
            }

            return Json(response, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 9
0
        public JsonResult InviteUser(string UserName, int TeamID)
        {
            Team team = repository.Teams.FirstOrDefault(t => t.TeamID == TeamID);
            int userID = WebSecurity.GetUserId(UserName);
            UserProfile user = repository
                .Users
                .FirstOrDefault(u => u.UserId == userID);

            JsonResponse response = new JsonResponse();
            if (team == null || user == null)
            {
                response.Message = user == null ? "Неккоректное имя пользователя" : "Произошла ошибка";
                response.Success = false;
            }
            else
            {
                UserProfileTeam userProfileTeam = repository
                    .UserProfileTeam
                    .FirstOrDefault(ut => ut.UserID == userID && ut.TeamID == team.TeamID);

                if (userProfileTeam == null)
                {
                    userProfileTeam = new UserProfileTeam()
                        {
                            UserID = user.UserId,
                            TeamID = team.TeamID
                        };
                }

                userProfileTeam.Confirm = 0;
                repository.AddUserProfileTeam(userProfileTeam);

                response.Message = "Приглашение для " + UserName + " успешно отправлено";
                response.Success = true;
            }

            return Json(response, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 10
0
        public ActionResult DeleteRoles(string roles, bool throwOnPopulatedRole)
        {
            JsonResponse response = new JsonResponse();
            response.Messages = new List<ResponseItem>();

            if (string.IsNullOrEmpty(roles))
            {
                response.Success = false;
                response.Message = "Пожалуйста, выберите роли.";
                return Json(response);
            }

            string[] roleNames = roles.Split(',');
            StringBuilder sb = new StringBuilder();

            ResponseItem item = null;

            foreach (var role in roleNames)
            {
                if (!string.IsNullOrEmpty(role))
                {
                    try
                    {
                        Roles.DeleteRole(role, throwOnPopulatedRole);

                        item = new ResponseItem();
                        item.Success = true;
                        item.Message = "Роль \"" + role + "\" успешно удалена";
                        item.CssClass = "green";
                        response.Messages.Add(item);

                        sb.AppendLine("Роль \"" + role + "\" успешно удалена <br />");

                        logger.Info("User " + WebSecurity.GetUserId(User.Identity.Name) +
                            " \"" + User.Identity.Name + "\" delete role \"" + role + "\"");
                    }
                    catch (System.Configuration.Provider.ProviderException)
                    {
                        sb.AppendLine("Произошла ошибка при удалении роли \"" + role + "\" <br />");

                        item = new ResponseItem();
                        item.Success = false;
                        item.Message = "Произошла ошибка при удалении роли \"" + role + "\"";
                        item.CssClass = "yellow";
                        response.Messages.Add(item);

                        logger.Info("User " + WebSecurity.GetUserId(User.Identity.Name) +
                            " \"" + User.Identity.Name + "\" delete role \"" + role + "\"");
                    }
                }
            }

            response.Success = true;
            response.Message = sb.ToString();

            return Json(response);
        }
Exemplo n.º 11
0
        public ActionResult CheckForUniqueTournamentName(string TournamentName, int TournamentID = -1)
        {
            Tournament tournament = repository
                .Tournaments
                .FirstOrDefault(t => t.Name == TournamentName && t.TournamentID != TournamentID);
            JsonResponse response = new JsonResponse();
            response.Exists = (tournament == null) ? false : true;

            return Json(response, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 12
0
        public ActionResult Unlock(string userName)
        {
            JsonResponse response = new JsonResponse();

            //MembershipUser user = membershipService.GetUser(userName);

            try
            {
                //user.UnlockUser();
                response.Success = true;
                response.Message = "User unlocked successfully!";
                response.Locked = false;
                response.LockedStatus = (response.Locked) ? "Locked" : "Unlocked";
            }
            catch (Exception)
            {
                response.Success = false;
                response.Message = "User unlocked failed.";
            }

            return Json(response);
        }
Exemplo n.º 13
0
        public ActionResult RevokeRolesFromUser(string UserName, string Roles)
        {
            JsonResponse response = new JsonResponse();

            if (string.IsNullOrEmpty(UserName))
            {
                response.Success = false;
                response.Message = "Имя пользователя не указано.";
                return Json(response);
            }

            if (string.IsNullOrEmpty(Roles))
            {
                response.Success = false;
                response.Message = "Роль не указана";
                return Json(response);
            }

            string[] roleNames = Roles.Substring(0, Roles.Length - 1).Split(',');

            if (roleNames.Length == 0)
            {
                response.Success = false;
                response.Message = "Роль не указана.";
                return Json(response);
            }

            try
            {
                System.Web.Security.Roles.RemoveUserFromRoles(UserName, roleNames);

                response.Success = true;
                response.Message = "Роль(и) успешно удалена(ы) у пользователя " + UserName;

                logger.Info("User " + WebSecurity.GetUserId(User.Identity.Name) +
                    " \"" + User.Identity.Name + "\" revoke role \"" + Roles + "\" from \"" + UserName + "\" ");
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = "Произошла ошибка при удалении роли(ей) у пользователя.";

                logger.Warn("Error occurred on user " + WebSecurity.GetUserId(User.Identity.Name) +
                    " \"" + User.Identity.Name + "\" revoking role \"" + Roles + "\" from \"" + UserName + "\": ", ex);
            }

            return Json(response);
        }
Exemplo n.º 14
0
        public ActionResult UnbindTournamentFromProblem(int tournamentID = -1, int problemID = -1)
        {
            JsonResponse response = new JsonResponse();

            if (tournamentID == -1)
            {
                response.Success = false;
                response.Message = "Идентификатор турнира некорректен.";
                return Json(response);
            }

            if (problemID == -1)
            {
                response.Success = false;
                response.Message = "Идентификатор задачи некорректен.";
                return Json(response);
            }

            try
            {
                repository.UnbindProblemFromTournament(tournamentID, problemID);

                response.Success = true;
                response.Message = "Задача успешно удалена из турнира.";

                logger.Info("User " + WebSecurity.GetUserId(User.Identity.Name) +
                    " \"" + User.Identity.Name + "\" unbind problem \"" + problemID + "\" from tournament \"" + tournamentID + "\" ");
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = "Произошла ошибка при удалении задачи из турнира.";

                logger.Warn("Error occurred on user " + WebSecurity.GetUserId(User.Identity.Name) +
                    " \"" + User.Identity.Name + "\" unbinding problem \"" + problemID + "\" from tournament \"" + tournamentID + "\": ", ex);
            }

            return Json(response);
        }
Exemplo n.º 15
0
        public JsonResult ChangeTeamName(string Name, int TeamID)
        {
            Team team = repository.Teams.FirstOrDefault(t => t.TeamID == TeamID);
            JsonResponse response = new JsonResponse();
            if (team == null)
            {
                response.Message = Name == null || Name == "" ? "Неккоректное имя команды" : "Команда не существует";
                response.Success = false;
            }
            else
            {
                team.Name = Name;
                repository.AddTeam(team);

                response.Message = "Имя команды успешно изменено";
                response.Success = true;
            }

            return Json(response, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 16
0
        public ActionResult BindProblemToTournament(int TournamentID = -1, int ProblemID = -1)
        {
            JsonResponse response = new JsonResponse();

            if (TournamentID == -1)
            {
                response.Success = false;
                response.Message = "Идентификатор турнира некорректен.";
                return Json(response);
            }

            if (ProblemID == -1)
            {
                response.Success = false;
                response.Message = "Идентификатор задачи некорректен.";
                return Json(response);
            }

            try
            {
                repository.BindProblemToTournament(TournamentID, ProblemID);

                response.Success = true;
                response.Message = "Задача успешно добавлена в турнир.";

                logger.Info("User " + WebSecurity.GetUserId(User.Identity.Name) +
                    " \"" + User.Identity.Name + "\" bind problem \"" + ProblemID + "\" to tournament \"" + TournamentID + "\" ");
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = "Произошла ошибка при добавлении задачи в турнир.";

                logger.Warn("Error occurred on user " + WebSecurity.GetUserId(User.Identity.Name) +
                    " \"" + User.Identity.Name + "\" binding problem \"" + ProblemID + "\" to tournament \"" + TournamentID + "\": {3} ", ex);
            }

            return Json(response);
        }
Exemplo n.º 17
0
        public ActionResult CheckForUniqueUser(string UserName)
        {
            UserProfile user = repository.Users.FirstOrDefault(u => u.UserName == UserName);
            JsonResponse response = new JsonResponse();
            response.Exists = (user == null) ? false : true;

            return Json(response, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 18
0
        public ActionResult UnbindUserFromTournament(int TournamentID = -1, int UserID = -1)
        {
            JsonResponse response = new JsonResponse();

            if (TournamentID == -1)
            {
                response.Success = false;
                response.Message = "Идентификатор турнира некорректен.";
                return Json(response);
            }

            if (UserID == -1)
            {
                response.Success = false;
                response.Message = "Идентификатор пользователя некорректен.";
                return Json(response);
            }

            try
            {
                repository.UnbindUserFromTournament(TournamentID, UserID);

                response.Success = true;
                response.Message = "Пользователь успешно удален из турнира.";

                logger.Info("User " + WebSecurity.GetUserId(User.Identity.Name) +
                    " \"" + User.Identity.Name + "\" unbind user \"" + UserID + "\" from tournament \"" + TournamentID + "\" ");
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = "Произошла ошибка при удалении пользователя из турнира.";

                logger.Warn("Error occurred on user " + WebSecurity.GetUserId(User.Identity.Name) +
                    " \"" + User.Identity.Name + "\" unbinding user \"" + UserID + "\" from tournament \"" + TournamentID + "\": ", ex);
            }

            return Json(response);
        }
Exemplo n.º 19
0
        public ActionResult DeleteRole(string roleName)
        {
            JsonResponse response = new JsonResponse();

            if (string.IsNullOrEmpty(roleName))
            {
                response.Success = false;
                response.Message = "Пожалуйста, выберите роль для удаления.";
                response.CssClass = "red";

                return Json(response);
            }

            Roles.DeleteRole(roleName);

            response.Success = true;
            response.Message = "Роль \"" + roleName + "\" успешно удалена!";
            response.CssClass = "green";

            logger.Info("User " + WebSecurity.GetUserId(User.Identity.Name) +
                " \"" + User.Identity.Name + "\" delete role \"" + roleName + "\"");

            return Json(response);
        }