public async Task <Photo> CreateAsync(string title, byte[] photoFile, string imageMimeType, string description, string userName, string tokenValue) { Guard.Against.NullOrEmpty(title, nameof(title)); DateTime createdDate = DateTime.Now; var photo = new Photo(title, photoFile, imageMimeType, description, createdDate, userName, new List <Comment>()); await _photosRepository.CreateAsync(photo, tokenValue); return(photo); }
public async Task <Photo> UploadAsync(Photo photo) { var user = await userService.GetUserAsync(); if (await photosAuthorizationService.ItemMayBeCreatedAsync(user, photo)) { photo.CreatedDate = DateTime.Now; photo.UserName = user.Identity.Name; return(await repository.CreateAsync(photo)); } else { throw new UnauthorizedCreateAttemptException <Photo>($"Unauthorized Create Attempt of Photo {photo.Id}"); } }