public IActionResult AddImage() { var viewModel = new ImagePostInputModel(); viewModel.LocationsDropDown = this.locationsService.GetAllLocationsAsKeyValuePair(); viewModel.CamerasDropDown = this.cameraService.GetAllCamerasAsKeyValuePair(); viewModel.TagsDropDown = this.tagsService.GetAllTagsAsKeyValuePair(); return(this.View(viewModel)); }
public async Task <IActionResult> AddImage(ImagePostInputModel 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 imageInfo = await CloudinaryExtension.UploadImageAsync(this.cloudinary, input.Image); var user = await this.userManager.GetUserAsync(this.User); await this.postsService.CreateImagePostAsync(input, user.Id, imageInfo); return(this.Redirect("/")); }
public async Task CreateImagePostAsync(ImagePostInputModel input, string userId, ImageUploadResult imageInput) { var image = await this.imagesService.CreateImage(userId, imageInput); 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 == "Image"); var post = new Post { AddedByUserId = userId, Camera = camera, Caption = input.Caption, Type = postType, Dislikes = 0, Likes = 0, Image = image, ImageId = image.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(); }