public int AddExpenseCategoryCheckDuplicate(BusinessObject.ExpenseCategory expenseCategory) { try { //Re-Map Object to Entity Object var myEntityObj = ExpenseCategoryMapper.Map <BusinessObject.ExpenseCategory, ExpenseCategory>(expenseCategory); if (myEntityObj == null) { return(-2); } using (var db = new ExpenseManagerDBEntities()) { if (db.ExpenseCategories.Count(m => m.Title.ToLower().Replace(" ", string.Empty) == expenseCategory.Title.ToLower().Replace(" ", string.Empty)) > 0) { return(-3); } db.AddToExpenseCategories(myEntityObj); db.SaveChanges(); expenseCategory.ExpenseCategoryId = myEntityObj.ExpenseCategoryId; return(expenseCategory.ExpenseCategoryId); } } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public int AddExpenseCategory(xPlug.BusinessObject.ExpenseCategory expenseCategory) { try { //Re-Map Object to Entity Object var myEntityObj = ExpenseCategoryMapper.Map <xPlug.BusinessObject.ExpenseCategory, ExpenseCategory>(expenseCategory); if (myEntityObj == null) { return(-2); } using (var db = new ExpenseManagerDBEntities()) { db.AddToExpenseCategories(myEntityObj); db.SaveChanges(); expenseCategory.ExpenseCategoryId = myEntityObj.ExpenseCategoryId; return(expenseCategory.ExpenseCategoryId); } } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(0); } }