Пример #1
0
 public IActionResult Create(Make make)
 {
     if (ModelState.IsValid)
     {
         _context.Add(make);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(make));
 }
 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
 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)));
        }
        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();
 }