public int AddAccountsHead(xPlug.BusinessObject.AccountsHead accountsHead) { try { //Re-Map Object to Entity Object var myEntityObj = AccountsHeadMapper.Map <xPlug.BusinessObject.AccountsHead, AccountsHead>(accountsHead); if (myEntityObj == null) { return(-2); } using (var db = new ExpenseManagerDBEntities()) { if (db.AccountsHeads.Any()) { var objTitle = myEntityObj.Title.ToLower().Replace(" ", string.Empty.Trim()); if (db.AccountsHeads.Count(m => m.Title.ToLower().Replace(" ", string.Empty.Trim()) == objTitle) > 0) { return(-3); } } db.AddToAccountsHeads(myEntityObj); db.SaveChanges(); accountsHead.AccountsHeadId = myEntityObj.AccountsHeadId; return(accountsHead.AccountsHeadId); } } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public int UpdateAccountsHead(BusinessObject.AccountsHead accountsHead) { try { //Re-Map Object to Entity Object var myEntityObj = AccountsHeadMapper.Map <BusinessObject.AccountsHead, AccountsHead>(accountsHead); if (myEntityObj == null) { return(-2); } using (var db = new ExpenseManagerDBEntities()) { var objTitle = myEntityObj.Title.ToLower().Replace(" ", string.Empty.Trim()); if (db.AccountsHeads.Count(m => m.Title.ToLower().Replace(" ", string.Empty.Trim()) == objTitle && m.AccountsHeadId != myEntityObj.AccountsHeadId) > 0) { return(-3); } db.AccountsHeads.Attach(myEntityObj); db.ObjectStateManager.ChangeObjectState(myEntityObj, EntityState.Modified); db.SaveChanges(); return(accountsHead.AccountsHeadId); } } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public List <xPlug.BusinessObject.AccountsHead> GetAccountsHeadsByExpenseCategoryId(Int32 expenseCategoryId) { try { using (var db = new ExpenseManagerDBEntities()) { var myObjList = db.AccountsHeads.ToList().FindAll(m => m.ExpenseCategoryId == expenseCategoryId); var myBusinessObjList = new List <xPlug.BusinessObject.AccountsHead>(); if (myObjList == null) { return(myBusinessObjList); } //Re-Map each Entity Object to Business Object foreach (var item in myObjList) { var myBusinessObj = AccountsHeadMapper.Map <AccountsHead, xPlug.BusinessObject.AccountsHead>(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.AccountsHead>()); } }
public BusinessObject.AccountsHead GetAccountsHead(int accountsHeadId) { try { using (var db = new ExpenseManagerDBEntities()) { var myObj = db.AccountsHeads.SingleOrDefault(s => s.AccountsHeadId == accountsHeadId); if (myObj == null) { return(new xPlug.BusinessObject.AccountsHead()); } //Re-Map Entity Object to Business Object var myBusinessObj = AccountsHeadMapper.Map <AccountsHead, xPlug.BusinessObject.AccountsHead>(myObj); if (myBusinessObj == null) { return(new xPlug.BusinessObject.AccountsHead()); } { return(myBusinessObj); } } } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(new xPlug.BusinessObject.AccountsHead()); } }
public BusinessObject.AccountsHead GetLastInsertedAccountsHeadsByExpenseCategoryId(int expenseCategoryId) { try { using (var db = new ExpenseManagerDBEntities()) { var myObjList = db.AccountsHeads.ToList().FindAll(m => m.ExpenseCategoryId == expenseCategoryId); var myBusinessObjList = new List <BusinessObject.AccountsHead>(); if (!myObjList.Any()) { return(new BusinessObject.AccountsHead()); } //Re-Map each Entity Object to Business Object foreach (var item in myObjList) { var myBusinessObj = AccountsHeadMapper.Map <AccountsHead, BusinessObject.AccountsHead>(item); if (myBusinessObj == null) { continue; } myBusinessObjList.Add(myBusinessObj); } var obj = myBusinessObjList.OrderByDescending(m => long.Parse(m.Code)).ElementAt(0); return(obj); } } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(new BusinessObject.AccountsHead()); } }
public List <BusinessObject.AccountsHead> GetFilteredAccountsHeads() { try { using (var db = new ExpenseManagerDBEntities()) { var myBusinessObjList = new List <BusinessObject.AccountsHead>(); var accountsHeadsObjList = db.AccountsHeads.Where(m => m.ExpenseCategory.Status == 1 && m.Status == 1 && m.ExpenseItems.Any()).ToList(); if (!accountsHeadsObjList.Any()) { return(myBusinessObjList); } //Re-Map each Entity Object to Business Object foreach (var item in accountsHeadsObjList) { bool any = myBusinessObjList.Any(m => m.AccountsHeadId == item.AccountsHeadId); if (!any) { var myBusinessObj = AccountsHeadMapper.Map <ExpenseManager.EF.AccountsHead, xPlug.BusinessObject.AccountsHead>(item); if (myBusinessObj == null) { continue; } myBusinessObjList.Add(myBusinessObj); } } if (!myBusinessObjList.Any()) { return(myBusinessObjList); } return(myBusinessObjList.OrderBy(m => m.Title).ToList()); } } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(new List <BusinessObject.AccountsHead>()); } }
public List <BusinessObject.AccountsHead> GetOrderedAccountsHeadsByExpenseCategoryId(Int32 expenseCategoryId) { try { using (var db = new ExpenseManagerDBEntities()) { var myBusinessObjList = new List <BusinessObject.AccountsHead>(); var accountsHeadsObjList = db.AccountsHeads.Where(m => m.ExpenseCategoryId == expenseCategoryId && m.ExpenseCategory.Status == 1).ToList(); if (!accountsHeadsObjList.Any()) { return(myBusinessObjList); } //Re-Map each Entity Object to Business Object foreach (var item in accountsHeadsObjList) { var myBusinessObj = AccountsHeadMapper.Map <AccountsHead, BusinessObject.AccountsHead>(item); if (myBusinessObj == null) { continue; } myBusinessObjList.Add(myBusinessObj); } if (!myBusinessObjList.Any()) { return(myBusinessObjList); } return(myBusinessObjList.OrderBy(m => m.ExpenseCategory.Title).ThenBy(m => m.Title).ToList()); } } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(new List <BusinessObject.AccountsHead>()); } }