Esempio n. 1
0
        public void UpdateSpecificExpenseShouldModifyGivenExpense()
        {
            var options = new DbContextOptionsBuilder <DataDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(UpdateSpecificExpenseShouldModifyGivenExpense))
                          .Options;

            using (var context = new DataDbContext(options))
            {
                var expenseService = new ExpensesService(context);

                var toAddExpense = new ExpensesPostModel()
                {
                    Description = "Test description",
                    Sum         = 20,
                    Location    = "Cluj",
                    Date        = DateTime.ParseExact("05/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "RON",
                    Type        = "Utilities",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "A test comment",
                            Important = false
                        }
                    }
                };
                var addedExpense = expenseService.AddExpense(toAddExpense);

                // new modified expense
                var toUpdatedExpense = new ExpensesPostModel()
                {
                    Description = "Test description updated",
                    Sum         = 30,
                    Location    = "Brasov",
                    Date        = DateTime.ParseExact("05/31/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "Euro",
                    Type        = "Food",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "An updated test comment",
                            Important = true
                        }
                    }
                };
                var updatedExpense = expenseService.UpsertExpense(addedExpense.Id, toUpdatedExpense);


                Assert.IsNotNull(updatedExpense);
                Assert.AreEqual(toUpdatedExpense.Description, updatedExpense.Description);
                Assert.AreEqual(toUpdatedExpense.Sum, updatedExpense.Sum);
                Assert.AreEqual(toUpdatedExpense.Location, updatedExpense.Location);
                Assert.AreEqual(toUpdatedExpense.Date, updatedExpense.Date);
                Assert.AreEqual(toUpdatedExpense.Currency, updatedExpense.Currency);
                Assert.AreEqual(toUpdatedExpense.Type, updatedExpense.Type.ToString());
                Assert.AreEqual(toUpdatedExpense.Comments, updatedExpense.Comments);
            }
        }
Esempio n. 2
0
        public void AddExpenseWithInvalidTypeFieldShouldNotCreateANewExpense()
        {
            var options = new DbContextOptionsBuilder <DataDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(AddExpenseWithInvalidTypeFieldShouldNotCreateANewExpense))
                          .Options;

            using (var context = new DataDbContext(options))
            {
                var expenseService = new ExpensesService(context);

                var expected = new ExpensesPostModel()
                {
                    Description = "Test description",
                    Sum         = 20,
                    Location    = "Cluj",
                    Date        = DateTime.ParseExact("05/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "RON",
                    Type        = "Invalid Type",
                    Comments    = null
                };

                var actual = expenseService.AddExpense(expected);

                Assert.IsNull(actual);
            }
        }
        public void CreateShouldAddAndReturnTheCreatedExpense()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(CreateShouldAddAndReturnTheCreatedExpense))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var taskService = new ExpensesService(context);
                var added       = taskService.Create(new Lab6.Viewmodels.ExpensePostModel

                {
                    Description = "Variable",
                    Type        = "5",
                    Location    = "Sibiu",
                    Date        = Convert.ToDateTime("2019-05-05T11:11:11"),
                    Currency    = "USD",
                    Sum         = 555.77,
                    Comments    = new List <Comment>()
                    {
                        new Comment
                        {
                            Important = true,
                            Text      = "Very important expense",
                            Owner     = null
                        }
                    },
                }, null);


                Assert.IsNotNull(added);
                Assert.AreEqual("Variable", added.Description);
                Assert.AreNotEqual("Fixed", added.Description);
            }
        }
