public bool DeleteTransporterChequeDetail(TransporterChequeDetail transporterChequeDetail)
 {
     if (transporterChequeDetail == null) return false;
     _unitOfWork.TransporterChequeDetailRepository.Delete(transporterChequeDetail);
     _unitOfWork.Save();
     return true;
 }
 public bool EditTransporterChequeDetail(TransporterChequeDetail transporterChequeDetail)
 {
     _unitOfWork.TransporterChequeDetailRepository.Edit(transporterChequeDetail);
     _unitOfWork.Save();
     return true;
 }
        public ActionResult EditCollectiveChequeInfo(Models.TransporterChequeViewModel transporterChequeViewModel, int transporterID)
        {
            var paymentRequestList = (IEnumerable<Cats.Models.TransporterPaymentRequest>)_transporterPaymentRequestService
                        .Get(t => t.BusinessProcess.CurrentState.BaseStateTemplate.StateNo == 3, null, "BusinessProcess")
                        .OrderByDescending(t => t.TransporterPaymentRequestID);
            //var transporterChequeObj = _transporterChequeService.Get(t => t.TransporterChequeId == transporterChequeViewModel.TransporterChequeId).FirstOrDefault();
            if (paymentRequestList.Any())
            {
                var transporterChequeDetails = new List<TransporterChequeDetail>();
                foreach(var paymentRequest in paymentRequestList)
                {
                    var transporterChequeDetail = new TransporterChequeDetail
                                                      {
                                                          TransporterPaymentRequestID = paymentRequest.TransporterPaymentRequestID
                                                      };
                    transporterChequeDetails.Add(transporterChequeDetail);
                }
                var user = UserAccountHelper.GetUser(User.Identity.Name);
                var transporterChequeObj = new TransporterCheque()
                                                {
                                                    CheckNo = transporterChequeViewModel.CheckNo,
                                                    PaymentVoucherNo = transporterChequeViewModel.PaymentVoucherNo,
                                                    BankName = transporterChequeViewModel.BankName,
                                                    Amount = transporterChequeViewModel.Amount,
                                                    PreparedBy = user.UserProfileID,
                                                    Status = 1,
                                                    TransporterChequeDetails = transporterChequeDetails
                                                };

                int BP_PR = _applicationSettingService.getTransporterChequeWorkflow();
                if (BP_PR != 0)
                {
                    BusinessProcessState createdstate = new BusinessProcessState
                    {
                        DatePerformed = DateTime.Now,
                        PerformedBy = "System",
                        Comment = "Created workflow for Transporter Cheque"

                    };
                    //_PaymentRequestservice.Create(request);

                    BusinessProcess bp = _businessProcessService.CreateBusinessProcess(BP_PR, transporterChequeObj.TransporterChequeId,
                                                                                        "ValidatedPaymentRequest", createdstate);
                    transporterChequeObj.BusinessProcessID = bp.BusinessProcessID;
                    transporterChequeObj.IssueDate = DateTime.Now;
                    _transporterChequeService.AddTransporterCheque(transporterChequeObj);
                    foreach (var paymentRequest in paymentRequestList)
                    {
                        var currFlowTemplate = paymentRequest.BusinessProcess.CurrentState.BaseStateTemplate.InitialStateFlowTemplates.FirstOrDefault();
                        if (currFlowTemplate != null)
                        {
                            var state = new BusinessProcessState()
                                            {
                                                StateID = currFlowTemplate.FinalStateID,
                                                PerformedBy = user.FullName,
                                                Comment = "Finance: Batch generated cheque for the payment request",
                                                DatePerformed = DateTime.Now,
                                                ParentBusinessProcessID = paymentRequest.BusinessProcess.CurrentState.ParentBusinessProcessID
                                            };
                            var item = _businessProcessService.FindById(state.ParentBusinessProcessID);
                            _businessProcessStateService.Add(state);
                            item.CurrentStateID = state.BusinessProcessStateID;
                            _businessProcessService.Update(item);
                        }
                    }
                }
            }
            return RedirectToAction("Cheques", "Cheque", new { Area = "Finance", transporterID });
        }