private cor_approvaldetail BuildApprovalDetailObject(SupplierMultipleStaffApprovalCommand request, cor_supplier currentItem, int staffId)
            {
                var approvalDeatil = new cor_approvaldetail();
                var previousDetail = _detailService.GetApprovalDetailsAsync(currentItem.SupplierId, currentItem.WorkflowToken).Result;

                approvalDeatil.ArrivalDate = currentItem.CreatedOn ?? DateTime.Now;

                if (previousDetail.Count() > 0)
                {
                    approvalDeatil.ArrivalDate = previousDetail.OrderByDescending(s => s.ApprovalDetailId).FirstOrDefault().Date;
                }

                approvalDeatil.Comment       = "Ok";
                approvalDeatil.Date          = DateTime.Today;
                approvalDeatil.StatusId      = (int)ApprovalStatus.Approved;
                approvalDeatil.TargetId      = currentItem.SupplierId;
                approvalDeatil.StaffId       = staffId;
                approvalDeatil.WorkflowToken = currentItem.WorkflowToken;
                return(approvalDeatil);
            }
        private cor_approvaldetail BuildApprovalDetailObject(LPOStaffApprovalCommand request, purch_plpo currentItem, int staffId)
        {
            var approvalDeatil = new cor_approvaldetail();
            var previousDetail = _detailService.GetApprovalDetailsAsync(request.TargetId, currentItem.WorkflowToken).Result;

            approvalDeatil.ArrivalDate = currentItem.RequestDate;

            if (previousDetail.Count() > 0)
            {
                approvalDeatil.ArrivalDate = previousDetail.OrderByDescending(s => s.ApprovalDetailId).FirstOrDefault().Date;
            }

            approvalDeatil.Comment         = request.ApprovalComment;
            approvalDeatil.Date            = DateTime.Today;
            approvalDeatil.StatusId        = request.ApprovalStatus;
            approvalDeatil.TargetId        = request.TargetId;
            approvalDeatil.StaffId         = staffId;
            approvalDeatil.ReferredStaffId = request.ReferredStaffId;
            approvalDeatil.WorkflowToken   = currentItem.WorkflowToken;
            return(approvalDeatil);
        }
Ejemplo n.º 3
0
        public async Task <ApprovalDetailsRespObj> Handle(GetCurrentTargetApprovalDetailQuery request, CancellationToken cancellationToken)
        {
            var list = await _detail.GetApprovalDetailsAsync(request.TargetId, request.WorkflowToken);

            var supplierList = await _supRepo.GetAllSupplierAsync();

            var staff = await _serverRequest.GetAllStaffAsync();

            var response = new ApprovalDetailsRespObj {
                Status = new APIResponseStatus {
                    IsSuccessful = true, Message = new APIResponseMessage()
                }
            };

            var temp          = list;
            var previousStaff = temp.GroupBy(d => d.StaffId).Select(d => d.First()).Where(d => d.StatusId == (int)ApprovalStatus.Approved && d.TargetId == request.TargetId && d.WorkflowToken == request.WorkflowToken).ToArray();

            response.AprovalDetails = list.Select(x => new AprovalDetailsObj()
            {
                ApprovalDetailId = x.ApprovalDetailId,
                Comment          = x.Comment,
                Date             = x.Date,
                StaffId          = x.StaffId,
                FirstName        = staff.FirstOrDefault(d => d.staffId == x.StaffId)?.firstName,
                LastName         = staff.FirstOrDefault(d => d.staffId == x.StaffId)?.lastName,
                StatusId         = x.StatusId,
                StatusName       = Convert.ToString((ApprovalStatus)x.StatusId),
                SupplierName     = supplierList.FirstOrDefault(d => d.SupplierId == x.TargetId)?.Name,
                TargetId         = x.TargetId,
                ArrivalDate      = x.ArrivalDate,
                WorkflowToken    = x.WorkflowToken,
            }).ToList();
            response.PreviousStaff = previousStaff.Select(p => new PreviousStaff
            {
                StaffId = p.StaffId,
                Name    = $"{staff.FirstOrDefault(d => d.staffId == p.StaffId)?.firstName} {staff.FirstOrDefault(d => d.staffId == p.StaffId)?.lastName}",
            }).ToList();
            return(response);
        }