public async Task <IActionResult> Document([FromForm] DocumentRequest file) { if (file == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(file)); } try { // Save Blob using (var stream = file.File.OpenReadStream()) { var url = await _azureStorageService.SaveDocumentAsync(stream, file.File.FileName, file.DocumentCategoryId); if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentException("Unable to save file."); } var document = _mapper.Map <DocumentRequest, Document>(file); document.CreatedBy = "Share Point"; document.CreatedDate = DateTime.UtcNow; document.LastModified = DateTime.UtcNow; document.LastModifiedBy = "Share Point"; document.DocumentName = file.DocumentName; document.FileName = file.File.FileName; _documentRepository.SetDocument(document); foreach (var partnerType in file.PartnerTypes.Split(',')) { var pd = new PartnerTypeDocument(); pd.PartnerTypeId = int.Parse(partnerType); pd.DocumentId = document.DocumentId; document.PartnerTypeDocuments.Add(pd); } _documentRepository.Complete(); return(CreatedAtRoute("GetDocumentById", new { documentId = document.DocumentId }, file)); } } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError)); } }