public async Task <IActionResult> Create(CreateAdvertViewModel model, IFormFile formFile) { if (ModelState.IsValid) { var createAdvertModel = _mapper.Map <CreateAdvertModel>(model); var advertResponse = await _client.Create(createAdvertModel); var id = advertResponse.Id; var fileName = ""; if (formFile != null) { fileName = !string.IsNullOrEmpty(formFile.FileName) ? formFile.FileName : id; var filePath = $"{id}/{fileName}"; try { using (var fileStream = formFile.OpenReadStream()) { var response = await _fileUploader.FileUploader(filePath, fileStream).ConfigureAwait(false); if (!response) { throw new Exception("Something went wrong. Could not upload the image to file repository."); } } var advertConfirmRequest = new CreateAdvertConfirmModel { Id = id, Status = AdvertStatus.Active }; var confirmResponse = await _client.Confirm(advertConfirmRequest).ConfigureAwait(false); if (!confirmResponse) { throw new Exception($"Cannot confirm advert of Id = {id}"); } return(RedirectToAction("Index", "Home")); } catch (Exception ex) { var advertConfirmRequest = new CreateAdvertConfirmModel { Id = id, Status = AdvertStatus.Pending }; await _client.Confirm(advertConfirmRequest).ConfigureAwait(false); Console.WriteLine(ex); } } } return(View(model)); }