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))); }
public IActionResult Create(Make make) { if (ModelState.IsValid) { _db.Add(make); _db.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(make)); }
public IActionResult CreatePost(BikeModelVM bikeModelVM) { if (!ModelState.IsValid) { return(View(ModelVM)); } _context.BikeModels.Add(bikeModelVM.BikeModel); _context.SaveChanges(); return(RedirectToAction("Index")); }
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)); }
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)); }
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))); }
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()); }
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))); }
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(); }
public int Commit() { return(bikeDbContext.SaveChanges()); }
public void SaveChanges() { _context.SaveChanges(); }