Пример #1
0
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var notification = await _repository.NotificationIncludeComments(id);

            if (notification == null)
            {
                return(NotFound());
            }
            var commentViewModel = new List <CommentViewModel>();
            var user             = await _userManager.FindByIdAsync(notification.OwnerID);

            if (notification.Comments != null)
            {
                foreach (var el in notification.Comments)
                {
                    var Owner = await _userManager.FindByIdAsync(el.OwnerID);

                    if (Owner == null)
                    {
                        var OwnerName = "Deleted user";
                        commentViewModel.Add(
                            new CommentViewModel()
                        {
                            Comment   = el,
                            OwnerName = OwnerName
                        });
                    }
                    else
                    {
                        var OwnerName = Owner.UserName == null ? "" : $"{Owner.UserName} ({Owner.FirstName} {Owner.LastName})";
                        commentViewModel.Add(
                            new CommentViewModel()
                        {
                            Comment   = el,
                            OwnerName = OwnerName
                        });
                    }
                }
            }
            var NotificationViewModel = new NotificationViewModel()
            {
                Notification     = notification,
                OwnerName        = $"{user.UserName} ({user.FirstName} {user.LastName})",
                CommentViewModel = commentViewModel
            };


            return(View(NotificationViewModel));
        }