public void Delete(ImageTransitional entity) { Guard.WhenArgument(entity, GlobalConstants.ImageTransitionalRequiredExceptionMessage) .IsNull() .Throw(); var entityDb = this.mapper.Map <Image>(entity); this.images.Delete(entityDb); this.context.Save(); }
private async Task <Image> CreateImage( ImageTransitional entity, string cropMode, string outputFormat) { int width, height; switch (entity.Format) { case ImageFormatType.Ordinary: { width = GlobalConstants.ImageWidth; height = GlobalConstants.ImageHeight; break; } case ImageFormatType.Cover: { width = GlobalConstants.ImageCoverWidth; height = GlobalConstants.ImageCoverHeight; break; } default: { width = GlobalConstants.ImageAvatarWidth; height = GlobalConstants.ImageAvatarHeight; break; } } var uniqueName = Guid.NewGuid().ToString(); string url = await this.storage.UploadFile( entity.FileStream, entity.FileName + "_" + uniqueName, entity.FileExtension, width, height, cropMode, outputFormat); var newImage = this.modelDbFactory.CreateImage( entity.FileName, entity.FileExtension, url, entity.Format, null, null); return(newImage); }
public async Task <Image> Create(ImageTransitional entity, ImageFormatType format) { Guard.WhenArgument( entity, GlobalConstants.ImageTransitionalRequiredExceptionMessage) .IsNull() .Throw(); entity.Format = format; var entityDb = await this.CreateImage(entity, null, null); this.images.Create(entityDb); await this.context.SaveAsync(); return(entityDb); }