private void EditContestData(Contest contest, ContestFullDetailsModel model) { if (contest == null || model == null) { return; } contest.Title = model.Title; contest.Description = model.Description; contest.DeadlineDate = model.DeadlineDate; contest.MaxNumberOfParticipants = model.MaxNumberOfParticipants; contest.ParticipationStrategyType = model.ParticipationStrategyType; contest.VotingStrategyType = model.VotingStrategyType; this.Data.Contests.Update(contest); this.Data.SaveChanges(); this.cache.RemoveContestsFromCache(); }
private void CheckIfUserCanVote(Contest contest, ContestFullDetailsModel model) { if (contest.Status == ContestStatusType.Active && contest.OwnerId != this.CurrentUser.Id) { if (contest.VotingStrategyType == VotingStrategyType.Closed && contest.MaxNumberOfParticipants > contest.Participants.Count && contest.Voters.Any(v => v.Id == this.CurrentUser.Id)) { model.CanVote = true; } if (contest.VotingStrategyType == VotingStrategyType.Open && contest.OwnerId != this.CurrentUser.Id) { model.CanVote = true; } } }
private void CheckIfUserCanEdit(Contest contest, ContestFullDetailsModel model) { if (contest.OwnerId == this.CurrentUser.Id || this.User.IsInRole("Administrator")) { model.CanEdit = this.CanEdit(contest); } }
private void CheckIfUserCanParticipate(Contest contest, ContestFullDetailsModel model) { if (contest == null || model == null) { return; } if (contest.Status == ContestStatusType.Active && contest.OwnerId != this.CurrentUser.Id) { if (contest.ParticipationStrategyType == ParticipationStrategyType.Open && contest.MaxNumberOfParticipants > contest.Participants.Count) { model.CanParticipate = true; } if (contest.Participants.Any(u => u.Id == this.CurrentUser.Id)) { model.CanParticipate = true; } } }
public JsonResult Edit(ContestFullDetailsModel model) { var contest = this.Data.Contests.Find(model.Id); if (contest != null) { this.EditContestData(contest, model); this.AddToastMessage(String.Empty, GlobalConstants.ContestEditedMessage, ToastType.Success); return Json(new { Message = GlobalConstants.Home }, JsonRequestBehavior.AllowGet); } this.AddToastMessage(String.Empty, GlobalConstants.SomethingIsWrongMessage, ToastType.Error); return this.Json(new { Message = GlobalConstants.Error }, JsonRequestBehavior.AllowGet); }