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()); }
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); }
public PhotoController(ILogger <PhotoController> logger) { _logger = logger; photoService = PhotoService.Create(); }