public async Task <IActionResult> Edit(int id, string plate, int customerid, DateTime startdate, DateTime enddate, string location, string couponcode, Reservation reservation) { if (id != reservation.ReservationId) { return(NotFound()); } if (_context.Cars.Where(c => c.Plate == plate && c.Location == location).FirstOrDefault() != null) { Car MyCar = _context.Cars.Where(c => c.Plate == plate && c.Location == location).FirstOrDefault(); reservation.CarId = MyCar.CarId; reservation.Plate = MyCar.Plate; reservation.Location = MyCar.Location; if (_context.Customers.Where(c => c.CustomerId == customerid).FirstOrDefault() != null) { Customer MyCustomer = _context.Customers.Where(c => c.CustomerId == customerid).FirstOrDefault(); reservation.CustomerId = MyCustomer.CustomerId; reservation.StartDate = startdate; reservation.EndDate = enddate; if ((reservation.StartDate <= reservation.EndDate) && (reservation.StartDate >= DateTime.Now)) { if (_context.Reservations.Where(c => (c.EndDate < reservation.StartDate || c.StartDate > reservation.EndDate)).Any()) { _context.Update(reservation); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else if (_context.Reservations.Where(c => c.Plate == reservation.Plate).Any() == false) { _context.Update(reservation); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } } else { return(View()); } } else { return(View()); } return(View()); }
public async Task <IActionResult> Edit(int id, [Bind("CustomerId,Name,BirthDate,Location")] Customer customer) { if (id != customer.CustomerId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(customer); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(customer.CustomerId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Rentee,CarId,Car,From,To")] Rental rental) { if (id != rental.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(rental); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RentalExists(rental.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(rental)); }
public async Task <IActionResult> Edit(int id, [Bind("CarId,Plate,Manufacturer,Model,PricePerDay,Location")] Car car) { if (id != car.CarId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(car); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CarExists(car.CarId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(car)); }
public async Task <IActionResult> Edit(string id, [Bind("CouponCode,Description,Discount")] Coupon coupon) { if (id != coupon.CouponCode) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(coupon); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CouponExists(coupon.CouponCode)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(coupon)); }
public async Task <IActionResult> Edit(int id, [Bind("ReservStatsID,Name,Description")] ReservationStatus reservationStatus) { if (id != reservationStatus.ReservStatsID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(reservationStatus); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReservationStatusExists(reservationStatus.ReservStatsID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(reservationStatus)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Brand,Model,Year,Mileage,Fuel,Seats,combisudan,about,ImgSrc")] Car car) { if (id != car.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(car); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CarExists(car.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(car)); }
public IActionResult Put(int id, [FromBody] Order order) { if (ModelState.IsValid) { db.Update(order); db.SaveChanges(); return(Ok(order)); } return(BadRequest(ModelState)); }
public async Task <ReservationDetailDTO> UpdateReservation(ReservationIndexDTO reservationIndexDTO, Reservation reservation) { if (reservationIndexDTO.ReservationNumber != reservation.ReservationNumber || reservationIndexDTO.Surname != reservation.Surname) { throw new ArgumentException("Given parameters does not match (ReservationNumber or Surname)"); } if (await FindReservation(reservationIndexDTO, true) == null) { throw new ArgumentNullException("Reservation does not exists"); } if (!await CheckCarAvailability(reservation.CarId, reservation.PickUpDate, reservation.ReturnDate, reservation.ReservationNumber)) { throw new ArgumentException("Selected Car is not available at this time"); } _context.Update(reservation); await _context.SaveChangesAsync(); return(await ReservationToDTO(reservation)); }