Ejemplo n.º 1
0
        public IActionResult List(int id)
        {
            if (id == 0)
            {
                return(RedirectToAction(nameof(MeetingController.List), "Meeting"));
            }

            var invitedUsersList = _invitedUserRepository.GetInvitedUsersList(id)
                                   .Select(item => new InvitedUserViewModel.InvitedUsersList
            {
                DisplayedUserName = item.AppUser.FullName, UserName = item.AppUser.UserName,
                UserEmail         = item.AppUser.Email, Status = item.Status,
                Id = item.AppUser.Id
            })
                                   .ToList();

            var meeting = _meetingRepository.GetMeeting(id);
            var vm      = new InvitedUserViewModel.InvitedUserListViewModel
            {
                MeetingId = id,

                /*AvailableUsers = _invitedUserRepository.GetAvailableUsers(id)
                 *  .OrderBy(u => u.LastName).ThenBy(u => u.Email)
                 *  .ToList(),*/
                AvailableUsers =
                    _friendInvitationRepository.GetFriendsOfCurrentUser(GetCurrentUserId().Result)
                    .OrderBy(u => u.LastName).ThenBy(u => u.Email).ToList(),
                InvitedUsersList = invitedUsersList,
                IsEditable       = meeting.Organizer.UserName == User.Identity.Name
            };

            return(View(vm));
        }
Ejemplo n.º 2
0
        public IActionResult Add(InvitedUserViewModel.InvitedUserListViewModel vm)
        {
            var userId              = vm.SelectedToInviteUserId;
            var meetingId           = vm.MeetingId;
            var meeting             = _meetingRepository.GetMeeting(meetingId);
            var overlappingMeetings = new List <Meeting>();

            overlappingMeetings = _meetingRepository.GetOverlappingMeetingsForUser(meeting.StartDateTime, meeting.EndDateTime, userId)
                                  .ToList();
            // bozy This variable should be inside the if part. Moreover setting a variable with a single space is a code smell
            var overlappingMeetingsTitle = " ";

            if (overlappingMeetings.Count > 0)
            {
                // use string.Join() instead of foreach.
                foreach (var m in overlappingMeetings)
                {
                    overlappingMeetingsTitle += m.Title + " ";
                }
                TempData["ErrorMessage"] = Constants.OverlappingMeetingsMessage + overlappingMeetingsTitle;
                return(RedirectToAction(nameof(List), new { id = meetingId }));
            }
            _invitedUserRepository.AddUserToMeeting(userId, meetingId, InvitationStatus.Pending);
            TempData["SuccessMessage"] = Constants.GeneralSuccessMessage;

            return(RedirectToAction(nameof(List), new { id = meetingId }));
        }
Ejemplo n.º 3
0
        public IActionResult List(int id)
        {
            if (id == 0)
            {
                return(RedirectToAction(nameof(MeetingController.List), "Meeting"));
            }

            var invitedUsersList = new Dictionary <string, InvitationStatus>();

            invitedUsersList = _invitedUserRepository.GetInvitedUsersList(id);

            var meeting = _meetingRepository.GetMeeting(id);

            var list = new List <InvitedUserViewModel.InvitedUsersList>();

            foreach (var kvp in invitedUsersList)
            {
                var user = _userManager.FindByIdAsync(kvp.Key).Result;
                list.Add(new InvitedUserViewModel.InvitedUsersList
                {
                    // bozy Use string interpolation
                    // DisplayedUserName = $"{user.UserName} {user.FirstName} {user.LastName}";
                    DisplayedUserName = user.UserName + " " + user.FirstName + " " + user.LastName,
                    UserName          = user.UserName,
                    Status            = kvp.Value,
                    Id = kvp.Key
                });
            }

            var vm = new InvitedUserViewModel.InvitedUserListViewModel
            {
                InvitedUsers     = _invitedUserRepository.GetInvitedUsers(id),
                MeetingId        = id,
                AvailableUsers   = _invitedUserRepository.GetAvailableUsers(id).ToList(),
                InvitedUsersList = list,
                IsEditable       = meeting.Organizer.UserName == User.Identity.Name
            };

            return(View(vm));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Add(InvitedUserViewModel.InvitedUserListViewModel vm)
        {
            var userId    = vm.SelectedToInviteUserId;
            var meetingId = vm.MeetingId;

            if (_invitedUserRepository.IfUserIsInvited(meetingId, userId))
            {
                TempData["ErrorMessage"] = Constants.ExistingMeetingInvitationMessage;
                return(RedirectToAction(nameof(List), new { id = meetingId }));
            }

            var meeting          = _meetingRepository.GetMeeting(meetingId);
            var user             = _userManager.FindByIdAsync(userId).Result;
            var games            = meeting.MeetingGame.Select(mg => mg.Game.Title);
            var meetingStartDate = ToolsExtensions
                                   .ConvertToTimeZoneFromUtc(meeting.StartDateTime, user.TimeZone, _logger)
                                   .ToString(Constants.DateTimeFormat, CultureInfo.InvariantCulture);
            var meetingEndDate = ToolsExtensions.ConvertToTimeZoneFromUtc(meeting.EndDateTime, user.TimeZone, _logger)
                                 .ToString(Constants.DateTimeFormat, CultureInfo.InvariantCulture);

            var overlappingMeetings = new List <string>();

            overlappingMeetings = _meetingRepository
                                  .GetOverlappingMeetingsForUser(meeting.StartDateTime, meeting.EndDateTime, userId)
                                  .Select(m => m.Title)
                                  .ToList();
            // bozy This variable should be inside the if part. Moreover setting a variable with a single space is a code smell

            if (overlappingMeetings.Count > 0)
            {
                // use string.Join() instead of foreach.
                var overlappingMeetingsTitle = string.Join(", ", overlappingMeetings);

                TempData["ErrorMessage"] = $"{Constants.OverlappingMeetingsMessage}: {overlappingMeetingsTitle}";
                return(RedirectToAction(nameof(List), new { id = meetingId }));
            }

            _invitedUserRepository.AddUserToMeeting(userId, meetingId, InvitationStatus.Pending);
            TempData["SuccessMessage"] = Constants.GeneralSuccessMessage;

            var appLink = Url.Action(nameof(List), "InvitedUser", new { id = meetingId }, HttpContext.Request.Scheme);
            var content =
                $"{Constants.ContentInviteUserEmail}: Organizer: {meeting.Organizer.FullName}; Start date: {meetingStartDate}; End date: {meetingEndDate};" +
                $" Games: {string.Join(", ", games)}";
            var response = await _templateSender.SendGeneralEmailAsync(new SendEmailDetails
            {
                IsHTML  = true,
                ToEmail = user.Email,
                Subject = Constants.SubjectInviteUserEmail
            }, Constants.TitleInviteUserEmail, content,
                                                                       Constants.ButtonCheckMeeting,
                                                                       appLink);

            if (response.Successful)
            {
                return(RedirectToAction(nameof(List), new { id = meetingId }));
            }
            TempData["ErrorMessage"] = Constants.GeneralSendEmailErrorMessage;
            foreach (var error in response.Errors)
            {
                _logger.LogError(error);
            }

            return(RedirectToAction(nameof(List), new { id = meetingId }));
        }