Esempio n. 1
0
        private RouteViewModel GetRouteExpenses(RouteViewModel routeViewModel)
        {
            //Get route expense list
            var expenseCate        = Convert.ToInt32(ExpenseCategory.Expense).ToString();
            var expensesDepartment = _routeDetailRepository.Query(
                p => p.RouteId == routeViewModel.RouteId & p.CategoryI == expenseCate &
                p.IsUsed).OrderBy(p => p.DisplayLineNo);

            var expensesDestination = Mapper.Map <IEnumerable <Route_D>, IEnumerable <RouteExpenseViewModel> >(expensesDepartment);

            //Get route allowance list
            var allowanceCate       = Convert.ToInt32(ExpenseCategory.Allowance).ToString();
            var allowancesDeparment = _routeDetailRepository.Query(
                p => p.RouteId == routeViewModel.RouteId & p.CategoryI == allowanceCate &
                p.IsUsed).OrderBy(p => p.DisplayLineNo);

            var allowancesDestination = Mapper.Map <IEnumerable <Route_D>, IEnumerable <RouteExpenseViewModel> >(allowancesDeparment);

            //Get route fixed expense list
            var fixedCate = Convert.ToInt32(ExpenseCategory.Fix).ToString();
            var fixedExpensesDeparment = _routeDetailRepository.Query(
                p => p.RouteId == routeViewModel.RouteId & p.CategoryI == fixedCate &
                p.IsUsed).OrderBy(p => p.DisplayLineNo);

            var fixedExpensesDestination = Mapper.Map <IEnumerable <Route_D>, IEnumerable <RouteExpenseViewModel> >(fixedExpensesDeparment);

            //Get route other expense list
            var otherCate = Convert.ToInt32(ExpenseCategory.Other).ToString();
            var otherExpensesDeparment = _routeDetailRepository.Query(
                p => p.RouteId == routeViewModel.RouteId & p.CategoryI == otherCate &
                p.IsUsed).OrderBy(p => p.DisplayLineNo);

            var otherExpensesDestination = Mapper.Map <IEnumerable <Route_D>, IEnumerable <RouteExpenseViewModel> >(otherExpensesDeparment);

            routeViewModel.ExpenseList      = expensesDestination == null ? null : expensesDestination.ToList();
            routeViewModel.AllowanceList    = allowancesDestination == null ? null : allowancesDestination.ToList();
            routeViewModel.FixedExpenseList = fixedExpensesDestination == null ? null : fixedExpensesDestination.ToList();
            routeViewModel.OtherExpenseList = otherExpensesDestination == null ? null : otherExpensesDestination.ToList();
            return(routeViewModel);
        }
        public SuggestedExpenseList GetSuggestedExpensesFromRoute(List <SuggestedRoute> suggestedRoutes)
        {
            var suggestedExpenses = new SuggestedExpenseList();

            suggestedExpenses.ExpenseList      = new List <CustomerPricingDetailViewModel>();
            suggestedExpenses.AllowanceList    = new List <CustomerPricingDetailViewModel>();
            suggestedExpenses.FixedExpenseList = new List <CustomerPricingDetailViewModel>();
            suggestedExpenses.OtherExpenseList = new List <CustomerPricingDetailViewModel>();
            foreach (var suggestedRoute in suggestedRoutes)
            {
                var route       = suggestedRoute;
                var expenseRoot = Convert.ToInt32(ExpenseRoot.Route).ToString();

                #region Get route expense list
                var expenseCate = Convert.ToInt32(ExpenseCategory.Expense).ToString();
                var expenses    = _routeDetailRepository.Query(
                    p => p.RouteId == route.RouteId & p.CategoryI == expenseCate &
                    p.IsUsed).ToList();

                if (expenses.Any())
                {
                    var expensesDestination = Mapper.Map <List <Route_D>, List <CustomerPricingDetailViewModel> >(expenses);
                    expensesDestination.ForEach(s => s.ExpenseRoot = expenseRoot);
                    suggestedExpenses.ExpenseList.AddRange(expensesDestination);
                }
                #endregion

                #region Get route allowance list
                var allowanceCate = Convert.ToInt32(ExpenseCategory.Allowance).ToString();
                var allowances    = _routeDetailRepository.Query(
                    p => p.RouteId == route.RouteId & p.CategoryI == allowanceCate &
                    p.IsUsed).ToList();

                if (allowances.Any())
                {
                    var allowancesDestination = Mapper.Map <List <Route_D>, List <CustomerPricingDetailViewModel> >(allowances);
                    allowancesDestination.ForEach(s => s.ExpenseRoot = expenseRoot);
                    suggestedExpenses.AllowanceList.AddRange(allowancesDestination);
                }
                #endregion

                #region Get fixed expense list
                var fixedCate     = Convert.ToInt32(ExpenseCategory.Fix).ToString();
                var fixedExpenses = _routeDetailRepository.Query(
                    p => p.RouteId == route.RouteId & p.CategoryI == fixedCate &
                    p.IsUsed).ToList();

                if (fixedExpenses.Any())
                {
                    var fixedExpensesDestination = Mapper.Map <List <Route_D>, List <CustomerPricingDetailViewModel> >(fixedExpenses);

                    fixedExpensesDestination.ForEach(s => s.ExpenseRoot = expenseRoot);
                    suggestedExpenses.FixedExpenseList.AddRange(fixedExpensesDestination);
                }
                #endregion

                #region Get other expense list
                var otherCate     = Convert.ToInt32(ExpenseCategory.Other).ToString();
                var otherExpenses = _routeDetailRepository.Query(
                    p => p.RouteId == route.RouteId & p.CategoryI == otherCate &
                    p.IsUsed).ToList();

                if (otherExpenses.Any())
                {
                    var otherExpensesDestination = Mapper.Map <List <Route_D>, List <CustomerPricingDetailViewModel> >(otherExpenses);
                    otherExpensesDestination.ForEach(s => s.ExpenseRoot = expenseRoot);
                    suggestedExpenses.OtherExpenseList.AddRange(otherExpensesDestination);
                }
                #endregion
            }
            return(suggestedExpenses);
        }