public PriceInformation GetPrices(Request request, CompetenceAndSpecialistLevel competenceLevel, decimal?expectedTravelCost) { if (request == null) { throw new ArgumentNullException(nameof(request)); } return(GetPrices( request.Order.StartAt, request.Order.EndAt, EnumHelper.Parent <CompetenceAndSpecialistLevel, CompetenceLevel>(competenceLevel), request.Order.CustomerOrganisation.PriceListType, request.RankingId, request.Order.CreatedAt, expectedTravelCost)); }
public async Task <JsonResult> InterpreterByInternalId(int id, CompetenceAndSpecialistLevel competenceLevel, int?orderId, int?orderGroupId) { int?brokerId = User.TryGetBrokerId(); VerificationResult result = VerificationResult.NotFound; if (brokerId.HasValue) { var interpreter = await _dbContext.InterpreterBrokers.SingleOrDefaultAsync(i => i.BrokerId == brokerId && i.InterpreterBrokerId == id); if (interpreter != null) { return(await InterpreterByOfficialId(interpreter.OfficialInterpreterId, competenceLevel, orderId, orderGroupId)); } } return(WrapResultInJson(result)); }
public async Task Accept( Request request, DateTimeOffset acceptTime, int userId, int?impersonatorId, InterpreterBroker interpreter, InterpreterLocation interpreterLocation, CompetenceAndSpecialistLevel competenceLevel, List <OrderRequirementRequestAnswer> requirementAnswers, List <RequestAttachment> attachedFiles, decimal?expectedTravelCosts, string expectedTravelCostInfo, DateTimeOffset?latestAnswerTimeForCustomer, string brokerReferenceNumber ) { NullCheckHelper.ArgumentCheckNull(request, nameof(Accept), nameof(RequestService)); NullCheckHelper.ArgumentCheckNull(interpreter, nameof(Accept), nameof(RequestService)); //maybe should be moved to AcceptRequest depending on ordergroup requesting each... request.Order.Requirements = await _tolkDbContext.OrderRequirements.GetRequirementsForOrder(request.Order.OrderId).ToListAsync(); request.Order.InterpreterLocations = await _tolkDbContext.OrderInterpreterLocation.GetOrderedInterpreterLocationsForOrder(request.Order.OrderId).ToListAsync(); request.Order.CompetenceRequirements = await _tolkDbContext.OrderCompetenceRequirements.GetOrderedCompetenceRequirementsForOrder(request.Order.OrderId).ToListAsync(); CheckSetLatestAnswerTimeForCustomerValid(latestAnswerTimeForCustomer, nameof(Accept)); AcceptRequest(request, acceptTime, userId, impersonatorId, interpreter, interpreterLocation, competenceLevel, requirementAnswers, attachedFiles, expectedTravelCosts, expectedTravelCostInfo, await VerifyInterpreter(request.OrderId, interpreter, competenceLevel), latestAnswerTimeForCustomer: latestAnswerTimeForCustomer, brokerReferenceNumber); //Create notification switch (request.Status) { case RequestStatus.Accepted: _notificationService.RequestAccepted(request); break; case RequestStatus.Approved: _notificationService.RequestAnswerAutomaticallyApproved(request); break; default: throw new NotImplementedException("NOT OK!!"); } }
private static VerificationResult CheckInterpreter(CompetenceAndSpecialistLevel competenceLevel, Order order, TellusInterpreterResponse information) { if (information.TotalMatching < 1) { return(VerificationResult.NotFound); } var interpreter = information.Result.First(); if (competenceLevel == CompetenceAndSpecialistLevel.EducatedInterpreter) { return(VerifyInterpreter(order.StartAt, interpreter.Educations.Where(c => c.Language == order.Language.TellusName))); } else { return(VerifyInterpreter(order.StartAt, interpreter.Competences.Where(c => c.Language == order.Language.TellusName && c.Competencelevel.Id == competenceLevel.GetTellusName()))); } }
private async Task <VerificationResult?> VerifyInterpreter(int orderId, InterpreterBroker interpreter, CompetenceAndSpecialistLevel competenceLevel) { VerificationResult?verificationResult = null; if (competenceLevel != CompetenceAndSpecialistLevel.OtherInterpreter && _tolkBaseOptions.Tellus.IsActivated) { //Only check if the selected level is other than other. verificationResult = await _verificationService.VerifyInterpreter(interpreter.OfficialInterpreterId, orderId, competenceLevel); } return(verificationResult); }
private void AcceptRequest(Request request, DateTimeOffset acceptTime, int userId, int?impersonatorId, InterpreterBroker interpreter, InterpreterLocation interpreterLocation, CompetenceAndSpecialistLevel competenceLevel, List <OrderRequirementRequestAnswer> requirementAnswers, List <RequestAttachment> attachedFiles, decimal?expectedTravelCosts, string expectedTravelCostInfo, VerificationResult?verificationResult, DateTimeOffset?latestAnswerTimeForCustomer, string brokerReferenceNumber, bool overrideRequireAccept = false) { NullCheckHelper.ArgumentCheckNull(request, nameof(AcceptRequest), nameof(RequestService)); //Get prices var prices = _priceCalculationService.GetPrices(request, competenceLevel, expectedTravelCosts); request.Accept(acceptTime, userId, impersonatorId, interpreter, interpreterLocation, competenceLevel, requirementAnswers, attachedFiles, prices, expectedTravelCostInfo, latestAnswerTimeForCustomer, brokerReferenceNumber, verificationResult, overrideRequireAccept); }
public async Task ChangeInterpreter( Request request, DateTimeOffset changedAt, int userId, int?impersonatorId, InterpreterBroker interpreter, InterpreterLocation interpreterLocation, CompetenceAndSpecialistLevel competenceLevel, List <OrderRequirementRequestAnswer> requirementAnswers, IEnumerable <RequestAttachment> attachedFiles, decimal?expectedTravelCosts, string expectedTravelCostInfo, DateTimeOffset?latestAnswerTimeForCustomer, string brokerReferenceNumber ) { NullCheckHelper.ArgumentCheckNull(request, nameof(ChangeInterpreter), nameof(RequestService)); NullCheckHelper.ArgumentCheckNull(interpreter, nameof(ChangeInterpreter), nameof(RequestService)); CheckSetLatestAnswerTimeForCustomerValid(latestAnswerTimeForCustomer, nameof(ChangeInterpreter)); request.Order.Requirements = await _tolkDbContext.OrderRequirements.GetRequirementsForOrder(request.Order.OrderId).ToListAsync(); request.Order.InterpreterLocations = await _tolkDbContext.OrderInterpreterLocation.GetOrderedInterpreterLocationsForOrder(request.Order.OrderId).ToListAsync(); request.Order.CompetenceRequirements = await _tolkDbContext.OrderCompetenceRequirements.GetOrderedCompetenceRequirementsForOrder(request.Order.OrderId).ToListAsync(); if (interpreter.InterpreterBrokerId == await GetOtherInterpreterIdForSameOccasion(request) && !(interpreter.Interpreter?.IsProtected ?? false)) { throw new InvalidOperationException("Det går inte att tillsätta samma tolk som redan är tillsatt som extra tolk för samma tillfälle."); } Request newRequest = new Request(request.Ranking, request.ExpiresAt, changedAt, isChangeInterpreter: true, requestGroup: request.RequestGroup) { Order = request.Order, Status = RequestStatus.AcceptedNewInterpreterAppointed }; bool noNeedForUserAccept = await NoNeedForUserAccept(request, expectedTravelCosts); request.Order.Requests.Add(newRequest); VerificationResult?verificationResult = null; if (competenceLevel != CompetenceAndSpecialistLevel.OtherInterpreter && _tolkBaseOptions.Tellus.IsActivated) { //Only check if the selected level is other than other. verificationResult = await _verificationService.VerifyInterpreter(interpreter.OfficialInterpreterId, request.OrderId, competenceLevel); } newRequest.ReplaceInterpreter(changedAt, userId, impersonatorId, interpreter, interpreterLocation, competenceLevel, requirementAnswers, attachedFiles, _priceCalculationService.GetPrices(request, competenceLevel, expectedTravelCosts), noNeedForUserAccept, request, expectedTravelCostInfo, brokerReferenceNumber, verificationResult, latestAnswerTimeForCustomer ); // need requestid for the link await _tolkDbContext.SaveChangesAsync(); if (noNeedForUserAccept) { _notificationService.RequestChangedInterpreterAccepted(newRequest, InterpereterChangeAcceptOrigin.NoNeedForUserAccept); } else { _notificationService.RequestChangedInterpreter(newRequest); } request.Status = RequestStatus.InterpreterReplaced; }
public async Task <JsonResult> InterpreterByOfficialId(string officialInterpreterId, CompetenceAndSpecialistLevel competenceLevel, int?orderId, int?orderGroupId) { if (!orderId.HasValue && orderGroupId.HasValue) { var order = await _dbContext.Orders.FirstOrDefaultAsync(g => g.OrderGroupId == orderGroupId); orderId = order?.OrderId; } if (!orderId.HasValue) { return(WrapResultInJson(VerificationResult.NotFound)); } _logger.LogInformation($"Verifying interpreterId {officialInterpreterId} for competence {competenceLevel} on order {orderId}"); return(WrapResultInJson(await _verificationService.VerifyInterpreter(officialInterpreterId, orderId.Value, competenceLevel))); }
public async Task <VerificationResult> VerifyInterpreter(string interpreterId, int orderId, CompetenceAndSpecialistLevel competenceLevel, bool reVerify = false) { if (string.IsNullOrWhiteSpace(interpreterId)) { return(VerificationResult.NotFound); } try { var order = await _dbContext.Orders.GetOrderWithLanguageByOrderId(orderId); if (string.IsNullOrEmpty(order.Language.TellusName)) { return(VerificationResult.LanguageNotRegistered); } var response = await client.GetAsync($"{_tolkBaseOptions.Tellus.Uri}{interpreterId}"); string content = await response.Content.ReadAsStringAsync(); TellusInterpreterResponse information = JsonConvert.DeserializeObject <TellusInterpreterResponse>(content); return(CheckInterpreter(competenceLevel, order, information)); } catch (Exception e) { _logger.LogError(e, $"Failed to verify the interpreter against {_tolkBaseOptions.Tellus.Uri}" + (reVerify ? " for second time" : " for first time")); //try to verify once more if reVerify is false since it's probably most often connection problem/timeout return(!reVerify ? await VerifyInterpreter(interpreterId, orderId, competenceLevel, true) : VerificationResult.UnknownError); } }