public IActionResult Add(IFormFile uploadedFile)
 {
     if (uploadedFile != null)
     {
         var    account = accountBaseFunction.GetMyAccount(User.Identity.Name, null, "Name");
         string path    = "/Files/" + uploadedFile.FileName;
         using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create))
         {
             uploadedFile.CopyTo(fileStream);
         }
         if (account != null)
         {
             Photo photo = new Photo {
                 Name = "/Files/" + uploadedFile.FileName, AccountId = account.Id
             };
             photoService.Create(photo);
         }
         return(Ok());
     }
     return(BadRequest());
 }
예제 #2
0
        public void Test_PhotoService()
        {
            var tableRepository = new TableRepository();
            var blobRepository  = new BlobRepository();
            var visionService   = new VisionService();
            var photoService    = new PhotoService(tableRepository, blobRepository, visionService);

            //Photo
            const string fileName = @"Desert.jpg";
            var          filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"Images\\{fileName}");

            if (!File.Exists(filePath))
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            //Photo Entity
            var partitionKey = Guid.NewGuid();
            var entity       = new PhotoEntity(partitionKey.ToString(), Rowkey)
            {
                ID    = partitionKey,
                Title = "Desert",
                Owner = Owner,
            };

            using (Stream file = File.OpenRead(filePath))
            {
                photoService.Create(entity, file);
            }

            var photos = photoService.GetAll();

            Assert.IsNotNull(photos);
            Assert.IsTrue(photos.Count > 0);
            var singleOrDefault = photos.SingleOrDefault(p => p.ID.Equals(entity.ID));

            Assert.IsNotNull(singleOrDefault);
            Assert.AreEqual("Desert", singleOrDefault.Title);
        }
예제 #3
0
 public PhotoController(ILogger <PhotoController> logger)
 {
     _logger      = logger;
     photoService = PhotoService.Create();
 }