public async Task <IActionResult> UpdateVideo(VideoPostUpdateModel input) { if (!this.ModelState.IsValid) { input.LocationsDropDown = this.locationsService.GetAllLocationsAsKeyValuePair(); input.CamerasDropDown = this.cameraService.GetAllCamerasAsKeyValuePair(); input.TagsDropDown = this.tagsService.GetAllTagsAsKeyValuePair(); return(this.View(input)); } await this.postsService.UpdateVideo(input); return(this.Redirect("/VideoPosts/VideosNewest")); }
public async Task UpdateVideo(VideoPostUpdateModel input) { var video = this.postRepository.All().FirstOrDefault(x => x.Id == input.VideoId); if (video.Caption != input.Caption) { video.Caption = input.Caption; } video.Camera = await this.cameraService.GetCameraByNameAsync(input.Camera); var country = await this.countriesService.GetCountry(input.Country); video.Location = await this.locationsService.GetLocation(input.Location, country); var tags = await this.tagsService.GetTagsForPost(input.Tags); var postTags = this.postTagsRepository.All().Where(x => x.PostId == input.VideoId); foreach (var tag in postTags) { this.postTagsRepository.Delete(tag); } await this.postTagsRepository.SaveChangesAsync(); foreach (var tag in tags) { var postTag = new PostTag { PostId = video.Id, TagId = tag.Id, }; video.Tags.Add(postTag); } await this.postRepository.SaveChangesAsync(); }