예제 #1
0
 public IActionResult Create(Make make)
 {
     if (ModelState.IsValid)
     {
         _context.Makes.Add(make);
         _context.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(make));
 }
예제 #2
0
        public IActionResult CreatePost()
        {
            if (!ModelState.IsValid)
            {
                return(View(BModelVM));
            }

            _context.BModels.Add(BModelVM.BModel);
            _context.SaveChanges();
            return(RedirectToAction(nameof(Index)));
        }
예제 #3
0
        public IActionResult CreatePost()
        {
            if (!ModelState.IsValid)
            {
                return(View(BikeVM));
            }

            _context.Bikes.Add(BikeVM.Bike);
            _context.SaveChanges();

            //////////////////////////
            // save bike logic
            //////////////////////////

            //   var BikeID = BikeVM.Bike.Id;

            //   string wwwrootPath = _hosting.ContentRootPath;

            //    var files = HttpContext.Request.Form.Files;

            //        var SavedBike = _context.Bikes.Find(BikeID);

            /*       if (files.Count != 0)
             *     {
             *         var ImagePath = @"images/bike/";
             *         var Extension = Path.GetExtension(files[0].FileName);
             *         var RelativeImagePath = ImagePath + BikeID + Extension;
             *         var AbsolutePath = Path.Combine(wwwrootPath, RelativeImagePath);
             *
             *         using (var fileStream = new FileStream(AbsolutePath, FileMode.Create))
             *         {
             *             files[0].CopyTo(fileStream);
             *         }
             *
             *         SavedBike.ImagePath = RelativeImagePath;
             *         _context.SaveChanges();
             *     }
             */
            return(RedirectToAction(nameof(Index)));
        }