public ExpenseSM AddExpense(ExpenseSM expense) { var exp = Mapper.Map <ExpenseDM>(expense); exp.ExpenseType = _data.ExpenseTypes.SingleOrDefault(x => x.Id == Convert.ToInt32(expense.ExpenseType.Id)); _data.Expenses.Add(exp); _data.SaveChanges(); expense.Id = exp.Id; return(expense); }
public void DeleteExpense(ExpenseSM expense) { if (_data.GetExpenseById(expense.Id) == null) { AddBusinessError(BusinessErrorCodes.DataNotFound, "ExpenseNotFound"); } else { _data.DeleteExpense(expense); } }
public bool DeleteExpense(ExpenseSM expense) { var exp = _data.Expenses.SingleOrDefault(x => x.Id == expense.Id); if (exp == null) { return(false); } _data.Remove(exp); _data.SaveChanges(); return(true); }
public ExpenseSM UpdateExpense(ExpenseSM expense) { var exp = _data.Expenses.SingleOrDefault(x => x.Id == expense.Id); AssertObjectNotNull(exp); exp.ExpenseType = _data.ExpenseTypes.SingleOrDefault(x => x.Id == Convert.ToInt32(expense.ExpenseType.Id)); exp.ExpenseValue = expense.ExpenseValue; exp.ExpenseDate = expense.ExpenseDate; _data.SaveChanges(); return(expense); }
public ExpenseSM UpdateExpense(ExpenseSM expense) { var expDataModel = Mapper.Map <ExpenseMongoDM>(expense); _expenseCollection.FindOneAndUpdate <ExpenseMongoDM>( Builders <ExpenseMongoDM> .Filter.Eq("_id", new ObjectId(expense.Id)), Builders <ExpenseMongoDM> .Update .Set("ExpenseType", expDataModel.ExpenseType) .Set("ExpenseValue", expDataModel.ExpenseValue) .Set("ExpenseDate", expDataModel.ExpenseDate) .Set("User", expDataModel.User) ); return(expense); }
public ExpenseSM AddExpense(ExpenseSM expense) { StartTransaction(); if (string.IsNullOrEmpty(expense.ExpenseType.Id)) { AddExpenseType(expense.ExpenseType); } var dm = Mapper.Map <ExpenseMongoDM>(expense); _expenseCollection.InsertOne(dm); expense.Id = dm.Id.ToString(); CommitTransaction(); return(expense); }
public bool DeleteExpense(ExpenseSM expense) { _expenseCollection.FindOneAndDelete <ExpenseMongoDM>(Builders <ExpenseMongoDM> .Filter.Eq("_id", new ObjectId(expense.Id))); return(true); }