public async Task<IActionResult> Create() { IActionResult statusCodeResult = BadRequest(); await Request.HasFiles(async (file) => { var filePath = Path.GetTempFileName(); using var stream = new FileStream(filePath, FileMode.Create); await file.CopyToAsync(stream); byte[] bytes = stream.ConvertToBlob(); FileModel fileModel = new FileModel { Name = file.FileName, Base64 = stream.ToBase64String(), ContentType = file.ContentType }; GuidResponse guidResponse = new GuidResponse() { Guid = await _fileService.Create(fileModel) }; statusCodeResult = Created("/api/" + guidResponse.Guid, guidResponse); }); return statusCodeResult; }
public async Task <IActionResult> Create(MockModelEnumerable request) { ObjectResult statusCodeResult = new ObjectResult(null); ValidateResult validateResult = _mockService.Validate(request.Mocks); (await validateResult.Success(async() => { GuidResponse guidResponse = new GuidResponse() { Guid = await _mockService.Create(request.Mocks) }; statusCodeResult = Created("/api/" + guidResponse.Guid, guidResponse); })) .Error((errorMessages) => { statusCodeResult = BadRequest(errorMessages); }); return(statusCodeResult); }
/// <summary> /// Get a new GUID from the Pocket API. /// </summary> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The GUID /// </returns> public async Task <string> GetGuid(CancellationToken cancellationToken = default(CancellationToken)) { GuidResponse response = await Request <GuidResponse>("guid", cancellationToken, requireAuth : false); return(response.Guid); }