public async Task <ListingImage> AddImage(Guid listingId, byte[] imageContent, string imageMediaType) { if (imageContent == null) { throw new ArgumentNullException(nameof(imageContent)); } if (string.IsNullOrWhiteSpace(imageMediaType)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(imageMediaType)); } var listing = await _findListingCoordinator.Find(listingId); if (listing == null) { return(null); } var imageFileName = $"{Guid.NewGuid()}"; var url = await _imageStore.PersistArticleEntryMedia(imageFileName, imageContent, imageMediaType); var image = new ListingImage() { Listing = listing, ListingId = listingId, Url = url }; await _dbContext.Add(image); await _dbContext.SaveChanges(); return(image); }
public async Task <Listing> Create(EditListingRequest newListing) { if (newListing == null) { throw new ArgumentNullException(nameof(newListing)); } var listing = new Listing(); listing.Update(newListing); if (!_validationHelper.HasValidFields(listing)) { return(null); } await _dbContext.Add(listing); await _dbContext.SaveChanges(); return(listing); }
public async Task <Listing> Edit(Guid listingId, Listing existingListing, EditListingRequest editRequest) { if (existingListing == null) { throw new ArgumentNullException(nameof(existingListing)); } if (editRequest == null) { throw new ArgumentNullException(nameof(editRequest)); } _dbContext.Attach(existingListing); existingListing.Update(editRequest); if (!_validationHelper.HasValidFields(existingListing)) { return(null); } await _dbContext.SaveChanges(); return(existingListing); }