Example #1
0
        public async Task <IActionResult> FollowUser([FromForm] string followeeUserName)
        {
            var followee = await _userService.GetUserByUserNameAsync(followeeUserName);

            if (followee == null)
            {
                return(NotFound());
            }

            await _followService.FollowUserAsync(followee.Id);

            var userSetting = await _userService.GetUserSettingUserIdAsync(followee.Id);

            if (userSetting.NotifyWhenUserFollow)
            {
                var attributes = new List <NotificationAttribute>
                {
                    new NotificationAttribute
                    {
                        Name  = "Link",
                        Value = Url.Action(nameof(ProfileController.GetUserFollowers), "Profile",
                                           new { username = followee.UserName })
                    }
                };

                var notification = new Notification(followee, await _userService.GetCurrentUserIdAsync(),
                                                    NotificationType.Following, attributes);

                followee.CreateNotification(notification);

                await _unitOfWork.CompleteAsync();

                await _notificationService.PushNotification(followee.Id, notification.Id);
            }

            await _unitOfWork.CompleteAsync();

            return(NoContent());
        }