Esempio n. 4
0
        public void GetExpenseByInvalidIdShouldNotFindAnyExpense()
        {
            var options = new DbContextOptionsBuilder <DataDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetExpenseByInvalidIdShouldNotFindAnyExpense))
                          .Options;

            using (var context = new DataDbContext(options))
            {
                var expenseService = new ExpensesService(context);

                var toAddExpense = new ExpensesPostModel()
                {
                    Description = "Test description",
                    Sum         = 20,
                    Location    = "Cluj",
                    Date        = DateTime.ParseExact("05/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "RON",
                    Type        = "Utilities",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "A test comment",
                            Important = false
                        }
                    }
                };

                var actual = expenseService.AddExpense(toAddExpense);

                var expected = expenseService.GetExpenseById(55555);

                Assert.IsNull(expected);
            }
        }
Esempio n. 5
0
        public void DeleteValidExpenseShouldDeleteExpense()
        {
            var options = new DbContextOptionsBuilder <DataDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(DeleteValidExpenseShouldDeleteExpense))
                          .Options;

            using (var context = new DataDbContext(options))
            {
                var expenseService = new ExpensesService(context);

                var expected = new ExpensesPostModel()
                {
                    Description = "Test description",
                    Sum         = 20,
                    Location    = "Cluj",
                    Date        = DateTime.ParseExact("05/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "RON",
                    Type        = "Food",
                    Comments    = null
                };
                // add the expense to db
                var actual = expenseService.AddExpense(expected);
                // delete expense and put return expense in obj
                var afterDelete = expenseService.DeleteExpense(actual.Id);
                // search for the added expense to see if exists in db
                var result = context.Expensess.Find(actual.Id);

                Assert.IsNotNull(afterDelete);
                Assert.IsNull(result);
            }
        }
Esempio n. 6
0
        public void CupOfCoffee_ShouldSaveFifteenThousandDollars()
        {
            //$4 cup of coffee equals $20 a week
            var expensesService          = new ExpensesService(20);
            var amountSavedByNotSpending = expensesService.CalculateWeeklyExpenses();

            Assert.AreEqual(15040, amountSavedByNotSpending);
        }
Esempio n. 7
0
        public void ProfessionalHaircut_ShouldSaveSeventeenThousandDollars()
        {
            //$100 haircut each month
            var expensesService          = new ExpensesService(100);
            var amountSavedByNotSpending = expensesService.CalculateMonthlyExpenses();

            Assert.AreEqual(17300, amountSavedByNotSpending);
        }
        public Result <IList <Expenses> > GetAll(int plannerId)
        {
            var             result          = new Result <IList <Expenses> >();
            ExpensesService ExpensesService = new ExpensesService();

            result.Value     = ExpensesService.GetAll(plannerId);
            result.IsSuccess = true;
            return(result);
        }
        public Result <Expenses> Get(int id, int plannerId)
        {
            var             result          = new Result <Expenses>();
            ExpensesService ExpensesService = new ExpensesService();

            result.Value     = ExpensesService.GetById(id, plannerId);
            result.IsSuccess = true;
            return(result);
        }
Esempio n. 10
0
        public void ValidateModelAttribute_WithError_ShouldThrowsException()
        {
            //Arrange
            var db = new ExpenseTrackerDbContext(
                new DbContextOptionsBuilder().UseInMemoryDatabase("test").Options);

            var service = new ExpensesService(db);

            //Act
            var result = service.AddAsync(AMOUNT, DESCRITION, CATEGORY_ID, USER_ID).Result;

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id != 0);
        }
Esempio n. 11
0
        public IActionResult List(int page = 1)
        {
            if (page < 1)
            {
                page = 1;
            }

            int pageSize = 20;

            ExpensesService service  = new ExpensesService(UserId);
            var             listData = service.GetForList(page, pageSize);

            ListViewModel vm = new ListViewModel(listData.expenses, listData.totalExpensesNumber, page, pageSize);

            return(View(vm));
        }
