public int AddExpenseTypeCheckDuplicate(BusinessObject.ExpenseType expenseType) { try { //Re-Map Object to Entity Object var myEntityObj = ExpenseTypeMapper.Map <BusinessObject.ExpenseType, ExpenseType>(expenseType); if (myEntityObj == null) { return(-2); } using (var db = new ExpenseManagerDBEntities()) { if (db.ExpenseTypes.Count(m => m.Name.ToLower().Replace(" ", string.Empty) == expenseType.Name.ToLower().Replace(" ", string.Empty)) > 0) { return(-3); } db.AddToExpenseTypes(myEntityObj); db.SaveChanges(); expenseType.ExpenseTypeId = myEntityObj.ExpenseTypeId; return(expenseType.ExpenseTypeId); } } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public int AddExpenseType(xPlug.BusinessObject.ExpenseType expenseType) { try { //Re-Map Object to Entity Object var myEntityObj = ExpenseTypeMapper.Map <xPlug.BusinessObject.ExpenseType, ExpenseType>(expenseType); if (myEntityObj == null) { return(-2); } using (var db = new ExpenseManagerDBEntities()) { db.AddToExpenseTypes(myEntityObj); db.SaveChanges(); expenseType.ExpenseTypeId = myEntityObj.ExpenseTypeId; return(expenseType.ExpenseTypeId); } } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(0); } }