コード例 #1
0
        public TransactionListDto GetTransactions()
        {
            var transactions  = _unitOfWork.TransactionRepository.GetAll();
            var categories    = _unitOfWork.CategoryRepository.GetAll().ToList();
            var subcategories = _unitOfWork.SubCategoryRepository.GetAll().ToList();

            TransactionListDto transactionList = new TransactionListDto
            {
                Transations = new List <TransactionResponseDto>()
            };

            if (transactions != null)
            {
                foreach (var item in transactions)
                {
                    transactionList.Transations.Add(new TransactionResponseDto
                    {
                        CategoryId      = item.CategoryId,
                        FamilyId        = item.FamilyId,
                        SubCategoryId   = item.SubCategoryId,
                        CategoryName    = categories.Where(x => x.Id.Equals(item.CategoryId)).Select(y => y.Name).FirstOrDefault(),
                        SubCategoryName = subcategories.Where(x => x.Id.Equals(item.SubCategoryId)).Select(y => y.Name).FirstOrDefault(),
                        TransactionDate = item.CreatedAt,
                        Amount          = item.Amount
                    });
                }
            }

            return(transactionList);
        }
コード例 #2
0
        public TransactionListDto[] Map(Transaction[] transactions)
        {
            List <TransactionListDto> list = new List <TransactionListDto> ();

            var servicesCategories = transactions.Select(t => t.ServiceId).Distinct();

            foreach (var serviceId in servicesCategories)
            {
                var services           = transactions.Where(t => t.ServiceId == serviceId);
                TransactionListDto tld = new TransactionListDto()
                {
                    ServiceId   = services.Select(t => t.Service.Id).First(),
                    Count       = services.Count(),
                    Price       = services.Select(t => t.Service.ServicePrice).First(),
                    ServiceName = services.Select(t => t.Service.ServiceName).First(),
                    TotalPrice  = services.Sum(t => t.Service.ServicePrice)
                };
                list.Add(tld);
            }
            return(list.ToArray());
        }