Esempio n. 12
0
        public void GetCommentsFilteredByValueShouldReturnAListOfFilteredComments()
        {
            var options = new DbContextOptionsBuilder <DataDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetCommentsFilteredByValueShouldReturnAListOfFilteredComments))
                          .Options;

            using (var context = new DataDbContext(options))
            {
                var commentsService = new CommentsService(context);
                var expensesService = new ExpensesService(context);

                var expenseWithCommentToAdd = new ExpensesPostModel()
                {
                    Description = "Test description",
                    Sum         = 20,
                    Location    = "Cluj",
                    Date        = DateTime.ParseExact("05/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "RON",
                    Type        = "Utilities",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "A test comment 1 filtered",
                            Important = false
                        },
                        new Comment()
                        {
                            Text      = "A test comment 2 filtered",
                            Important = true
                        },
                        new Comment()
                        {
                            Text      = "A test comment 3",
                            Important = false
                        }
                    }
                };
                expensesService.AddExpense(expenseWithCommentToAdd);

                List <CommentGetModel> comments = commentsService.GetAll("filtered");
                int numberOfComments            = comments.Count;

                Assert.IsNotNull(comments);
                Assert.AreEqual(2, numberOfComments);
            }
        }
        public Result Delete(Expenses Expenses)
        {
            var result = new Result();

            try
            {
                ExpensesService ExpensesService = new ExpensesService();
                ExpensesService.Delete(Expenses);
                result.IsSuccess = true;
            }
            catch (Exception exception)
            {
                result.IsSuccess     = false;
                result.ExceptionInfo = exception;
            }
            return(result);
        }
        public void UpsertShouldModifyTheGivenExpense()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(UpsertShouldModifyTheGivenExpense))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var expenseService = new ExpensesService(context);
                var added          = new ExpensePostModel()

                {
                    Description = "Variable",
                    Type        = "5",
                    Location    = "Sibiu",
                    Date        = Convert.ToDateTime("2019-05-05T11:11:11"),
                    Currency    = "USD",
                    Sum         = 555.77,
                    Comments    = new List <Comment>()
                    {
                        new Comment
                        {
                            Important = true,
                            Text      = "Very important expense",
                            Owner     = null
                        }
                    },
                };

                var toAdd  = expenseService.Create(added, null);
                var update = new ExpensePostModel()
                {
                    Description = "Variable-Updated"
                };

                var toUp         = expenseService.Create(update, null);
                var updateResult = expenseService.Upsert(toUp.Id, toUp);


                Assert.IsNotNull(updateResult);
                Assert.AreEqual(toUp.Description, updateResult.Description);
            }
        }
Esempio n. 15
0
        public void DeleteValidExpenseWithCommentsShouldDeleteExpenseAndComments()
        {
            var options = new DbContextOptionsBuilder <DataDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(DeleteValidExpenseWithCommentsShouldDeleteExpenseAndComments))
                          .Options;

            using (var context = new DataDbContext(options))
            {
                var expenseService = new ExpensesService(context);

                var expected = new ExpensesPostModel()
                {
                    Description = "Test description",
                    Sum         = 20,
                    Location    = "Cluj",
                    Date        = DateTime.ParseExact("05/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "RON",
                    Type        = "Food",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "A test comment",
                            Important = false
                        }
                    }
                };
                // add the expense to db
                var actual = expenseService.AddExpense(expected);
                // delete expense and put return expense in obj
                var afterDelete = expenseService.DeleteExpense(actual.Id);
                // find the number of comments that exists in db
                int numberOfCommentsInDb = context.Comments.CountAsync().Result;
                // search for the added expense to see if exists in db
                var resultExpense = context.Expensess.Find(actual.Id);

                Assert.IsNotNull(afterDelete);
                Assert.IsNull(resultExpense);
                Assert.AreEqual(0, numberOfCommentsInDb);
            }
        }
