public override string GetLocalFileName(HttpContentHeaders headers) { if (string.CompareOrdinal("png", headers.ContentDisposition.FileName) != 0 && string.CompareOrdinal("jpg", headers.ContentDisposition.FileName) != 0) { Error = ErrorType.InvalidImageType; throw new Exception(); } // TODO: Write to db and use entity id as filename. // String filename = Guid.NewGuid().ToString() + "." + headers.ContentDisposition.FileName; // Since we get string from header.. makesure all dangerous characters are removed filename = filename.Replace("\\", "_"); filename = filename.Replace("/", "_"); filename = filename.Replace("(", "_"); filename = filename.Replace(")", "_"); filename = filename.Replace(":", "_"); var model = new IssueImageModel { IssueId = _issueID, Created = DateTime.Now, Image = new IssueImageModel.ImageInfo(filename) }; _imageRepository.Create(model); ImageID = model.Id; return(filename); }
private ImageVM ModelToVM(IssueImageModel model) { return(new ImageVM { Id = model.Id, IssueId = model.IssueId, Created = model.Created, Image = new ImageVM.ImageInfo(model.Image.FileName) }); }
protected void DeleteImageFile(String location, IssueImageModel image) { try { String imageStorageLocation = @"C:\IssueManager\ImagesStorage\"; imageStorageLocation += location.ToUpper(); imageStorageLocation += @"\"; imageStorageLocation += image.IssueId.ToString(); imageStorageLocation += @"\"; imageStorageLocation += image.Image.FileName; System.IO.File.Delete(imageStorageLocation); } catch (Exception ex) { } }
public void Create(IssueImageModel model) { var issue = _context.Issues.FirstOrDefault(x => x.Id == model.IssueId); if (issue == null) { throw new IssueNotFoundException(); } // TODO: Validate user rights var issueImage = new IssueImage { IssueId = model.IssueId, FileName = model.Image.FileName, Created = DateTime.UtcNow }; issue.Images.Add(issueImage); _context.SaveChanges(); model.Id = issueImage.Id; }