コード例 #1
0
        public async Task <IActionResult> Index(string categoryId = "")
        {
            CostPerUnitController.MaintainCostPerUnitRecords(_context);

            if (categoryId == "")
            {
                var model = new CostItemIndexViewModel {
                    CostCategories = await _context.CostCategory.OrderBy(cc => cc.CategoryName).ToListAsync(),
                    CategoryItems  = new List <CostItem>()
                };

                return(View(model));
            }
            else
            {
                var catId = int.Parse(categoryId);
                var model = new CostItemIndexViewModel {
                    CategoryItems = await _context.CostItem.Where(ci => ci.CostCategoryId == catId)
                                    .Include(c => c.CostCategory)
                                    .Include(c => c.UnitOfMeasure)
                                    .OrderBy(ci => ci.ItemName)
                                    .ToListAsync()
                };

                return(PartialView("_IndexPartial", model));
            }
        }
コード例 #2
0
        // GET: ProjectCosts/Create
        public async Task <IActionResult> Create(int id)
        {
            CostPerUnitController.MaintainCostPerUnitRecords(_context);

            DateTime Today = DateTime.UtcNow;

            ProjectCostCreateViewModel model = new ProjectCostCreateViewModel {
                ProjectId = id,
                Project   = await _context.Project.FirstOrDefaultAsync(p => p.Id == id),
                Costs     = new List <ProjectCost>(),
                CostItems = new List <CostItem> ()
            };

            model.CostItems = await _context.CostItem.Include(ci => ci.UnitOfMeasure).OrderBy(ci => ci.ItemName).ToListAsync();

            ProjectCost Cost = new ProjectCost {
                ProjectId = id,
                DateUsed  = Today
            };

            model.Costs.Add(Cost);

            return(View(model));
        }