/// <summary> /// Method to perform file modification using Magick.Net /// </summary> /// <returns>Path to the new file ( modified )</returns> public async Task <DefaultServiceResponse> ModifyFile(ModifyModel model) { // Get last uploaded photo by the customer var lastUploadedImageName = DataContext.CustomerImageFiles.ToList().Where(imageFile => imageFile.CustomerId == model.UserId).OrderByDescending(orderBy => orderBy.UploadTime).Select(response => response.FullName); var intesivity = model.Intesivity; var editedFileName = ""; using (var image = new MagickImage(lastUploadedImageName.First())) { switch (model.SelectedOperation) { case "CycleColorMap": image.CycleColormap(intesivity); break; case "FloodFill": image.FloodFill(10, 10, 10); break; case "Flop": image.Flop(); break; case "GammaCorrect": image.GammaCorrect(intesivity); // gramma break; case "GausiianBlur": image.GaussianBlur(intesivity, intesivity); // double radius + double sigma break; case "MedianFilter": image.MedianFilter(intesivity); // radius break; case "MotionBlur": image.MotionBlur(10, 10, 10); break; case "Negate": image.Negate(); // simple negate break; default: break; } if (model.UseFrame) { image.Border(7, 7); } editedFileName = lastUploadedImageName.First().Replace(Path.GetFileNameWithoutExtension(lastUploadedImageName.First()), Path.GetFileNameWithoutExtension(lastUploadedImageName.First()) + "_modified").Replace(Path.GetExtension(lastUploadedImageName.First()), "." + model.OutputFileType.ToLower()); using (File.Create(editedFileName)) image.Write(editedFileName); } // Save file to the DB var originalImageId = DataContext.CustomerImageFiles.Where(imageData => imageData.CustomerId == model.UserId && imageData.FullName.Contains(Path.GetFileNameWithoutExtension(lastUploadedImageName.First()))).Select(result => result.Id).First(); await DataContext.CustomerEditedImageFiles.AddAsync(new ResultImageFIleModel { Id = new Guid(), CustomerId = model.UserId, FullName = editedFileName, OriginalImageId = originalImageId.ToString(), UploadTime = DateTime.Now }); await DataContext.SaveChangesAsync(); return(new DefaultServiceResponse { ResponseData = "../" + Path.Combine("CustomersImages", Path.GetFileName(editedFileName)) }); }