public ActionResult Create(CreateContestInputModel model) { var ownerId = this.User.Identity.GetUserId(); var getParticipants = new List<User>(); var getVoters = new List<User>(); var participationStrategy = Enum.GetValues(typeof(ParticipationType)) .Cast<ParticipationType>(); var deadlineStrategy = Enum.GetValues(typeof(DeadlineType)) .Cast<DeadlineType>(); var votingnStrategy = Enum.GetValues(typeof(VotingType)) .Cast<VotingType>(); var users = this.ContestData.Users.All().ToList(); if (model != null && this.ModelState.IsValid) { var contest = new Contest() { Title = model.Title, Description = model.Description, StartDate = model.StartDate, EndDate = model.EndDate, VotesCount = model.VotesCount, WinnersCount = model.WinnersCount, OwnerId = ownerId, HasEnded = false, ContestStatus = ContestStatus.Active, ParticipationType = (ParticipationType)Enum.Parse(typeof(ParticipationType), model.SelectParticipationStrategy.FirstOrDefault()), VotingType = (VotingType)Enum.Parse(typeof(VotingType), model.SelectVotingStrategy.FirstOrDefault()), DeadlineType = (DeadlineType)Enum.Parse(typeof(DeadlineType), model.SelectDeadlineStrategy.FirstOrDefault()) }; this.ContestData.Contest.Add(contest); contest.Pictures.Add(new Picture { Url = "default.jpg", UploaderId = ownerId }); this.ContestData.SaveChanges(); contest.Participants = GetParticipants(contest.ContestId,model, getParticipants); contest.Voters = GetVoters(contest.ContestId,model, getVoters); this.ContestData.SaveChanges(); this.AddNotification("Contest Create",NotificationType.INFO); return this.RedirectToAction("Index"); } model.ParticipationStrategy = participationStrategy; model.DeadlineStrategy = deadlineStrategy; model.VotingStrategy = votingnStrategy; model.Users = users; return this.View(model); }
public ActionResult Create() { var contest = new Contest(); var users = this.ContestData.Users.All().ToList(); var participationStrategy = Enum.GetValues(typeof(ParticipationType)) .Cast<ParticipationType>(); var deadlineStrategy = Enum.GetValues(typeof(DeadlineType)) .Cast<DeadlineType>(); var votingnStrategy = Enum.GetValues(typeof(VotingType)) .Cast<VotingType>(); CreateContestInputModel inputModel = new CreateContestInputModel(contest, users, participationStrategy, deadlineStrategy, votingnStrategy); return this.View(inputModel); }
public List<User> GetVoters(int contestId, CreateContestInputModel model, List<User> voters) { var ownerId = this.User.Identity.GetUserId(); var userName = this.User.Identity.GetUserName(); var contestName = model.Title; if (model.SelectedVoters != null) { foreach (var id in model.SelectedVoters) { var user = this.ContestData.Users.All().First(u => u.Id == id); var voterNotification = new Notification() { RecipientId = id, SenderId = ownerId, Content = string.Format("{0} has invited you to be a voter in {1} contest", userName, contestName), CreatedOn = DateTime.Now, IsRead = false, InviteType = InvitationType.Voter, ContestId = contestId }; this.ContestData.Notifications.Add(voterNotification); voters.Add(user); } } this.ContestData.SaveChanges(); return voters; }