Пример #1
0
        public IActionResult GetAllUsers()
        {
            var contentType = Request.ContentType;
            //IEnumerable<UserDTO> userDTO = new List<UserDTO>();
            IEnumerable <User> users = new List <User>();

            users = _userData.GetAll();

            foreach (var u in users)
            {
                u.UserVideos = _videoData.GetByOwnerId(u.Id);
            }
            List <UserForAdminPage> userDTO = UserForAdminPage.ConvertDTO(users);

            if (contentType != null)
            {
                if (contentType.Equals("application/json"))
                {
                    return(Json(userDTO));
                }
                else if (contentType.Equals("text/html"))
                {
                    UsersViewModel newDTO = new UsersViewModel();
                    newDTO.Users = users;
                    return(View("UserInfo", newDTO));
                }
                return(StatusCode(415));
            }
            return(Json(userDTO));
        }
Пример #2
0
        public IActionResult AddVideo(AddVideoDTO videoDTO, IFormFile image)
        {
            if (ModelState.IsValid)
            {
                var loggedInUserId = HttpContext.Session.GetString("LoggedInUserId");

                if (loggedInUserId == null)
                {
                    return(StatusCode(401));
                }
                User user = _userData.GetById(long.Parse(loggedInUserId));
                if (user == null)
                {
                    return(StatusCode(401));
                }
                if (user.Blocked == true)
                {
                    return(StatusCode(401));
                }

                Video newVideo = new Video();
                newVideo.AllowComments    = videoDTO.AllowComments;
                newVideo.AllowRaiting     = videoDTO.AllowRaiting;
                newVideo.Blocked          = false;
                newVideo.Deleted          = false;
                newVideo.Description      = videoDTO.Description;
                newVideo.CreationDate     = DateTime.Today;
                newVideo.Name             = videoDTO.Name;
                newVideo.NumberOfDislikes = 0;
                newVideo.NumberOfLikes    = 0;
                newVideo.NumberOfViews    = 0;
                newVideo.OwnerId          = user.Id;
                newVideo.VideoUrl         = videoDTO.VideoUrl;
                newVideo.Visibility       = videoDTO.Visibility;

                if (image != null)
                {
                    newVideo.PhotoUrl = AddImage(newVideo.Name, user.Username, image);
                }
                else
                {
                    newVideo.PhotoUrl = "defaultVideoImage.jpg";
                }


                newVideo = _videoData.Create(newVideo);
                VideoDTO video       = VideoDTO.ConvertVideoToDTO(newVideo);
                var      contentType = Request.ContentType;

                user.Followers   = _followData.GetFollowers(user.Id);
                user.Following   = _followData.GetFollowings(user.Id);
                user.UserVideos  = _videoData.GetByOwnerId(user.Id);
                user.LikedVideos = _videoData.GetLikedVideos(user);
                foreach (var u in user.LikedVideos)
                {
                    u.Owner = _userData.GetById(u.OwnerId);
                }

                SingleUserDTO singleUserDTO = SingleUserDTO.ConvertUserToDTO(user);

                if (contentType != null)
                {
                    if (contentType.Equals("application/json"))
                    {
                        return(Json(video));
                    }
                    else if (contentType.Equals("text/html"))
                    {
                        return(View("UserPage", singleUserDTO));
                    }
                    return(View("UserPage", singleUserDTO));
                }
                return(Json(video));
            }
            else
            {
                return(Json(new VideoDTO()));
            }
        }