Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
 public void AddImage(int placeId, Stream input, File file)
 {
     _fileService.AddImage(input, file);
     this.AddImage(placeId, file);
 }