Esempio n. 16
0
        public void AddAValidExpenseShouldCreateANewExpense()
        {
            var options = new DbContextOptionsBuilder <DataDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(AddAValidExpenseShouldCreateANewExpense))
                          .Options;

            using (var context = new DataDbContext(options))
            {
                var expenseService = new ExpensesService(context);

                var expected = new ExpensesPostModel()
                {
                    Description = "Test description",
                    Sum         = 20,
                    Location    = "Cluj",
                    Date        = DateTime.ParseExact("05/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "RON",
                    Type        = "Utilities",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "A test comment",
                            Important = false
                        }
                    }
                };

                var actual = expenseService.AddExpense(expected);

                Assert.IsNotNull(actual);
                Assert.AreEqual(expected.Description, actual.Description);
                Assert.AreEqual(expected.Sum, actual.Sum);
                Assert.AreEqual(expected.Location, actual.Location);
                Assert.AreEqual(expected.Date, actual.Date);
                Assert.AreEqual(expected.Currency, actual.Currency);
                Assert.AreEqual(expected.Type, actual.Type.ToString());
                Assert.AreEqual(expected.Comments, actual.Comments);
            }
        }
        public void GetByIdShouldReturnExpenseWithCorrectId()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetByIdShouldReturnExpenseWithCorrectId))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var expenseService = new ExpensesService(context);
                var added          = new ExpensePostModel()

                {
                    Description = "Variable",
                    Type        = "5",
                    Location    = "Sibiu",
                    Date        = Convert.ToDateTime("2019-05-05T11:11:11"),
                    Currency    = "USD",
                    Sum         = 555.77,
                    Comments    = new List <Comment>()
                    {
                        new Comment
                        {
                            Important = true,
                            Text      = "Very important expense",
                            Owner     = null
                        }
                    },
                };

                var current  = expenseService.Create(added, null);
                var expected = expenseService.GetById(current.Id);

                Assert.IsNotNull(expected);
                Assert.AreEqual(expected.Description, current.Description);
                Assert.AreEqual(expected.Location, current.Location);
                Assert.AreEqual(expected.Sum, current.Sum);
                Assert.AreEqual(expected.Id, current.Id);
            }
        }
        public void DeleteExpenseWithCommentsShouldDeleteExpenseAndComments()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(DeleteExpenseWithCommentsShouldDeleteExpenseAndComments))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var expensesService = new ExpensesService(context);

                var expected = new ExpensePostModel()
                {
                    Description = "Variable",
                    Type        = "5",
                    Location    = "Sibiu",
                    Date        = Convert.ToDateTime("2019-05-05T11:11:11"),
                    Currency    = "USD",
                    Sum         = 555.77,
                    Comments    = new List <Comment>()
                    {
                        new Comment
                        {
                            Important = true,
                            Text      = "Very important expense",
                            Owner     = null
                        }
                    },
                };

                var actual               = expensesService.Create(expected, null);
                var afterDelete          = expensesService.Delete(actual.Id);
                int numberOfCommentsInDb = context.Comments.CountAsync().Result;
                var resultExpense        = context.Expenses.Find(actual.Id);

                Assert.IsNotNull(afterDelete);
                Assert.IsNull(resultExpense);
                Assert.AreEqual(0, numberOfCommentsInDb);
            }
        }
