internal void UpdateInterpreter(InterpreterBroker interpreter) { interpreter.Email = Email; interpreter.FirstName = FirstName; interpreter.LastName = LastName; interpreter.PhoneNumber = PhoneNumber; interpreter.OfficialInterpreterId = OfficialInterpreterId; }
internal void UpdateAndChangeStatusInterpreter(InterpreterBroker interpreter, int?userId, int?impersonatorId, DateTimeOffset?inactivatedAt) { UpdateInterpreter(interpreter); interpreter.InactivatedAt = inactivatedAt; interpreter.InactivatedBy = userId; interpreter.ImpersonatingInactivatedBy = impersonatorId; interpreter.IsActive = IsActive; }
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); }
internal static InterpreterModel GetModelFromInterpreter(InterpreterBroker interpreter) { return(new InterpreterModel { Id = interpreter?.InterpreterBrokerId, Email = interpreter.Email, FirstName = interpreter.FirstName, LastName = interpreter.LastName, PhoneNumber = interpreter.PhoneNumber, OfficialInterpreterId = interpreter.OfficialInterpreterId, IsActive = interpreter.IsActive }); }
internal static InterpreterDetailsModel GetModelFromEntity(InterpreterBroker interpreter) { return(new InterpreterDetailsModel { IsActive = interpreter.IsActive, Email = interpreter.Email, FirstName = interpreter.FirstName, InterpreterId = interpreter.InterpreterBrokerId, LastName = interpreter.LastName, InterpreterInformationType = EnumHelper.GetCustomName(InterpreterInformationType.ExistingInterpreter), OfficialInterpreterId = interpreter.OfficialInterpreterId, PhoneNumber = interpreter.PhoneNumber }); }
internal InterpreterAnswerDto GetInterpreterModel(InterpreterGroupAnswerModel interpreterModel, int brokerId, bool isMainInterpreter = true) { if (interpreterModel == null) { throw new InvalidApiCallException(ErrorCodes.InterpreterAnswerNotValid); } if (!interpreterModel.IsValid) { throw new InvalidApiCallException(ErrorCodes.InterpreterAnswerNotValid); } if (isMainInterpreter && !interpreterModel.Accepted) { throw new InvalidApiCallException(ErrorCodes.InterpreterAnswerMainInterpereterDeclined); } if (!isMainInterpreter && !interpreterModel.Accepted) { return(new InterpreterAnswerDto { Accepted = false, DeclineMessage = interpreterModel.DeclineMessage }); } InterpreterBroker interpreter = GetInterpreter(new InterpreterDetailsModel(interpreterModel.Interpreter), brokerId); //Does not handle Kammarkollegiets tolknummer if (interpreter == null) { throw new InvalidApiCallException(ErrorCodes.InterpreterNotFound); } return(new InterpreterAnswerDto { Interpreter = interpreter, CompetenceLevel = EnumHelper.GetEnumByCustomName <CompetenceAndSpecialistLevel>(interpreterModel.CompetenceLevel).Value, RequirementAnswers = interpreterModel.RequirementAnswers.Select(ra => new OrderRequirementRequestAnswer { Answer = ra.Answer, CanSatisfyRequirement = ra.CanMeetRequirement, OrderRequirementId = ra.RequirementId, }).ToList(), ExpectedTravelCosts = interpreterModel.ExpectedTravelCosts, ExpectedTravelCostInfo = interpreterModel.ExpectedTravelCostInfo }); }
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!!"); } }
public async Task <ActionResult> Create(InterpreterModel model) { if (ModelState.IsValid) { if (!_interpreterService.IsUniqueOfficialInterpreterId(model.OfficialInterpreterId, User.GetBrokerId())) { ModelState.AddModelError(nameof(model.OfficialInterpreterId), $"Er förmedling har redan registrerat en tolk med detta tolknummer (Kammarkollegiets) i tjänsten."); } else { InterpreterBroker interpreter = new InterpreterBroker(User.GetBrokerId()); model.UpdateInterpreter(interpreter); await _dbContext.AddAsync(interpreter); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(List), new InterpreterListModel { Message = "Ny tolk har skapats" })); } } return(View(model)); }
public async Task <InterpreterBroker> GetInterpreter(int interpreterId, InterpreterInformation interpreterInformation, int brokerId) { NullCheckHelper.ArgumentCheckNull(interpreterInformation, nameof(GetInterpreter), nameof(OrderService)); if (interpreterId == Constants.NewInterpreterId) { if (!IsUniqueOfficialInterpreterId(interpreterInformation.OfficialInterpreterId, brokerId)) { throw new ArgumentException("Er förmedling har redan registrerat en tolk med detta tolknummer (Kammarkollegiets) i tjänsten.", nameof(interpreterId)); } var interpreter = new InterpreterBroker( interpreterInformation.FirstName, interpreterInformation.LastName, brokerId, interpreterInformation.Email, interpreterInformation.PhoneNumber, interpreterInformation.OfficialInterpreterId ); await _dbContext.AddAsync(interpreter); return(interpreter); } return(await _dbContext.InterpreterBrokers.GetInterpreterBrokerById(interpreterId)); }
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; }
internal InterpreterBroker GetInterpreter(InterpreterDetailsModel interpreterModel, int brokerId, bool updateInformation = true) { if (interpreterModel == null) { throw new InvalidApiCallException(ErrorCodes.InterpreterAnswerNotValid); } InterpreterBroker interpreter = null; switch (EnumHelper.GetEnumByCustomName <InterpreterInformationType>(interpreterModel.InterpreterInformationType)) { case InterpreterInformationType.ExistingInterpreter: interpreter = _dbContext.InterpreterBrokers .SingleOrDefault(i => i.InterpreterBrokerId == interpreterModel.InterpreterId && i.BrokerId == brokerId); break; case InterpreterInformationType.AuthorizedInterpreterId: interpreter = _dbContext.InterpreterBrokers .SingleOrDefault(i => i.OfficialInterpreterId == interpreterModel.OfficialInterpreterId && i.BrokerId == brokerId); break; case InterpreterInformationType.NewInterpreter: //check if unique officialInterpreterId for broker if (_interpreterService.IsUniqueOfficialInterpreterId(interpreterModel.OfficialInterpreterId, brokerId)) { //Create the new interpreter, connected to the provided broker var newInterpreter = new InterpreterBroker( interpreterModel.FirstName, interpreterModel.LastName, brokerId, interpreterModel.Email, interpreterModel.PhoneNumber, interpreterModel.OfficialInterpreterId ); _dbContext.Add(newInterpreter); return(newInterpreter); } else { throw new InvalidApiCallException(ErrorCodes.InterpreterOfficialIdAlreadySaved); } default: return(null); } if (updateInformation) { interpreter.IsActive = interpreterModel.IsActive; if (!string.IsNullOrWhiteSpace(interpreterModel.FirstName)) { interpreter.FirstName = interpreterModel.FirstName; } if (!string.IsNullOrWhiteSpace(interpreterModel.LastName)) { interpreter.LastName = interpreterModel.LastName; } if (!string.IsNullOrWhiteSpace(interpreterModel.Email)) { interpreter.Email = interpreterModel.Email; } if (!string.IsNullOrWhiteSpace(interpreterModel.PhoneNumber)) { interpreter.PhoneNumber = interpreterModel.PhoneNumber; } if (!string.IsNullOrWhiteSpace(interpreterModel.OfficialInterpreterId)) { if (_interpreterService.IsUniqueOfficialInterpreterId(interpreterModel.OfficialInterpreterId, brokerId, interpreter.InterpreterBrokerId)) { interpreter.OfficialInterpreterId = interpreterModel.OfficialInterpreterId; } else { throw new InvalidApiCallException(ErrorCodes.InterpreterOfficialIdAlreadySaved); } } } return(interpreter); }