public IActionResult DeletePart(string id) { var myContext = new ElectronicsWarehouseContext(); var myPart = myContext.Articles.FirstOrDefault(n => n.Id == int.Parse(id)); myContext.Articles.Remove(myPart); myContext.SaveChanges(); PictureProcessor.DeletePicture(myPart.PictureName); ViewData["Id"] = id; return(View()); }
public CreatePictureResponse Create(CreatePictureRequest request) { var response = new CreatePictureResponse(); bool isPicture = FileHelper.IsPicture(request.ContentType, request.FileExtention); if (isPicture == false) { response.Result = CreatePictureResult.InvalidFormat; return(response); } bool isValidFileSize = FileHelper.IsValidImageSize(request.InputStream.Length); if (isValidFileSize == false) { response.Result = CreatePictureResult.TooLarge; return(response); } string picName = FileHelper.GeneratePictureName(request.FileExtention); string fullPath = $"{request.ServerPath}{picName}"; if (request.MaxHeight.HasValue && request.MaxWidth.HasValue) { PictureProcessor.SaveJpeg(fullPath, request.InputStream, request.Quality, request.MaxWidth.Value, request.MaxHeight.Value); } else { PictureProcessor.SaveJpeg(fullPath, request.InputStream, request.Quality); } string urlPath = $"{request.UrlPath}{picName}"; Picture picture = new Picture { FullPath = fullPath, Url = urlPath, UploadDate = DateTime.Now, }; this.PictureRepository.Insert(picture); response.Picture = picture; response.Result = CreatePictureResult.Success; return(response); }