public bool UpdateExpenseType(xPlug.BusinessObject.ExpenseType expenseType) { try { //Re-Map Object to Entity Object var myEntityObj = ExpenseTypeMapper.Map <xPlug.BusinessObject.ExpenseType, ExpenseType>(expenseType); if (myEntityObj == null) { return(false); } using (var db = new ExpenseManagerDBEntities()) { db.ExpenseTypes.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 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); } }