public List <xPlug.BusinessObject.Cheque> GetChequesByBankId(Int32 bankId)
 {
     try
     {
         using (var db = new ExpenseManagerDBEntities())
         {
             var myObjList         = db.Cheques.ToList().FindAll(m => m.BankId == bankId);
             var myBusinessObjList = new List <xPlug.BusinessObject.Cheque>();
             if (myObjList == null)
             {
                 return(myBusinessObjList);
             }
             //Re-Map each Entity Object to Business Object
             foreach (var item in myObjList)
             {
                 var myBusinessObj = ChequeMapper.Map <Cheque, xPlug.BusinessObject.Cheque>(item);
                 if (myBusinessObj == null)
                 {
                     continue;
                 }
                 myBusinessObjList.Add(myBusinessObj);
             }
             return(myBusinessObjList);
         }
     }
     catch (Exception ex)
     {
         ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
         return(new List <xPlug.BusinessObject.Cheque>());
     }
 }
 public xPlug.BusinessObject.Cheque GetCheque(int chequePaymentId)
 {
     try
     {
         using (var db = new ExpenseManagerDBEntities())
         {
             var myObj = db.Cheques.SingleOrDefault(s => s.ChequePaymentId == chequePaymentId);
             if (myObj == null)
             {
                 return(new xPlug.BusinessObject.Cheque());
             }
             //Re-Map Entity Object to Business Object
             var myBusinessObj = ChequeMapper.Map <Cheque, xPlug.BusinessObject.Cheque>(myObj);
             if (myBusinessObj == null)
             {
                 return(new xPlug.BusinessObject.Cheque());
             }
             { return(myBusinessObj); }
         }
     }
     catch (Exception ex)
     {
         ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
         return(new xPlug.BusinessObject.Cheque());
     }
 }
 public bool UpdateCheque(xPlug.BusinessObject.Cheque cheque)
 {
     try
     {
         //Re-Map Object to Entity Object
         var myEntityObj = ChequeMapper.Map <xPlug.BusinessObject.Cheque, Cheque>(cheque);
         if (myEntityObj == null)
         {
             return(false);
         }
         using (var db = new ExpenseManagerDBEntities())
         {
             db.Cheques.Attach(myEntityObj);
             db.ObjectStateManager.ChangeObjectState(myEntityObj, EntityState.Modified);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
         return(false);
     }
 }
 public int AddCheque(xPlug.BusinessObject.Cheque cheque)
 {
     try
     {
         //Re-Map Object to Entity Object
         var myEntityObj = ChequeMapper.Map <xPlug.BusinessObject.Cheque, Cheque>(cheque);
         if (myEntityObj == null)
         {
             return(-2);
         }
         using (var db = new ExpenseManagerDBEntities())
         {
             db.AddToCheques(myEntityObj);
             db.SaveChanges();
             cheque.ChequePaymentId = myEntityObj.ChequePaymentId;
             return(cheque.ChequePaymentId);
         }
     }
     catch (Exception ex)
     {
         ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }