Пример #1
0
        public NotificationsViewDTO Handle()
        {
            var NotificationsViewDTO = new NotificationsViewDTO()
            {
            };
            var Notifications = from x in _NotificationBox.GetUserNotifications(_CurrentUser.UserName)
                                orderby x.NotificationDate descending
                                select x;

            foreach (var notification in Notifications)
            {
                var ElapsedMinutes = DateTime.Now.Subtract(notification.NotificationDate).TotalMinutes;
                var ElapsedHours   = DateTime.Now.Subtract(notification.NotificationDate).TotalHours;
                var ElapsedDays    = DateTime.Now.Subtract(notification.NotificationDate).TotalDays;

                var ElapsedMonths = DateTime.Now.Subtract(notification.NotificationDate).TotalDays / 12;
                NotificationsViewDTO.AllNotifications.Add(new NotificationDTO()
                {
                    Id                = notification.Id,
                    Message           = notification.Message,
                    NotificationBoxId = notification.NotificationBoxId,
                    RecieverUsername  = notification.RecieverUsername,
                    ElapsedHour       = Math.Round(ElapsedHours),
                    ElapsedMinute     = Math.Round(ElapsedMinutes),
                    ElapsedDay        = Math.Round(ElapsedDays)
                });
            }
            return(NotificationsViewDTO);
        }
Пример #2
0
        public PostViewDto Handle()
        {
            var FriendList = _FriendListStore.GetFriendListOfUser(CurrentUser.Id);

            FriendList.Users = _FriendListStore.GetFriendsOfUser(FriendList.Id);

            var Notifications  = _NotificationBox.GetUserNotifications(ExistingAccount.Username);
            var FriendRequests = _FriendListStore.GetIncomingFriendRequests(FriendList.Id);
            var Posts          = GetCurrentUserPosts().Concat(GetAllFriendPosts(FriendList)).ToList();

            var postViewDTO = new PostViewDto
            {
                FriendRequestCount = FriendRequests.Count,
                NotificationCount  = Notifications.Count,
                Permissions        = ExistingAccount.UserType,
                AllPosts           = Posts
            };

            return(postViewDTO);
        }
Пример #3
0
        public IActionResult Profile()
        {
            try
            {
                var _currentUser = _context.Users.Find(userManager.GetUserId(User));
                if (_currentUser is null)
                {
                    throw new DomainException(ErrorMessages.NotSignedIn);
                }

                var existingAccount = _userStore.GetByIdentityUserId(_currentUser.Id);
                if (existingAccount.AccountStatus.Equals(Status.Suspended))
                {
                    signInManager.SignOutAsync();
                }

                var FriendList        = _FriendListStore.GetFriendListOfUser(_currentUser.Id);
                var FriendUsers       = _FriendListStore.GetFriendsOfUser(FriendList.Id);
                var GroupsWithUser    = GroupStore.GetGroupsWithUser(existingAccount.UserId);
                var NotificationCount = _notificationBox.GetUserNotifications(existingAccount.Username).Count
                                        + _FriendListStore.GetIncomingFriendRequests(FriendList.Id).Count;

                var ProfileViewModel = new ProfileViewModel()
                {
                    FirstName         = existingAccount.FirstName,
                    LastName          = existingAccount.LastName,
                    Location          = existingAccount.Location,
                    Email             = existingAccount.Email,
                    Username          = existingAccount.Username,
                    Occupation        = existingAccount.Occupation,
                    LastActive        = existingAccount.LastActive,
                    JoinDate          = existingAccount.DateJoined,
                    UserType          = existingAccount.UserType,
                    Groups            = GroupsWithUser,
                    UserId            = _currentUser.Id,
                    NotificationCount = NotificationCount,
                    Friends           = _mapper.Map <List <FriendDTO> >(FriendUsers)
                };
                foreach (var friend in ProfileViewModel.Friends)
                {
                    var account = _userStore.GetByUsername(friend.Username);
                    if (account.AccountStatus.Equals(Status.Active))
                    {
                        friend.AccountId = account.Id;
                    }
                    else
                    {
                        ProfileViewModel.Friends.Remove(friend);
                    }
                }
                return(View(ProfileViewModel));
            }
            catch (DomainException ex)
            {
                _logger.LogError(ex.Message);
                return(RedirectToAction("Login", "Accounts"));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(RedirectToAction("ServerError"));
            }
        }