Esempio n. 19
0
        private static void CalculateExpensesOver10Years()
        {
            Console.WriteLine("*** Calculating Expesnses ***");
            Console.WriteLine("*** The following calculation assumes a 7% growth over 10 years. ***");

            Console.WriteLine("Is the following expense a monthly (M), or weekly (W) expense?");
            var expenseType = Console.ReadLine().ToUpper();

            if (expenseType != "W" && expenseType != "M")
            {
                return;
            }

            Console.WriteLine("Please enter the recurring expense amount");
            var expenseAmount = decimal.Parse(Console.ReadLine());

            var expensesService = new ExpensesService(expenseAmount);
            var amountSaved     = expenseType == "M" ?
                                  expensesService.CalculateMonthlyExpenses() :
                                  expensesService.CalculateWeeklyExpenses();

            Console.WriteLine($"If you invested your ${expenseAmount} instead, you would save ${amountSaved} after 10 years!");
        }
        public void GetAllShouldReturnCorrectNumberOfPagesForExpenses()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetAllShouldReturnCorrectNumberOfPagesForExpenses))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var expenseService = new ExpensesService(context);
                var added          = expenseService.Create(new Lab6.Viewmodels.ExpensePostModel

                {
                    Description = "Variable",
                    Type        = "5",
                    Location    = "Sibiu",
                    Date        = Convert.ToDateTime("2019-05-05T11:11:11"),
                    Currency    = "USD",
                    Sum         = 555.77,
                    Comments    = new List <Comment>()
                    {
                        new Comment
                        {
                            Important = true,
                            Text      = "Very important expense",
                            Owner     = null
                        }
                    },
                }, null);

                DateTime from = DateTime.Parse("2019-04-13T00:00:00");
                DateTime to   = DateTime.Parse("2019-06-19T00:00:00");

                var allExpenses = expenseService.GetAll(1, from, to);
                Assert.AreEqual(1, allExpenses.Entries.Count);
                Assert.IsNotNull(allExpenses);
            }
        }
Esempio n. 21
0
        public void GetAllShouldReturnCorrectNumberOfPagesForComments()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetAllShouldReturnCorrectNumberOfPagesForComments))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var taskService    = new ExpensesService(context);
                var commentService = new CommentsService(context);
                var added          = new ExpensePostModel()

                {
                    Description = "Variable",
                    Type        = "5",
                    Location    = "Sibiu",
                    Date        = Convert.ToDateTime("2019-05-05T11:11:11"),
                    Currency    = "USD",
                    Sum         = 555.77,
                    Comments    = new List <Comment>()
                    {
                        new Comment
                        {
                            Important = true,
                            Text      = "An important expense",
                            Owner     = null
                        }
                    },
                };

                var current = taskService.Create(added, null);

                var allComments = commentService.GetAll(string.Empty, 1);
                Assert.AreEqual(1, allComments.NumberOfPages);
            }
        }
Esempio n. 22
0
 public ExpensesController(IUnitOfWork <Expense> uowExpense, IUnitOfWork <Category_expense> uowCategory)
 {
     _expenseRepo      = new ExpensesService(uowExpense);
     _categorieExpense = new CategoriesService(uowCategory);
 }
Esempio n. 23
0
 public ExpensesController(ExpensesService service)
 {
     expensesService = service;
 }
Esempio n. 24
0
 public ExpensesServicesTests(ExpensesRepo repo, ExpensesService service)
 {
     _repo    = repo;
     _service = new ExpensesService(_repo);
 }
