/// <summary> /// Add an <see cref="ImageFileDto"/> to Database /// </summary> /// <param name="dto">Data Transfer Object as <see cref="ImageFileDto"/></param> /// <returns><see cref="Task{ImageFile}"/></returns> /// <inheritdoc cref="ICommand{T}.AddAsync(T)"/> public async Task <ImageFileDto> AddAsync(ImageFileDto dto) { if (dto == null) { throw new ArgumentNullException(nameof(dto)); } Images image = new Images { ContentType = dto.ContentType, Length = dto.Length, Name = dto.Name, FileName = dto.FileName, Data = dto.Data(), Thumbnail = dto.Thumbnail() }; await _dbContext.Images.AddAsync(image).ConfigureAwait(false); // Save image in database await _dbContext.SaveChangesAsync().ConfigureAwait(false); PicturesXref xRef = new PicturesXref { RecipeId = dto.RecipeId, ImageId = image.Id }; _dbContext.PicturesXref.Add(xRef); // Save xRef in database await _dbContext.SaveChangesAsync().ConfigureAwait(false); dto.Id = image.Id; return(dto); }
/// <summary> /// Add an <see cref="ImageFileDto"/> to Database /// </summary> /// <param name="dto">Data Transfer Object as <see cref="ImageFileDto"/></param> /// <returns><see cref="ImageFileDto"/></returns> /// <inheritdoc cref="ICommand{T}.Add(T)"/> public ImageFileDto Add(ImageFileDto dto) { if (dto == null) { throw new ArgumentNullException(nameof(dto)); } Images image = new Images() { ContentType = dto.ContentType, Length = dto.Length, Name = dto.Name, FileName = dto.FileName, Data = dto.Data(), Thumbnail = dto.Thumbnail() }; _dbContext.Images.Add(image); // Save image in database _dbContext.SaveChanges(); PicturesXref xRef = new PicturesXref { RecipeId = dto.RecipeId, ImageId = image.Id }; _dbContext.PicturesXref.Add(xRef); // Save xRef in database _dbContext.SaveChanges(); dto.Id = image.Id; return(dto); }