public ActionResult UserResponse(int notificationId, bool accepted) { var userId = this.User.Identity.GetUserId(); var user = this.ContestData.Users.Find(userId); var notification = this.ContestData.Notifications.All().FirstOrDefault(n => n.RecipientId == userId && n.Id == notificationId); if (notification == null || notification.InviteType == InvitationType.Custom) { return RedirectToAction("Index"); } Notification newNotification = new Notification { SenderId = userId, RecipientId = notification.SenderId, Content = String.Format("{0} has declined your {1} invitation.", user.UserName, notification.InviteType), CreatedOn = DateTime.Now, InviteType = InvitationType.Custom, ContestId = notification.ContestId }; if (accepted) { newNotification.Content = String.Format("{0} has accepted your invitation.", user.UserName); if (notification.InviteType == InvitationType.Participant) { this.ContestData.Contest.Find(notification.ContestId).Participants.Add(user); } if (notification.InviteType == InvitationType.Voter) { this.ContestData.Contest.Find(notification.ContestId).Voters.Add(user); } } notification.InviteType = InvitationType.Custom; this.ContestData.Notifications.Add(newNotification); this.ContestData.SaveChanges(); return View("Index"); }
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; }