Esempio n. 25
0
        public void CheckExpensesOnPaginatedListShouldReturnAllExpenseOnAPage()
        {
            var options = new DbContextOptionsBuilder <DataDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(CheckExpensesOnPaginatedListShouldReturnAllExpenseOnAPage))
                          .Options;

            using (var context = new DataDbContext(options))
            {
                // declare service
                var expenseService = new ExpensesService(context);

                // add 5 expenses, for 2 pages with 3 expenses on a PaginatedList
                expenseService.AddExpense(new ExpensesPostModel()
                {
                    Description = "Test description 1",
                    Sum         = 20,
                    Location    = "Cluj",
                    Date        = DateTime.ParseExact("05/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "RON",
                    Type        = "Food",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "A test comment",
                            Important = false
                        }
                    }
                });
                expenseService.AddExpense(new ExpensesPostModel()
                {
                    Description = "Test description 2",
                    Sum         = 20,
                    Location    = "Brasov",
                    Date        = DateTime.ParseExact("05/31/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "Euro",
                    Type        = "Food",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "A test comment 2",
                            Important = false
                        }
                    }
                });
                expenseService.AddExpense(new ExpensesPostModel()
                {
                    Description = "Test description 2",
                    Sum         = 20,
                    Location    = "Brasov",
                    Date        = DateTime.ParseExact("05/31/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "Euro",
                    Type        = "Food",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "A test comment 2",
                            Important = false
                        }
                    }
                });
                expenseService.AddExpense(new ExpensesPostModel()
                {
                    Description = "Test description 2",
                    Sum         = 20,
                    Location    = "Brasov",
                    Date        = DateTime.ParseExact("05/31/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "Euro",
                    Type        = "Food",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "A test comment 2",
                            Important = false
                        }
                    }
                });
                expenseService.AddExpense(new ExpensesPostModel()
                {
                    Description = "Test description 2",
                    Sum         = 20,
                    Location    = "Brasov",
                    Date        = DateTime.ParseExact("05/31/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "Euro",
                    Type        = "Food",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "A test comment 2",
                            Important = false
                        }
                    }
                });

                // set the page number
                int Page = 1;
                PaginatedList <ExpensesGetModel> actual =
                    expenseService.GetAllExpenses(Page,
                                                  DateTime.ParseExact("04/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                                                  DateTime.ParseExact("06/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                                                  TaskWork.Models.Type.Food);

                // check if something is returned and number of expenses on the first page
                Assert.IsNotNull(actual);
                Assert.AreEqual(3, actual.Entries.Count);

                // set the page number
                Page = 2;
                PaginatedList <ExpensesGetModel> actual2 =
                    expenseService.GetAllExpenses(Page,
                                                  DateTime.ParseExact("04/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                                                  DateTime.ParseExact("06/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                                                  TaskWork.Models.Type.Food);

                // check if something is returned and number of expenses on on the second page
                Assert.IsNotNull(actual2);
                Assert.AreEqual(2, actual2.Entries.Count);
            }
        }
