コード例 #1
0
 public IActionResult Create(Make make)
 {
     if (ModelState.IsValid)
     {
         _context.Add(make);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(make));
 }
コード例 #2
0
 public IActionResult CreatePost()
 {
     if (!ModelState.IsValid)
     {
         return(View(ModelVM));
     }
     _db.Models.Add(ModelVM.Model);
     _db.SaveChanges();
     return(RedirectToAction(nameof(Index)));
 }
コード例 #3
0
 public IActionResult Create(Make make)
 {
     if (ModelState.IsValid)
     {
         _db.Add(make);
         _db.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(make));
 }
コード例 #4
0
ファイル: BikeModelController.cs プロジェクト: ashiq97/eBike
 public IActionResult CreatePost(BikeModelVM bikeModelVM)
 {
     if (!ModelState.IsValid)
     {
         return(View(ModelVM));
     }
     _context.BikeModels.Add(bikeModelVM.BikeModel);
     _context.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #5
0
 public ActionResult Create([Bind(Include = "Id,Count,Price,BikeId,CompanyLocationId")] CompanyBike companyBike)
 {
     if (ModelState.IsValid)
     {
         db.CompanyBikes.Add(companyBike);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.BikeId = new SelectList(db.Bikes, "Id", "BikeModel", companyBike.BikeId);
     return(View(companyBike));
 }
コード例 #6
0
        public IActionResult CreatePost()
        {
            if (!ModelState.IsValid)
            {
                return(View(ModelViewModel));
            }

            mDbContext.Add(ModelViewModel.Model);
            mDbContext.SaveChanges();

            return(RedirectToAction(nameof(Index)));
        }
コード例 #7
0
        public ActionResult Create([Bind(Include = "Id,CompanyId,Street,Town,Postcode,Lat,Lon,ImageFilename")] CompanyLocation companyLocation)
        {
            if (ModelState.IsValid)
            {
                db.CompanyLocations.Add(companyLocation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CompanyId = new SelectList(db.Companies, "Id", "Name", companyLocation.CompanyId);
            return(View(companyLocation));
        }
コード例 #8
0
 public IActionResult EditPost()
 {
     if (!ModelState.IsValid)
     {
         MotorBikeVM.Makes  = _db.Makes.ToList();
         MotorBikeVM.Models = _db.Models.ToList();
         return(View(MotorBikeVM));
     }
     _db.MotorBikes.Update(MotorBikeVM.MotorBike);
     UploadImageIfAvailable();
     _db.SaveChanges();
     return(RedirectToAction(nameof(Index)));
 }
コード例 #9
0
        public ActionResult Create([Bind(Include = "Id,StartDate,EndDate,UserId,CompanyBikeId")] Booking booking)
        {
            //UpdateModel(booking);
            if (ModelState.IsValid)
            {
                // check the num of days of booking, max: 7
                if ((booking.EndDate - booking.StartDate).TotalDays > 7)
                {
                    return(HttpNotFound());
                }

                // check if the user creates data under their id
                if (booking.UserId != User.Identity.GetUserId())
                {
                    return(HttpNotFound());
                }

                if (booking.StartDate >= booking.EndDate)
                {
                    return(HttpNotFound());
                }

                if (booking.StartDate <= DateTime.Today)
                {
                    return(HttpNotFound());
                }

                var bookings = db.Bookings;
                foreach (var b in bookings.Where(c => c.CompanyBikeId == booking.CompanyBikeId && c.EndDate > DateTime.Today))
                {
                    if (booking.EndDate >= b.StartDate && booking.StartDate <= b.EndDate)
                    {
                        return(HttpNotFound());
                    }
                }
                db.Bookings.Add(booking);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(HttpNotFound());
        }
コード例 #10
0
        public IActionResult CreatePost()
        {
            if (!ModelState.IsValid)
            {
                BikeVM.Makes  = _db.Makes.ToList();
                BikeVM.Models = _db.Models.ToList();
                return(View(BikeVM));
            }
            _db.Bikes.Add(BikeVM.Bike);
            _db.SaveChanges();

            return(RedirectToAction(nameof(Index)));
        }
コード例 #11
0
        public InMemoryDbContextFactory(IEnumerable <T> data, bool seedData = true)
        {
            var options = new DbContextOptionsBuilder <BikeDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            context = new BikeDbContext(options);

            if (seedData == false)
            {
                return;
            }

            context.Set <T>().AddRange(data);
            context.SaveChanges();
        }
コード例 #12
0
 public int Commit()
 {
     return(bikeDbContext.SaveChanges());
 }
コード例 #13
0
 public void SaveChanges()
 {
     _context.SaveChanges();
 }