Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id">contest id</param>
        /// <returns></returns>
        public IActionResult List(int id)
        {
            var submissionsToSee =
                this.submissions.All <ListSubmissionModel>().Where(s => s.UserEmail == this.User.Name);

            IContestService contests    = new ContestService();
            var             allContests = contests
                                          .All <Contest>()
                                          .Select(c => new { Name = c.Name, Id = c.Id })
                                          .Where(c => c.Id == id); //could use automapper here too

            StringBuilder contestsHtml = new StringBuilder();

            //draw contest html
            foreach (var cont in allContests)
            {
                var state = string.Empty;

                if (id == cont.Id)
                {
                    state = "active";
                }
                contestsHtml.Append(string.Format(this.ContestLink, state));
            }
            this.ViewModel["contests"] = contestsHtml.ToString();


            var currentUserEmail = this.User.Name;

            IUserService users           = new UserService();
            var          userSubmissions = this.submissions
                                           .All <Submission>()
                                           .Count(s => s.ContestId == id &&
                                                  s.UserId == users.GetId(currentUserEmail));

            StringBuilder submissionsHtml = new StringBuilder();

            //draw contest submissions html
            for (int i = 0; i < userSubmissions; i++)
            {
                Random r     = new Random();
                var    color = r.Next(0, 100) < 70 ? "danger" : "success";
                submissionsHtml.Append(string.Format(this.ContestSubmission, color));
            }

            this.ViewModel["submissions"] = submissionsHtml.ToString();
            return(View());
        }