public IActionResult AddVideo() { var viewModel = new VideoPostInputModel(); viewModel.LocationsDropDown = this.locationsService.GetAllLocationsAsKeyValuePair(); viewModel.CamerasDropDown = this.cameraService.GetAllCamerasAsKeyValuePair(); viewModel.TagsDropDown = this.tagsService.GetAllTagsAsKeyValuePair(); return(this.View(viewModel)); }
public async Task <IActionResult> AddVideo(VideoPostInputModel input) { if (!this.ModelState.IsValid) { input.LocationsDropDown = this.locationsService.GetAllLocationsAsKeyValuePair(); input.CamerasDropDown = this.cameraService.GetAllCamerasAsKeyValuePair(); input.TagsDropDown = this.tagsService.GetAllTagsAsKeyValuePair(); return(this.View(input)); } var videoInfo = await CloudinaryExtension.UploadVideoAsync(this.cloudinary, input.Video); var user = await this.userManager.GetUserAsync(this.User); await this.postsService.CreateVideoPostAsync(input, user.Id, videoInfo); return(this.Redirect("/")); }
public async Task CreateVideoPostAsync(VideoPostInputModel input, string userId, VideoUploadResult videoInput) { var video = await this.videosService.CreateVideo(userId, videoInput); var camera = await this.cameraService.GetCameraByNameAsync(input.Camera); var country = await this.countriesService.GetCountry(input.Country); var location = await this.locationsService.GetLocation(input.Location, country); var postType = this.postTypeRepository.All().FirstOrDefault(x => x.Name == "Video"); var post = new Post { AddedByUserId = userId, Camera = camera, Caption = input.Caption, Type = postType, Dislikes = 0, Likes = 0, Video = video, VideoId = video.Id, Location = location, }; var tags = await this.tagsService.GetTagsForPost(input.Tags); foreach (var tag in tags) { post.Tags.Add(new PostTag { Tag = tag, Post = post, }); } await this.postRepository.AddAsync(post); await this.postRepository.SaveChangesAsync(); }