public async Task <Response <int> > Handle(UpdateExpenseClaimCommand request, CancellationToken cancellationToken)
            {
                var claim = await _claimRepository.GetByIdAsync(request.Id);

                if (claim == null)
                {
                    throw new ApiException("Expense claim not Found.");
                }
                else
                {
                    claim.Title             = request.Title;
                    claim.RequesterId       = request.RequesterId;
                    claim.ApproverId        = request.ApproverId;
                    claim.SubmitDate        = request.SubmitDate;
                    claim.ApprovalDate      = request.ApprovalDate;
                    claim.ProcessedDate     = request.ProcessedDate;
                    claim.TotalAmount       = request.TotalAmount;
                    claim.Status            = request.Status;
                    claim.RequesterComments = request.RequesterComments;
                    claim.ApproverComments  = request.ApproverComments;
                    claim.FinanceComments   = request.FinanceComments;

                    await _claimRepository.UpdateAsync(claim);

                    await _unitOfWork.Commit(cancellationToken);

                    return(new Response <int>(claim.Id));
                }
            }
Пример #2
0
            public async Task <Result <int> > Handle(UpdateExpenseClaimCommand command, CancellationToken cancellationToken)
            {
                var expenseClaim = await _repository.GetByIdAsync(command.Id);

                if (expenseClaim == null)
                {
                    return(Result <int> .Fail($"Product Not Found."));
                }
                else
                {
                    expenseClaim.Title                = command.Title ?? expenseClaim.Title;
                    expenseClaim.RequesterName        = command.RequesterName ?? expenseClaim.RequesterName;
                    expenseClaim.RequesterID          = (command.RequesterID == 0) ? expenseClaim.RequesterID : command.RequesterID;
                    expenseClaim.ApproverName         = command.ApproverName ?? expenseClaim.ApproverName;
                    expenseClaim.ApproverID           = (command.ApproverID == 0) ? expenseClaim.ApproverID : command.ApproverID;
                    expenseClaim.SubmitDate           = (command.SubmitDate == DateTime.MinValue) ? expenseClaim.SubmitDate : command.SubmitDate;
                    expenseClaim.ApprovalDate         = (command.ApprovalDate == DateTime.MinValue) ? expenseClaim.ApprovalDate : command.ApprovalDate;
                    expenseClaim.ProcessedDate        = (command.ProcessedDate == DateTime.MinValue) ? expenseClaim.ProcessedDate : command.ProcessedDate;
                    expenseClaim.TotalAmount          = (command.TotalAmount == 0) ? expenseClaim.TotalAmount : command.TotalAmount;
                    expenseClaim.Status               = command.Status ?? expenseClaim.Status;
                    expenseClaim.RequesterComments    = command.RequesterComments ?? expenseClaim.RequesterComments;
                    expenseClaim.ApproverComments     = command.ApproverComments ?? expenseClaim.ApproverComments;
                    expenseClaim.FinanceComments      = command.FinanceComments ?? expenseClaim.FinanceComments;
                    expenseClaim.ExpensClaimLineItems = command.ExpensClaimLineItems ?? expenseClaim.ExpensClaimLineItems;


                    await _repository.UpdateAsync(expenseClaim);

                    if (command.Status == "submitted")
                    {
                        var route = $"reports/process/{expenseClaim.Id}";
                        await _mailService.SendAsync(new MailRequest()
                        {
                            From = "*****@*****.**", To = "*****@*****.**", Body = $"Report is resubmitted. <a href=https://localhost:44380/{route}> click here to see the report</a>", Subject = "Report is resubmitted"
                        });
                    }
                    await _unitOfWork.Commit(cancellationToken);

                    return(Result <int> .Success(expenseClaim.Id));
                }
            }
            public async Task <Result <int> > Handle(ChangeStatusCommand command, CancellationToken cancellationToken)
            {
                var expenseClaim = await _repository.GetByIdAsync(command.Id);

                if (expenseClaim == null)
                {
                    return(Result <int> .Fail($"Product Not Found."));
                }
                else
                {
                    expenseClaim.Status            = command.Status ?? expenseClaim.Status;
                    expenseClaim.ApproverName      = command.ApproverName ?? expenseClaim.ApproverName;
                    expenseClaim.ApproverID        = (command.ApproverID == 0) ? expenseClaim.ApproverID : command.ApproverID;
                    expenseClaim.ApprovalDate      = (command.ApprovalDate == DateTime.MinValue) ? expenseClaim.ApprovalDate : command.ApprovalDate;
                    expenseClaim.ProcessedDate     = (command.ProcessedDate == DateTime.MinValue) ? expenseClaim.ProcessedDate : command.ProcessedDate;
                    expenseClaim.RequesterComments = command.RequesterComments ?? expenseClaim.RequesterComments;
                    expenseClaim.ApproverComments  = command.ApproverComments ?? expenseClaim.ApproverComments;
                    expenseClaim.FinanceComments   = command.FinanceComments ?? expenseClaim.FinanceComments;

                    await _repository.UpdateAsync(expenseClaim);

                    await _unitOfWork.Commit(cancellationToken);

                    if (command.Status == "approved")
                    {
                        await _mailService.SendAsync(
                            new MailRequest()
                        {
                            From    = "*****@*****.**",
                            To      = "*****@*****.**",
                            Body    = "Your Expense Claim is approved by approval",
                            Subject = "Expense Claim is approved"
                        }
                            );
                    }
                    else if (command.Status == "quried")
                    {
                        var route = $"reports/rework/{command.Id}";
                        await _mailService.SendAsync(
                            new MailRequest()
                        {
                            From    = "*****@*****.**",
                            To      = "*****@*****.**",
                            Body    = $"Your Expense Claim is queried by approval.                    Rework is required. <a href=https://localhost:44380/{route}>Click here to                          rework</a>",
                            Subject = "Expense Claim is quried"
                        }
                            );
                    }
                    else if (command.Status == "rejected")
                    {
                        await _mailService.SendAsync(
                            new MailRequest()
                        {
                            From    = "*****@*****.**",
                            To      = "*****@*****.**",
                            Body    = "Your Expense Claim is rejected by approval",
                            Subject = "Expense Claim is rejected"
                        }
                            );
                    }
                    else if (command.Status == "financeRejected")
                    {
                        await _mailService.SendAsync(
                            new MailRequest()
                        {
                            From    = "*****@*****.**",
                            To      = "*****@*****.**",
                            Body    = "Your Expense Claim is rejected by finance",
                            Subject = "Expense Claim is rejected by approval"
                        }
                            );
                    }
                    else if (command.Status == "processed")
                    {
                        await _mailService.SendAsync(
                            new MailRequest()
                        {
                            From    = "*****@*****.**",
                            To      = "*****@*****.**",
                            Body    = "Your Expense Claim is processed by finance",
                            Subject = "Expense Claim is processed"
                        }
                            );
                    }

                    return(Result <int> .Success(expenseClaim.Id));
                }
            }