public async Task <IActionResult> AddNewVideo([FromBody] NewVideoVM vm)
        {
            if (!ModelState.IsValid)
            {
                string errorMsg = null;
                foreach (var m in ModelState.Values)
                {
                    foreach (var msg in m.Errors)
                    {
                        errorMsg = msg.ErrorMessage;
                    }
                }
                return(BadRequest(errorMsg));
            }

            var user = await _userManager.FindByIdAsync(User.Identity.Name);

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

            if (await _userManager.IsInRoleAsync(user, "Admin"))
            {
                VideoPost newVideoPost = new VideoPost
                {
                    CareerId           = vm.CareerId ?? null,
                    CategoryId         = vm.CategoryId,
                    CountryId          = vm.CountryId,
                    UploaderId         = vm.UploaderId,
                    SalaryInfoId       = vm.SalaryInfoId,
                    Likes              = vm.Likes,
                    Title              = vm.Title,
                    UploadedDate       = DateTime.UtcNow,
                    YouTubeVideoId     = vm.YouTubeVideoId,
                    SharerId           = vm.SharerId,
                    IsGoogleDriveVideo = vm.IsGoogleDriveVideo ? (byte)1 : (byte)0
                };

                await _vpRepository.AddAsync(newVideoPost);

                await _vpRepository.CommitAsync();

                var videoCommentVM = Mapper.Map <VideoPost, VideoPostVM>(newVideoPost);

                return(CreatedAtRoute("GetVideoPost", new
                {
                    controller = "Admin",
                    id = videoCommentVM.VideoPostId
                }, videoCommentVM));
            }

            return(StatusCode(401));
        }
Exemple #2
0
        public async Task <IActionResult> UpdateVideoPostLikes(int id)
        {
            if (id <= 0)
            {
                return(NotFound());
            }

            var videoPost = _vpRepository.GetSingle(vc => vc.VideoPostId == id);

            if (videoPost == null)
            {
                return(NotFound());
            }
            else
            {
                videoPost.Likes += 1;
            }

            _vpRepository.Update(videoPost);
            await _vpRepository.CommitAsync();

            return(new NoContentResult());
        }