示例#1
0
            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);
            }
示例#2
0
 public void DeleteExpense(ExpenseSM expense)
 {
     if (_data.GetExpenseById(expense.Id) == null)
     {
         AddBusinessError(BusinessErrorCodes.DataNotFound, "ExpenseNotFound");
     }
     else
     {
         _data.DeleteExpense(expense);
     }
 }
示例#3
0
            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);
            }
示例#4
0
            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);
            }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
 public bool DeleteExpense(ExpenseSM expense)
 {
     _expenseCollection.FindOneAndDelete <ExpenseMongoDM>(Builders <ExpenseMongoDM> .Filter.Eq("_id", new ObjectId(expense.Id)));
     return(true);
 }