public async Task <IActionResult> AddPhotoForUser(int userId, PhotoForCreation photoDto) { var user = await _userService.GetUser(userId); if (user == null) { return(BadRequest("Could not find user")); } var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); if (currentUserId != user.Id) { return(Unauthorized()); } var photoForReturn = await _photoService.AddPhotoForUser(userId, photoDto); if (photoForReturn != null) { return(CreatedAtRoute("GetPhoto", new { id = photoForReturn.Id }, photoForReturn)); } return(BadRequest()); }
public async Task <IActionResult> AddPhotoForUser([FromForm] UserPhotoDto userPhotoDto) { var result = await _photoService.AddPhotoForUser(userPhotoDto); if (result.IsSuccessful) { return(Ok(result.Result)); } //return CreatedAtAction("GetPhoto", new { id = photo.Id }, photo); return(BadRequest(result.Message)); }
public async Task <IActionResult> UploadStreamFile() { if (!Helpers.MultipartRequestHelper.IsMultipartContentType(Request.ContentType)) { return(BadRequest($"Expected a multipart request, but got {Request.ContentType}")); } var file = await GetFileStream(HttpContext.Request.Body); if (!_fileFormatInspectorProvider.ValidateFileFormat(file.stream)) { return(BadRequest("Given file format is not supported")); } var fileMetadata = new PhotoForStreamUploadMetadataDto(); var bindingSuccessful = await TryUpdateModelAsync(fileMetadata, prefix : string.Empty, valueProvider : file.formValueProvider); if (!bindingSuccessful && !ModelState.IsValid) { return(BadRequest(ModelState)); } var user = GetUser(); var fileUploadResult = await _filesStorageProvider.UploadAsync(file.stream, fileMetadata, user.PendingUploadPhotosFolderName); var photoForUser = new PhotoForUserDto { FileId = fileUploadResult.FileId, UserId = user.Id, Url = fileUploadResult.Uri }; await _photoService.AddPhotoForUser(photoForUser); return(NoContent()); }
public async Task <IActionResult> AddPhotoForUser(int userId, [FromForm] PhotoForCreationDto photoForCreationDto) { var addPhoto = await photoService.AddPhotoForUser(userId, photoForCreationDto); return(Ok(addPhoto)); }