private async Task ActionOnCost(PurchaseOrderResponse message, PgPurchaseOrderResponse payload, Cost cost, SystemAdminUserIdentity adminUser) { var adminUserId = adminUser.Id; OperationResponse response; switch (message.ActivityType) { case ActivityTypes.Updated: switch (payload.ApprovalStatus) { case ApprovalStatuses.Approved: if (ApprovalRequired(cost)) { await ApproveCost(cost.Id, adminUser); } break; case ApprovalStatuses.Rejected: message.Payload.TryGetValue(nameof(PgPurchaseOrderResponse.Comments), StringComparison.OrdinalIgnoreCase, out var commentsToken); var comments = commentsToken != null?commentsToken.ToObject <string>() : string.Empty; response = await _approvalService.Reject(cost.Id, adminUser, BuType.Pg, comments, SourceSystem.Coupa); if (response.Success) { await _emailNotificationService.CostHasBeenRejected(cost.Id, adminUserId, ApprovalType.Brand.ToString(), comments); } break; // ADC-1731 Dealing with COUPA's limitations case ApprovalStatuses.AwaitingDecisionInCost: if (ApprovalRequired(cost) && await HasCostBeenApproved(cost, payload)) { await ApproveCost(cost.Id, adminUser); } break; } break; case ActivityTypes.Cancelled: response = await _costActionService.CompleteCancel(cost.Id, BuType.Pg); if (response.Success) { await _emailNotificationService.CostHasBeenCancelled(cost.Id); } break; case ActivityTypes.Recalled: await _costActionService.CompleteRecall(cost.Id, adminUser); break; } }
private async Task Reject(PurchaseOrderResponse message, PurchaseOrderErrorMessage errorMessage) { var adminUser = await _efContext.CostUser.FirstOrDefaultAsync(u => u.Email == ApprovalMemberModel.BrandApprovalUserEmail); var adminUserIdentity = new SystemAdminUserIdentity(adminUser); var cost = await _efContext.Cost.SingleAsync(c => c.CostNumber == message.CostNumber); var result = await _approvalService.Reject(cost.Id, adminUserIdentity, GetBuType(message.ClientName), errorMessage.Message, SourceSystem.Coupa); if (!result.Success) { await OnTechnicalError(message.CostNumber, $"Failed to reject cost due to error! {result.Messages}"); } else { var error = $"Cost {message.CostNumber} rejected due to : {errorMessage.Type.GetStringValue()} {errorMessage.Message}"; _logger.Information(error); await _emailNotificationService.CostHasBeenRejected( cost.Id, adminUser.Id, ApprovalType.Brand.ToString(), error); } }
public Task RejectApproval([FromBody] NotificationApprovalViewModel inputModel) => approvalService.Reject(inputModel.Id, Guid.Parse(LoggedUserId));