public IActionResult GetById(long id) { var loggedInUserRole = HttpContext.Session.GetString("LoggedInUserRole"); var contentType = Request.ContentType; User user = _userData.GetById(id); if (user == null) { return(NotFound()); } if (contentType == null) { if (loggedInUserRole != null) { if (loggedInUserRole.Equals("1")) { long loggedInUserId = long.Parse(HttpContext.Session.GetString("LoggedInUserId")); if (user.Blocked == true && user.Id != loggedInUserId) { return(StatusCode(401)); } } } else { if (user.Blocked == true) { return(StatusCode(401)); } } } user.Followers = _followData.GetFollowers(user.Id); user.Following = _followData.GetFollowings(user.Id); user.UserVideos = _videoData.GetByOwnerId(user.Id); user.LikedVideos = _videoData.GetLikedVideos(user); user.UserComments = _commentData.GetCommentsByUser(user.Id); 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(singleUserDTO)); } else if (contentType.Equals("text/html")) { SingleUserDTO newDTO = SingleUserDTO.ConvertUserToDTO(user); return(View("SingleUserInfo", newDTO)); } return(StatusCode(415)); } return(View("UserPage", singleUserDTO)); }
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())); } }