public virtual async Task <EvlRequestDto> SubmitEvlRequest(CancellationToken cancellationToken) { if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } MultipartMemoryStreamProvider provider = new MultipartMemoryStreamProvider(); await Request.Content.ReadAsMultipartAsync(provider, cancellationToken); bool isFirstPart = true; EvlRequestDto evlRequestDto = null; foreach (HttpContent requestPart in provider.Contents) { if (isFirstPart == true) { evlRequestDto = JsonConvert.DeserializeObject <EvlRequestDto>(await requestPart.ReadAsStringAsync()); evlRequestDto.Status = EvlRequestStatus.SabteAvalie; EvlRequest evlRequest = Mapper.FromDtoToEntity(evlRequestDto); evlRequest.CustomerId = Guid.Parse(UserInformationProvider.GetCurrentUserId()); evlRequestDto = Mapper.FromEntityToDto(await EvlRequestsRepository.AddAsync(evlRequest, cancellationToken)); isFirstPart = false; continue; } else { byte[] data = await requestPart.ReadAsByteArrayAsync(); int typeId = int.Parse(Path.GetFileName(requestPart.Headers.ContentDisposition.FileName.Trim('\"'))); await EvlRequestFilesRepository.AddAsync(new EvlRequestFile { EvlRequestId = evlRequestDto.Id, TypeId = typeId, File = data }, cancellationToken); } } if (evlRequestDto == null) { throw new BadRequestException($"{nameof(EvlRequestDto)} is null"); } return(evlRequestDto); }
public virtual async Task <EvlRequestExpertDto> FindEvlRequestExpert(FindEvlReqeustExpertArgs args, CancellationToken cancellationToken) { EvlRequest evlRequest = await(await EvlRequestsRepository.GetAllAsync(cancellationToken)).Where(e => e.Id == args.requestId).Include(c => c.Customer).FirstOrDefaultAsync(); if (evlRequest == null) { throw new ResourceNotFoundException("evlRequest is null"); } List <EvlRequestFile> requestFiles = await(await EvlRequestFileRepository.GetAllAsync(cancellationToken)).Where(e => e.EvlRequestId == evlRequest.Id).ToListAsync(); HttpClient httpClient = HttpClientFactory.CreateClient("SoltaniHttpClient"); SoltaniFindExpertRequest soltaniFindExpertParams = new SoltaniFindExpertRequest(); soltaniFindExpertParams.UserID = evlRequest.CustomerId; soltaniFindExpertParams.RequestID = evlRequest.Id; soltaniFindExpertParams.Type = (short)evlRequest.InsuranceType; DefaultDateTimeUtils defaultDateTimeUtils = new DefaultDateTimeUtils(); soltaniFindExpertParams.AccidentDate = defaultDateTimeUtils.ConvertMiladiToShamsi(evlRequest.AccidentDate); soltaniFindExpertParams.MapLat = evlRequest.Latitude; soltaniFindExpertParams.MapLng = evlRequest.Longitude; soltaniFindExpertParams.Address = "آدرس تستی"; requestFiles.ForEach(r => soltaniFindExpertParams.Photos.Add(new RequestPhoto { Data = Convert.ToBase64String(r.File), Type = r.TypeId })); if (evlRequest.InsuranceType == Enums.InsuranceType.Badane) { soltaniFindExpertParams.LostName = evlRequest.OwnerFirstName; soltaniFindExpertParams.LostFamily = evlRequest.OwnerLastName; soltaniFindExpertParams.LostInsuranceID = evlRequest.InsurerId; soltaniFindExpertParams.LostCarID = evlRequest.CarId; soltaniFindExpertParams.LostMobile = evlRequest.Customer.Mobile; } else { soltaniFindExpertParams.LostName = evlRequest.LostFirstName; soltaniFindExpertParams.LostFamily = evlRequest.LostLastName; soltaniFindExpertParams.LostMobile = evlRequest.Customer.Mobile; soltaniFindExpertParams.LostCarID = evlRequest.LostCarId; soltaniFindExpertParams.CrmName = evlRequest.OwnerFirstName; soltaniFindExpertParams.CrmFamily = evlRequest.OwnerLastName; soltaniFindExpertParams.CrmInsuranceID = evlRequest.InsurerId; soltaniFindExpertParams.CrmInsuranceNO = evlRequest.InsurerNo; soltaniFindExpertParams.CrmNumberplate = evlRequest.PlateNumber; soltaniFindExpertParams.CrmCarID = evlRequest.CarId; } string json = JsonConvert.SerializeObject(soltaniFindExpertParams); StringContent stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); HttpResponseMessage findExpertRawResponse = await httpClient.PostAsync("FindNearExpert", stringContent); try { findExpertRawResponse.EnsureSuccessStatusCode(); } catch (Exception ex) { throw new DomainLogicException("FindNearExpert call failed", ex); } EvlRequestExpertDto evlRequestExpert = JsonConvert.DeserializeObject <EvlRequestExpertDto>(await findExpertRawResponse.Content.ReadAsStringAsync()); evlRequest.Code = evlRequestExpert.FileID; await EvlRequestsRepository.UpdateAsync(evlRequest, cancellationToken); return(evlRequestExpert); }