Esempio n. 26
0
        /// <summary>
        ///     获取店铺今日运营概况
        /// </summary>
        /// <param name="userContext"></param>
        /// <returns></returns>
        public AccountOverview GetAccountOverViewToday(UserContext userContext)
        {
            var accountBusiness = _accountBusinessDapperRepository.Find(x => x.accountid == userContext.AccId);

            //销售情况
            var strSqlCoupon =
                @"SELECT @SalesMoney=cast(sum(RealMoney) as decimal(18, 2)),@GoodsSalesCount=SUM(saleNum) FROM dbo.T_SaleInfo 
                                WHERE accID=@AccountId AND saleTime BETWEEN @sDate AND @eDate;
                                IF @SalesMoney IS NULL SET @SalesMoney=0;
                                IF @GoodsSalesCount IS NULL SET @GoodsSalesCount=0;
                                ";

            var sDate = DateTime.Now.ToShortDateString();
            var eDate = DateTime.Now.ToShortDateString();

            sDate = sDate + " 00:00:00";
            eDate = eDate + " 23:59:59";
            var sqlParams = new
            {
                AccountId = userContext.AccId,
                sDate,
                eDate
            };
            var dapperParam = new DynamicParameters(sqlParams);

            dapperParam.Add("SalesMoney", dbType: DbType.Decimal, direction: ParameterDirection.Output);
            dapperParam.Add("GoodsSalesCount", dbType: DbType.Int32, direction: ParameterDirection.Output);
            var sqlQuery = new SqlQuery(strSqlCoupon, dapperParam);

            _salesDapperRepository.FindAll(sqlQuery);
            var salesMoney      = dapperParam.Get <decimal>("SalesMoney");
            var goodsSalesCount = dapperParam.Get <int>("GoodsSalesCount");

            //库存警告
            var strSqlGoodsWarning = new StringBuilder();

            strSqlGoodsWarning.Append("SELECT @GoodsWarning=COUNT( DISTINCT a.gid) ");
            strSqlGoodsWarning.Append("from T_GoodsInfo ");
            strSqlGoodsWarning.Append("a left join T_Goods_Sku b ");
            strSqlGoodsWarning.Append("on a.gid=b.gid ");
            strSqlGoodsWarning.Append("where a.accID=@accId and  ISNULL(a.isDown,0)=0  ");
            strSqlGoodsWarning.Append(
                "and ((a.IsExtend=1 and ( b.gsQuantity>=b.LimitUpper or b.gsQuantity<=b.LimitLower)) ");
            strSqlGoodsWarning.Append(
                "or (ISNULL(a.IsExtend,0)=0 and (a.gQuantity>=a.LimitUpper or a.gQuantity<=a.LimitLower))) ");
            var sqlParamsGoodsWarning = new
            {
                accId = userContext.AccId
            };
            var dapperParamGoodsWarning = new DynamicParameters(sqlParamsGoodsWarning);

            dapperParamGoodsWarning.Add("GoodsWarning", dbType: DbType.Int32, direction: ParameterDirection.Output);
            var sqlQueryGoodsWarning = new SqlQuery(strSqlGoodsWarning.ToString(), dapperParamGoodsWarning);

            _salesDapperRepository.FindAll(sqlQueryGoodsWarning);
            var goodsWarning = dapperParamGoodsWarning.Get <int>("GoodsWarning");


            //店铺会员生日
            var userBirthdayCount = 0;
            var responseUser      = _userService.GetBirthdayUsers(userContext,
                                                                  DateTime.Parse(DateTime.Now.ToShortDateString()));

            if (responseUser.Code == (int)ErrorCodeEnum.Success)
            {
                userBirthdayCount = ((IEnumerable <BirthdayUsersResult>)responseUser.Data).Count();
            }

            var expenseService  = new ExpensesService();
            var accountOverview = new AccountOverview
            {
                SalesMoney        = salesMoney,
                GoodsSalesCount   = goodsSalesCount,
                UserBirthdayCount = userBirthdayCount,
                GoodsStockCount   = goodsWarning,
                SmsCount          = accountBusiness.dxunity
            };
            var searchParams = new ExpensesSearchParam
            {
                StartDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1, 0, 0, 0),
                EndDate   = DateTime.Now
            };

            //本月支出总额
            var expenseResult = expenseService.GetExpenses(userContext, searchParams);

            if (expenseResult.Code == (int)ErrorCodeEnum.Success)
            {
                accountOverview.ThisMonthExpense = ((ExpensesSearchResult)expenseResult.Data).TotalExpensesAmount;
            }
            //资金账户可提现余额
            accountOverview.TotalMoeny =
                ((AccountBalanceResponse)_accountbookService.GetWithdrawingBalance(userContext).Data).TotalBalance;

            //会员总数
            accountOverview.UsersNum = _userInfoDapperRepository.FindAll(x => x.AccId == userContext.AccId).Count();

            //今日手机橱窗订单总数
            var ordersStrSql = new StringBuilder();
            var searchDate   = Convert.ToDateTime(DateTime.Now.ToShortDateString());

            ordersStrSql.Append(
                "SELECT COUNT(bid) as TotalOrdersNum FROM T_Goods_Booking WHERE accid=@accId AND payType=1 AND bState IN (4,6) AND bInsertTime BETWEEN @StartDate AND @EndDate;");
            var sqlParamMobileOrdersNum = new
            {
                accId     = userContext.AccId,
                StartDate = searchDate,
                EndDate   = searchDate.AddDays(1).AddSeconds(-1)
            };
            var dapperParamMobileOrdersNum = new DynamicParameters(sqlParamMobileOrdersNum);
            var sqlQueryMobileOrdersNum    = new SqlQuery(ordersStrSql.ToString(), dapperParamMobileOrdersNum);

            accountOverview.TodayMobileOrdersNum = Convert.ToInt32(_getRepository.FindAll(sqlQueryMobileOrdersNum).FirstOrDefault());

            return(accountOverview);
        }
Esempio n. 27
0
 public ExpensesController(ExpensesService expensesService)
 {
     _expensesService = expensesService;
 }