public async Task <IActionResult> Delete(string name) { var contest = await this.contestService.FindContestByNameAsync(name); var contestDTO = new ContestDTO(contest); return(View(new ContetsViewModel(contestDTO))); }
/// <summary> /// Filter and/or sort contests by phase. /// </summary> /// <param name="phaseName">Name of the phase for which we are filtering the contests.</param> /// <param name="sortBy">Value to sort by.</param> /// <param name="order">Value to order by.</param> /// <returns>Returns the contests that correspond to the filters.</returns> public async Task <IEnumerable <ContestDTO> > GetByPhaseAsync(string phaseName, string sortBy, string order) { var allContests = await this.dbContext .Contests .Include(c => c.Category) .Include(c => c.Status) .Where(c => c.IsDeleted == false) .ToListAsync(); var filteredContests = new List <ContestDTO>(); if (phaseName.Equals("phase 1", StringComparison.OrdinalIgnoreCase)) { foreach (var contest in allContests) { if (contest.Status.Name == "Phase 1") { var contestDTO = new ContestDTO(contest); filteredContests.Add(contestDTO); } } } else if (phaseName.Equals("phase 2", StringComparison.OrdinalIgnoreCase)) { foreach (var contest in allContests) { if (contest.Status.Name == "Phase 2") { var contestDTO = new ContestDTO(contest); filteredContests.Add(contestDTO); } } } else if (phaseName.Equals("finished", StringComparison.OrdinalIgnoreCase)) { foreach (var contest in allContests) { if (contest.Status.Name == "Finished") { var contestDTO = new ContestDTO(contest); filteredContests.Add(contestDTO); } } } else { throw new ArgumentException(Exceptions.InvalidPhase); } if (filteredContests.Count != 0 && sortBy != null) { filteredContests = Sorting(filteredContests, sortBy, order); } return(filteredContests); }
public async Task <IActionResult> Details(string name) { var contest = await this.contestService.FindContestByNameAsync(name); var userContests = await this.userContestService.GetAllUserContestsAsync(); var photos = await this.photoService.GetAllAsync(); var juries = await this.contestService.GetAllJuriesAsync(); var contestDTO = new ContestDTO(contest); return(View(new ContetsViewModel(contestDTO) { AllUserContests = userContests, AllPhotos = photos.ToList(), Juries = juries.ToList() })); }
public ContetsViewModel(ContestDTO contestDTO) { this.Name = contestDTO.Name; this.Category = contestDTO.Category; this.Status = contestDTO.Status; this.Phase1 = contestDTO.Phase1; this.Phase2 = contestDTO.Phase2; this.Finished = contestDTO.Finished; this.OpenOrInvitational = contestDTO.OpenOrInvitational; if (this.Status == "Phase 1") { this.TimeUntilNextPhase = Phase2; } if (this.Status == "Phase 2") { this.TimeUntilNextPhase = Finished; } if (this.Status == "Finished") { this.TimeUntilNextPhase = "Contest is in the final phase."; } }
public void getMatches(ContestDTO contest) { Matches = stub.getListOfMatches(contest.UID); }
/// <summary> /// Kiểm tra màn hình sau click vào kì thì sẽ là bắt đầu , tiếp tục hay thống kê /// </summary> /// <param name="termID"></param> /// <param name="indexPage"></param> /// <param name="sizePage"></param> /// <param name="keyword"></param> /// <returns></returns> public async Task <ActionServiceResult> CheckScreen(string userID, string contestID) { var res = new ActionServiceResult(); var result = await _contestBaseRepository.GetEntityByIdAsync(contestID); if (result == null) { return(null); } else { var user = await _userBaseRepository.GetEntityByIdAsync(userID); if (user == null) { return(null); } var roleName = string.IsNullOrEmpty(_role.GetValueOrDefault(user.RoleId.ToString())) ? "student" : _role.GetValueOrDefault(user.RoleId.ToString()); var contestDTO = new ContestDTO(); var exams = _examBaseRepository.GetEntitites("Proc_GetExamByContestID", new object[] { contestID }).Result.ToList(); var exam = exams.Where(item => item.UserId == Guid.Parse(userID)).FirstOrDefault(); if (roleName.Equals("student")) { if (DateTime.Compare(Utils.GetNistTime(), result.StartTime) < 0) { //Tao de thi if (exam == null) { var exam_new = await _examService.CreateExam(contestID, userID); await _examBaseRepository.AddAsync(exam_new, true); exam = exam_new; } return(new ActionServiceResult(true, "Chưa đến thời gian làm bài", Code.NotTimeToDo, exam.ExamId, 0)); } else if (DateTime.Compare(Utils.GetNistTime(), result.FinishTime) > 0) { if (exam == null) { var exam_new = await _examService.CreateExam(contestID, userID); exam_new.Status = 1; exam_new.Point = 0; exam_new.CreatedDate = exam_new.ModifiedDate = Utils.GetNistTime(); await _examBaseRepository.AddAsync(exam_new, true); contestDTO.ExamID = exam_new.ExamId; } else { contestDTO.ExamID = exam.ExamId; } contestDTO.Continue = 2; return(new ActionServiceResult(true, "Đã hết thời gian làm bài", Code.TimeOut, contestDTO, 0)); } else { if (exam == null) { contestDTO.Continue = 0; var exam_new = await _examService.CreateExam(contestID, userID); await _examBaseRepository.AddAsync(exam_new, true); contestDTO.ExamID = exam_new.ExamId; //Tao bai thi } else { contestDTO.ExamID = exam.ExamId; if (exam.IsDoing == 1 && DateTime.Compare(Utils.GetNistTime(), exam.ModifiedDate.Value) > 0 && exam.Status == 0) { contestDTO.Continue = 1; } if (exam.Status == 1) { contestDTO.Continue = 2; } } } res.Data = contestDTO; } else { if (DateTime.Compare(Utils.GetNistTime(), result.FinishTime) < 0) { var data = new { NumOfJoining = exams.Count(item => item.IsDoing == 1) }; return(new ActionServiceResult(true, "Đang trong thời gian làm bài", (Code)1001, data, 0)); } else { return(new ActionServiceResult(true, "", (Code)1001, exams, 0)); } } } return(res); }