public File AddImage(string source, string description, long userId) { File file; using (var input = FileHelper.GetStreamFromUrl(source)) { file = new File { Description = description, ContentLength = Convert.ToInt32(input.Length), ContentType = "image/jpeg", CreatedBy = new User { Id = userId }, }; AddImage(input, file); } return file; }
public void AddImage(Stream input, File file) { // validate image Image.FromStream(input); var fileName = GenerateFileName(file.CreatedBy.Id, input.Length); input.SaveToFile(fileName); var entity = new FileEntity { FileName = fileName, Description = file.Description, ContentLength = file.ContentLength, ContentType = file.ContentType, UserId = file.CreatedBy.Id, InsertDate = DateTime.Now, }; _context.Files.AddObject(entity); _context.SaveChanges(); file.Id = entity.Id; }
internal void AddImage(int placeId, File file) { var placeEntity = _context.Places.Where(p => p.Id == placeId).ToList().First(); var fileEntity = _context.Files.Where(f => f.Id == file.Id).ToList().First(); placeEntity.Files.Add(fileEntity); _context.SaveChanges(); }
public void AddImage(int placeId, Stream input, File file) { _fileService.AddImage(input, file); this.AddImage(placeId, file); }