Esempio n. 1
0
        public async Task <int> EditExpensesAsync(Domain.Expense dExpenseToUpdate, int id)
        {
            var result = -1;
            var entiry = _expContext.Expenses.Include(d => d.ExpenseDetail).FirstOrDefault(x => x.Id == id);

            try
            {
                if (entiry != null)
                {
                    entiry.ExpenseTitle      = dExpenseToUpdate.ExpenseTitle;
                    entiry.ExpensesAmount    = dExpenseToUpdate.ExpensesAmount;
                    entiry.ExpenseDate       = dExpenseToUpdate.ExpenseDate;
                    entiry.ExpenseCategoryId = dExpenseToUpdate.ExpenseCategoryId;
                    entiry.CurrencyId        = dExpenseToUpdate.CurrencyId;
                    entiry.updateDate        = DateTime.UtcNow;
                    entiry.ExpenseDetail     = dExpenseToUpdate.ExpenseDetail;
                    entiry.Signature         = dExpenseToUpdate.Signature;
                    entiry.PaymentMethod     = dExpenseToUpdate.PaymentMethod;
                    entiry.PaymentType       = dExpenseToUpdate.PaymentType;
                    // _expContext.Update(oExp);
                    result = await _expContext.SaveChangesAsync();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(result);
        }
Esempio n. 2
0
        public void GetExpenses_oneValidExpense_Ok()
        {
            var repoExpense1 = new Domain.Expense
            {
                Amount      = 100,
                Category    = "grocery",
                ExpneseDate = new DateTime(2016, 11, 15),
                ID          = 1,
                Merchant    = "pns"
            };
            var repoExpenses = new List <Domain.Expense>()
            {
                repoExpense1
            };
            var repo = new Moq.Mock <IExpenseRepository>();

            repo.Setup <List <Expense> >(t => t.GetAllExpenses())
            .Returns(repoExpenses);

            var fac = new Moq.Mock <ITransactionFactory>();

            fac.Setup <DisplayExpensesTransaction>(m => m.CreateDisplayExpensesTransaction())
            .Returns(new DisplayExpensesTransaction(repo.Object));

            var sut = new ExpensesController(fac.Object, _logger.Object);

            //act
            var actualResponse = sut.Get();
            var contentResult  = actualResponse as OkNegotiatedContentResult <IEnumerable <ViewModels.Expense> >;

            //assert
            Assert.IsNotNull(contentResult, "Ok-200 status was not returned");
            Assert.IsNotNull(contentResult.Content, "No content was returned");
        }
        public void automapper_validDomainModel_sucessfull()
        {
            var source = new Domain.Expense {
                Amount = 10.11m, Category = "Test Category", ExpneseDate = new DateTime(2016, 11, 17), ID = 55, Merchant = "Test Merchant"
            };
            var expected = new API.ViewModels.Expense {
                Amount = 10.11m, Category = "Test Category", ExpneseDate = "2016/11/17", Merchant = "Test Merchant"
            };

            //act
            var actualResults = Mapper.Map <Domain.Expense, API.ViewModels.Expense>(source);

            //assert
            Assert.AreEqual(expected.Amount, actualResults.Amount);
            Assert.AreEqual(expected.Category, actualResults.Category);
            Assert.AreEqual(expected.ExpneseDate, actualResults.ExpneseDate);
            Assert.AreEqual(expected.Merchant, actualResults.Merchant);
        }
Esempio n. 4
0
        public async Task <Domain.Expense> GetExpensesAsync(int id)
        {
            //_expContext = new MEMCore.Data.ExpenseContext();
            var result = new Domain.Expense();
            //using (_expContext.Expenses)
            //{
            var quary = await _expContext.Expenses.OrderByDescending(x => x.ExpenseDate)
                        .Include(s => s.Category)
                        .Include(s => s.Currency)
                        .Include(s => s.ExpenseDetail)
                        .Where(x => x.Id == id).FirstOrDefaultAsync();

            //}
            if (quary != null)
            {
                result = quary;
            }

            return(result);
        }
Esempio n. 5
0
        public async Task <int> NewExpensesAsync(Domain.Expense expense)
        {
            var result = -1;

            try
            {
                _expContext.Add(expense);
                result = await _expContext.SaveChangesAsync();

                if (result < 1)
                {
                    throw new Exception("Error occurred while adding new expense into database");
                }
                result = expense.Id;
            }
            catch (Exception)
            {
                throw;
            }

            return(result);
        }