public async Task AddRatingQuestionAnswer(RatingQuestionAnswerData ratingQuestionAnswer, bool saveChanges = false) { if (ratingQuestionAnswer.RatingQuestionId == null || ratingQuestionAnswer.RatingQuestionId == Guid.Empty) { throw new ValidationException("Answer must have a question"); } if (!ratingQuestionAnswer.LoadId.HasValue) { throw new ValidationException("Answer must have a load attached"); } if (!ratingQuestionAnswer.LoadClaimId.HasValue) { throw new ValidationException("Answer must be tied to a load claim"); } var entity = _mapper.Map <RatingQuestionAnswerEntity>(ratingQuestionAnswer); _context.RatingQuestionAnswers.Add(entity); if (saveChanges) { await _context.SaveChangesAsync(); } }
public void AddRatingQuestion_Should_ThrowLoadRequired() { _svc = CreateService(); var add = new RatingQuestionAnswerData() { RatingQuestionId = VALID_QUESTION_ID }; _svc.Awaiting(x => x.AddRatingQuestionAnswer(add)).Should() .Throw <ValidationException>() .WithMessage("Answer must have a load attached"); }
public void AddRatingQuestion_Should_ThrowLoadClaimRequired() { _svc = CreateService(); var add = new RatingQuestionAnswerData() { RatingQuestionId = VALID_QUESTION_ID, LoadId = Guid.NewGuid() }; _svc.Awaiting(x => x.AddRatingQuestionAnswer(add)).Should() .Throw <ValidationException>() .WithMessage("Answer must be tied to a load claim"); }
public async Task <IActionResult> DeleteDetailLoad([FromRoute] Guid loadId, [FromBody] RatingQuestionAnswerData ratingQuestionAnswer) { try { if (!_userContext.UserId.HasValue) { throw new EmptyUserIdException("Invalid UserId"); } return(Success(await _shippingService.DeleteLoad(loadId, _userContext.UserName, ratingQuestionAnswer))); } catch (Exception e) { throw e; } }
public async Task AddRatingQuestion_Should_NotSave() { _svc = CreateService(); var add = new RatingQuestionAnswerData() { RatingQuestionId = VALID_QUESTION_ID, LoadId = Guid.NewGuid(), LoadClaimId = Guid.NewGuid() }; await _svc.AddRatingQuestionAnswer(add); //string userId, System.Threading.CancellationToken _db.Verify(x => x.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Never); }
public async Task <ShippingLoadData> RemoveCarrierFromLoad(Guid loadId, string username, RatingQuestionAnswerData ratingQuestionAnswer) { _securityService.GuardAction(SecurityActions.Loadshop_Ui_Shop_It_Load_Edit); var updateLoad = await _context.Loads .Include(x => x.LoadTransactions) .Include(x => x.Contacts) .Include(x => x.LoadStops) .Include(x => x.Equipment) .SingleOrDefaultAsync(x => x.LoadId == loadId); if (updateLoad == null) { throw new Exception("Load not found"); } if (!AuthorizedForCustomer(updateLoad.CustomerId)) { throw new UnauthorizedAccessException($"User is not authorized for customer: {updateLoad.CustomerId}"); } if (updateLoad.LoadTransactions == null || updateLoad.LoadTransactions.Count == 0) { throw new Exception($"Load Carrier may not be removed - Load {loadId} has no transactions"); } var loadTransactions = updateLoad.LoadTransactions .OrderByDescending(loadTransaction => loadTransaction.CreateDtTm) .ToList(); var bookedTransactionTypes = _serviceUtilities.MapShipperSearchTypeToTransactionList(ShipperSearchTypeData.Booked); if (!bookedTransactionTypes.Contains(updateLoad.LatestTransactionTypeId)) { throw new Exception("Load Carrier may not be removed - not an active Load"); } AddLoadTransaction(updateLoad, TransactionTypes.PendingRemoveScac); var originalLoadHistory = _mapper.Map <LoadHistoryEntity>(updateLoad); updateLoad.IsAccepted = false; var newLoadHistory = _mapper.Map <LoadHistoryEntity>(updateLoad); if (_serviceUtilities.HasLoadChanged(originalLoadHistory, newLoadHistory)) { _context.LoadHistories.Add(newLoadHistory); } var loadClaim = GetLatestLoadClaim(loadTransactions); ratingQuestionAnswer.LoadClaimId = loadClaim.LoadClaimId; ratingQuestionAnswer.LoadId = loadId; await _ratingService.AddRatingQuestionAnswer(ratingQuestionAnswer); await _context.SaveChangesAsync(username); var ratingQuestion = await _ratingService.GetRatingQuestion(ratingQuestionAnswer.RatingQuestionId); //Todo validate update load contacts logic _notificationService.SendCarrierRemovedEmail(updateLoad, loadClaim?.User, updateLoad.Contacts, this._userContext.Email, ratingQuestion.DisplayText); return(_mapper.Map <ShippingLoadData>(updateLoad)); }
/// <summary> /// Removes the load from loadshop, if removed from booked tab, a rating question is prompted and the answer will be recorded /// </summary> /// <param name="loadId"></param> /// <param name="username"></param> /// <param name="ratingQuestionAnswer"></param> /// <returns></returns> public async Task <ShippingLoadData> DeleteLoad(Guid loadId, string username, RatingQuestionAnswerData ratingQuestionAnswer = null) { _securityService.GuardAction(SecurityActions.Loadshop_Ui_Shopit_Load_Manual_Delete); var updateLoad = _context.Loads .Include(x => x.LoadTransactions) .Include(x => x.CarrierScacs) .Include(x => x.PostedLoadCarrierGroups) .SingleOrDefault(x => x.LoadId == loadId); if (updateLoad == null) { throw new Exception("Load not found"); } if (!AuthorizedForCustomer(updateLoad.CustomerId)) { throw new UnauthorizedAccessException($"User is not authorized for customer: {updateLoad.CustomerId}"); } AddLoadTransaction(updateLoad, TransactionTypes.PendingRemove); /** * https://kbxltrans.visualstudio.com/Suite/_workitems/edit/38578 * Delete all LoadCarrierScacs associated with this Load */ _context.LoadCarrierScacs.RemoveRange(updateLoad.CarrierScacs); _context.PostedLoadCarrierGroups.RemoveRange(updateLoad.PostedLoadCarrierGroups); if (ratingQuestionAnswer != null) { // the load was removed from a booked tab var loadClaim = GetLatestLoadClaim(updateLoad.LoadTransactions); ratingQuestionAnswer.LoadClaimId = loadClaim.LoadClaimId; ratingQuestionAnswer.LoadId = loadId; await _ratingService.AddRatingQuestionAnswer(ratingQuestionAnswer); } await _context.SaveChangesAsync(username); return(_mapper.Map <ShippingLoadData>(updateLoad)); }