Exemple #1
0
 public ActionResult Create(ViewModels.BilCreateViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     using (var db = new Models.BilModel2())
     {
         var bil = new Models.Bil
         {
             Color        = model.Color,
             Manufacturer = model.Manufacturer,
             Model        = model.Modell,
             Year         = model.Year
         };
         db.Bilar.Add(bil);
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Exemple #2
0
        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"));
        }
Exemple #3
0
        public ActionResult Create()
        {
            var model = new ViewModels.BilCreateViewModel();

            return(View(model));
        }