private static ControlNumber _Create(FormType formType)
        {
            int lastControlNum = 0;
            var lastControls = Context.ControlNumbers.Where(e => e.FormTypeId == formType.Id);
            if (lastControls.Count() == 0)
            {
                lastControlNum = 0;
            }
            else
            {
                lastControlNum = lastControls.Max(e => e.LastControlNumber) + 1;
            }

            ControlNumber controlnum = new ControlNumber();
            controlnum.FormType = formType;
            controlnum.LastControlNumber = lastControlNum;
            Context.ControlNumbers.AddObject(controlnum);

            return controlnum;
        }
 public static ControlNumber Create(FormType formType, Payment payment)
 {
     var controlNumber = _Create(formType);
     controlNumber.Payment = payment;
     return controlNumber;
 }
 public static ControlNumber GetByPaymentId(int paymentId, FormType formType)
 {
     return Context.ControlNumbers.FirstOrDefault(e => e.PaymentId == paymentId && e.FormTypeId == formType.Id);
 }
 public static IQueryable<FormDetail> GetByLoanAppIdAndType(int id, FormType type)
 {
     return Context.FormDetails.Where(entity => entity.LoanAppId == id && entity.FormTypeId == type.Id);
 }