public ActionResult AddNewTimeChoice(int id) { User currentUser = UserRepository.Get(Convert.ToInt32(User.Identity.GetUserId())); Time timeChosen = TimeRepository.Get(id); TimeChoice newTimeChoice = new TimeChoice(); newTimeChoice.Time = timeChosen; newTimeChoice.User = currentUser; newTimeChoice.Meeting = timeChosen.Meeting; TimeChoiceRepository.Add(newTimeChoice); updateInvitationStatus(currentUser, timeChosen.Meeting.Id, 1); return(RedirectToAction("Profile", new { id = newTimeChoice.Meeting.Id })); }
public ActionResult Profile(int?id) { try { int id2 = Convert.ToInt32(id); Meeting meeting = MeetingRepository.Get(id2); var model = new MeetingViewModel(); if (meeting.Times.Count > 0) { foreach (var time in meeting.Times) { model.Times.Add(time); } } List <int> alreadyInvitedUserIds = new List <int>(); List <Invitation> StatusZero = new List <Invitation>(); List <Invitation> StatusOne = new List <Invitation>(); List <Invitation> StatusTwo = new List <Invitation>(); List <Invitation> invitations = InvitationRepository.GetMeeting(id2); if (invitations.Count > 0) { foreach (Invitation invitation in invitations) { model.Invitations.Add(invitation); alreadyInvitedUserIds.Add(invitation.User.Id); if (invitation.User.Id == Convert.ToInt32(User.Identity.GetUserId())) { model.CurrentUsersInvitation = invitation; } if (invitation.Status == 0) { StatusZero.Add(invitation); } if (invitation.Status == 1) { StatusOne.Add(invitation); } if (invitation.Status == 2) { StatusTwo.Add(invitation); } } } ICollection <User> allUsers = UserRepository.Get(); foreach (User user in allUsers) { if (!alreadyInvitedUserIds.Contains(user.Id) && user.Id != meeting.Creator.Id && allUsers.Count > 0 && !user.Username.ToLower().Equals("admin")) { model.NotInvitedUsers.Add(new SelectListItem { Text = user.Name, Value = user.Id.ToString() }); } } var allTimeChoices = TimeChoiceRepository.Get(); var currentUsersCoices = new List <int>(); foreach (var choice in allTimeChoices) { if (choice.User.Id == Convert.ToInt32(User.Identity.GetUserId())) { currentUsersCoices.Add(choice.Time.Id); } } if (alreadyInvitedUserIds.Contains(Convert.ToInt32(User.Identity.GetUserId()))) { model.Invited = true; } else { model.Invited = false; } var voteList = new List <int>(); foreach (var time in meeting.Times) { voteList.Add(TimeChoiceRepository.GetCount(time.Id)); } model.VoteArray = voteList.ToArray(); model.Inactive = meeting.Inactive; model.ConfirmedTime = meeting.ConfirmedTime; model.AlreadySelectedTimes = currentUsersCoices; model.CurrentUserId = Convert.ToInt32(User.Identity.GetUserId()); model.MeetingId = meeting.Id; model.Creator = meeting.Creator; model.Title = meeting.Title; model.Description = meeting.Description; model.StatusZero = StatusZero; model.StatusOne = StatusOne; model.StatusTwo = StatusTwo; return(View(model)); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(RedirectToAction("Index")); } }