public static DisbursementVcrStatu ChangeStatus(LoanDisbursementVcr loanDisbursementVoucher, DisbursementVcrStatusType statusType, DateTime today)
 {
     DisbursementVcrStatu disbursementStatus = GetActive(loanDisbursementVoucher);
     if (CanChangeStatus(disbursementStatus.DisbursementVcrStatusType, statusType, today))
         return CreateOrUpdateCurrent(loanDisbursementVoucher, statusType, today);
     return disbursementStatus;
 }
        public static LoanDisbursementVcr CreateForAdditionalLoan(LoanApplication loanApplication, Agreement agreement, decimal additionalAmount, DateTime today)
        {
            LoanDisbursementVcr disbursement = new LoanDisbursementVcr();
            disbursement.Agreement = agreement;
            disbursement.Date = today;
            disbursement.Amount = loanApplication.LoanAmount;
            disbursement.Balance = additionalAmount;

            Context.LoanDisbursementVcrs.AddObject(disbursement);
            return disbursement;
        }
        public static DisbursementVcrStatu Create(LoanDisbursementVcr loanDisbursementVoucher, DisbursementVcrStatusType statusType, DateTime today)
        {
            DisbursementVcrStatu status = new DisbursementVcrStatu();
            status.DisbursementVoucherStatTypId = statusType.Id;
            status.LoanDisbursementVcr = loanDisbursementVoucher;
            status.Remarks = null;
            status.TransitionDateTime = today;
            status.IsActive = true;

            Context.DisbursementVcrStatus.AddObject(status);
            return status;
        }
        public static DisbursementVcrStatu CreateOrUpdateCurrent(LoanDisbursementVcr loanDisbursementVoucher, DisbursementVcrStatusType statusType, DateTime today)
        {
            DisbursementVcrStatu disbursementStatus = GetActive(loanDisbursementVoucher);
            if (disbursementStatus != null && disbursementStatus.DisbursementVcrStatusType.Id != statusType.Id)
                disbursementStatus.IsActive = false;

            if (disbursementStatus == null || disbursementStatus.DisbursementVcrStatusType.Id != statusType.Id)
            {
                DisbursementVcrStatu newDisbursementStatus = new DisbursementVcrStatu();
                newDisbursementStatus.DisbursementVoucherStatTypId = statusType.Id;
                newDisbursementStatus.LoanDisbursementVcr = loanDisbursementVoucher;
                newDisbursementStatus.Remarks = null;
                newDisbursementStatus.TransitionDateTime = today;
                newDisbursementStatus.IsActive = true;

                Context.DisbursementVcrStatus.AddObject(newDisbursementStatus);

                return newDisbursementStatus;
            }
            return disbursementStatus;
        }
 public static DisbursementVcrStatu GetActive(LoanDisbursementVcr loanDisbursementVoucher)
 {
     var result = loanDisbursementVoucher.DisbursementVcrStatus.Where(entity => entity.IsActive);
     if (result.Count() > 0)
         return result.First();
     else
         return null;
 }
 public static DisbursementVcrStatu RetrieveStatus(LoanDisbursementVcr loanDisbursementVoucher, DisbursementVcrStatusType statusType)
 {
     return Context.DisbursementVcrStatus.SingleOrDefault(entity => entity.LoanDisbursementVoucherId == loanDisbursementVoucher.Id
         && entity.TransitionDateTime == GetActive(loanDisbursementVoucher).TransitionDateTime && entity.DisbursementVoucherStatTypId == statusType.Id);
 }