コード例 #1
0
ファイル: BilController.cs プロジェクト: aspcodenet/SPOBil
        // GET: Bil
        public ActionResult Index()
        {
            var model = new ViewModels.BilIndexViewModel();
            var db    = new Models.DBContext();

            model.Cars.AddRange(db.GetAll().Select(r => new ViewModels.BilIndexViewModel.BilListViewModel
            {
                Manufacturer = r.Manufacturer,
                Model        = r.Model,
                Year         = r.Year,
                Id           = r.Id
            }));

            return(View(model));
        }
コード例 #2
0
ファイル: BilController.cs プロジェクト: aspcodenet/SPOBil
        public ActionResult Search(string SearchManufacturer, string SearchYear)
        {
            var db    = new Models.DBContext();
            var model = new ViewModels.BilIndexViewModel
            {
                SearchManufacturer = SearchManufacturer,
                SearchYear         = SearchYear
            };

            model.Cars.AddRange(db.GetAll().Select(r => new ViewModels.BilIndexViewModel.BilListViewModel
            {
                Manufacturer = r.Manufacturer,
                Model        = r.Model,
                Year         = r.Year,
                Id           = r.Id
            }).Where(c => Matches(c, SearchManufacturer, SearchYear)
                     ));

            return(View("Index", model));
        }
コード例 #3
0
ファイル: BilController.cs プロジェクト: aspcodenet/SPOBil
        public ActionResult Create(ViewModels.BilCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var db    = new Models.DBContext();
            var newId = db.GetAll().Max(r => r.Id) + 1;

            var bil = new Models.Bil
            {
                Id           = newId,
                Color        = model.Color,
                Manufacturer = model.Manufacturer,
                Model        = model.Modell,
                Year         = model.Year
            };

            db.AddBil(bil);

            return(RedirectToAction("Index"));
        }