public async Task <IActionResult> ReserveBike([FromRoute] int bikeId, [FromBody] BikeReservationRequest bikeReservationRequest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var idClaim = User.Claims.FirstOrDefault(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"); if (idClaim == null) { return(BadRequest()); } var newReservation = new BikeReservation { BikeId = bikeId, ReservedBy = idClaim.Value, StartTime = bikeReservationRequest.StartTime, EndTime = bikeReservationRequest.EndTime, IsActive = true }; _context.Add(newReservation); await _context.SaveChangesAsync(); return(CreatedAtRoute("ReservationDetails", newReservation.Id, newReservation)); }
public IActionResult Create(Customer customer) { if (ModelState.IsValid) { _context.Add(customer); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public IActionResult Create(Product product) { if (ModelState.IsValid) { _context.Add(product); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryID"] = new SelectList(_context.Category, "CategoryID", "CategoryName", product.CategoryID); return(View(product)); }
public IActionResult Create(Order order) { if (ModelState.IsValid) { _context.Add(order); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } ViewData["CustomerID"] = new SelectList(_context.Customer, "CustomerId", "Address", order.CustomerID); ViewData["ProductId"] = new SelectList(_context.Product, "ProductId", "ProductDescription", order.ProductId); return(View(order)); }
public void TestCreateRental() { BikePoco bikePoco = new BikePoco { Brand = "KTM", Category = "Sport Bike", DateOfLastService = DateTime.Parse("2018/01/20"), PriceFirstHour = 3, PriceAdditionalHour = 5, PurchaseDate = DateTime.Now }; this.rentalController.CreateNewBike(bikePoco); CustomerPoco customerPoco = new CustomerPoco { Birthday = DateTime.Parse("2018/06/24"), Firstname = "Philipp", Lastname = "CreateCustomerTest", Gender = "männlich", Housenumber = 24, Street = "Marktplatz", ZipCode = 4310, Town = "Mauthausen" }; this.rentalController.CreateNewCustomer(customerPoco); BikeContext context = new BikeContext(); Bike bike = context.Bikes.Last(); Customer customer = context.Customers.Last(); Rental rental = new Rental { Bike = bike, Customer = customer, Paid = false, RentalBegin = DateTime.Parse("24.06.1999 10:00:00"), RentalEnd = DateTime.Parse("24.06.1999 11:00:00"), TotalPrice = 0 }; context.Add(rental); context.SaveChanges(); Rental selectRental = this.rentalController.GetAllRentalsByCustomerId(customer.CustomerId).Find(r => r.Customer.CustomerId == customer.CustomerId); if (selectRental == null) { Assert.Fail(); } }