public async Task <IActionResult> Dispute([FromBody] ComplaintDisputeModel model) { if (model == null) { return(ReturnError(ErrorCodes.IncomingPayloadIsMissing, nameof(Dispute))); } try { var brokerId = User.TryGetBrokerId().Value; var apiUserId = User.UserId(); _ = await _apiOrderService.GetOrderAsync(model.OrderNumber, brokerId); var user = await _apiUserService.GetBrokerUser(model.CallingUser, brokerId); var complaint = await GetCreatedComplaint(model.OrderNumber, brokerId); _complaintService.Dispute(complaint, user?.Id ?? apiUserId, (user != null ? (int?)apiUserId : null), model.Message); await _dbContext.SaveChangesAsync(); return(Ok(new ResponseBase())); } catch (InvalidApiCallException ex) { return(ReturnError(ex.ErrorCode, nameof(Dispute))); } }
public void Dispute(ComplaintStatus status) { var service = new ComplaintService(_tolkDbContext, _clock, _notificationService, _logger); var complaint = new Complaint { Status = status }; service.Dispute(complaint, 1, null, "detta är fel"); }
public void Dispute_InvalidStatus(ComplaintStatus status) { var service = new ComplaintService(_tolkDbContext, _clock, _notificationService, _logger); var complaint = new Complaint { Status = status }; Assert.Throws <InvalidOperationException>(() => service.Dispute(complaint, 1, null, "Fulfel")); }
public async Task <IActionResult> Dispute(DisputeComplaintModel model) { var complaint = await _dbContext.Complaints.GetFullComplaintById(model.ComplaintId); if (ModelState.IsValid) { if ((await _authorizationService.AuthorizeAsync(User, complaint, Policies.Accept)).Succeeded) { if (!complaint.CanAnswer) { _logger.LogWarning("Wrong status when trying to Dispute complaint. Status: {complaint.Status}, ComplaintId: {complaint.ComplaintId}", complaint.Status, complaint.ComplaintId); return(RedirectToAction("View", "Request", new { id = complaint.RequestId, tab = "complaint" })); } _complaintService.Dispute(complaint, User.GetUserId(), User.TryGetImpersonatorId(), model.DisputeMessage); await _dbContext.SaveChangesAsync(); return(RedirectToAction("View", "Request", new { id = complaint.RequestId, tab = "complaint" })); } return(Forbid()); } return(RedirectToAction("View", "Request", new { id = complaint.RequestId, tab = "complaint" })); }