public ActionResult Rent(RentalValidation rentalValidation) { var passToView = new RentalViewModel() { SelectedCustomer = rentalValidation.SelectedCustomer, SelectedVehicle = rentalValidation.SelectedVehicle, Vehicles = _context.Vehicles.Where(c => c.IsAvailable == true).ToList(), Customers = _context.Customers.ToList() }; if (!ModelState.IsValid) { return(View("Index", passToView)); } var activeRentalObject = new ActiveRental(); var vehicle = _context.Vehicles.Include(c => c.VehicleType).SingleOrDefault(c => c.Id == rentalValidation.SelectedVehicle); var customer = _context.Customers.Include(c => c.Gender).SingleOrDefault(c => c.Id == rentalValidation.SelectedCustomer); vehicle.IsAvailable = false; customer.IsActive = true; activeRentalObject.CustomerName = customer.Name; activeRentalObject.VehicleNumber = vehicle.Number; activeRentalObject.VehicleName = vehicle.Name; activeRentalObject.IssueTime = DateTime.Now; activeRentalObject.VehicleId = vehicle.Id; activeRentalObject.CustomerId = customer.Id; activeRentalObject.VehicleTypeId = vehicle.VehicleTypeId; _context.ActiveRentals.Add(activeRentalObject); _context.SaveChanges(); return(RedirectToAction("ActiveRentals")); }
public ActionResult AddRental(RentalViewModel model) { RentalViewModel r = new RentalViewModel(); r.PolicyId = HttpContext.User.Identity.Name; ViewBag.Itemcode = _item.CanBeRentedItems(); if (!_Rental.ItemAvailability(model).Equals("no error")) { ViewBag.ItemAvailability = _Rental.ItemAvailability(model); return(View()); } if (model.Quantity <= 0) { ViewBag.ItemAvailability = "Quantity must be greater than 0"; return(View()); } if (model.DateRequire <= System.DateTime.Now.Date) { ViewBag.Calender = "Date required cannot be today's or previous date"; return(View()); } if (model.Quantity > 0) { _Rental.AddRental(model); } return(RedirectToAction("Details", "Rental", new { id = _Rental.getRentalID(HttpContext.User.Identity.Name) })); }
public ActionResult DeleteRental(RentalViewModel model, string id) { _Rental.DeleteRental(id); RedirectToAction("Index"); //Content("Sucessfull"); return(View()); }
public IActionResult Index() { var model = new RentalViewModel(); model.Films = filmService.listAll(); return(View(model)); }
public IActionResult RentMovie(int movieId) { var rentVM = new RentalViewModel() { Movie = _movieRepository.GetById(movieId), Customers = _customerRepository.GetAll() }; return(View(rentVM)); }
public IActionResult RentMovie(RentalViewModel rentalViewModel) { var movie = _movieRepository.GetById(rentalViewModel.Movie.Id); var customer = _customerRepository.GetById(rentalViewModel.Movie.BorrowerId); movie.Borrower = customer; _movieRepository.Update(movie); return(RedirectToAction("Index")); }
public ActionResult AddRental(string id, double price, string name) { RentalViewModel r = new RentalViewModel(); r.PolicyId = HttpContext.User.Identity.Name; r.ItemCode = id; r.TotalPrice = price; r.ItemName = name; return(View(r)); }
public ActionResult Index() { var Customers = _context.Customers.ToList(); var availableVehicles = _context.Vehicles.Where(c => c.IsAvailable == true).ToList(); var passToView = new RentalViewModel() { Customers = Customers, Vehicles = availableVehicles }; return(View(passToView)); }
public async Task <IActionResult> Create(RentalViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var rental = await _gatewayService.Post("rentals", model); return(rental.IsSuccess ? RedirectToAction(nameof(Index)).WithSuccess("Puiku!", "Sukurtas naujas nuomos objektas.") : View().WithWarning("Oops!", rental.ErrorMessage)); }
public async Task <IActionResult> Edit(RentalViewModel model) { if (!ModelState.IsValid) { return(RedirectToAction(nameof(Edit), new { id = model.Id })); } var rental = await _gatewayService.Put("rentals", model); return(rental.IsSuccess ? RedirectToAction(nameof(Edit), new { id = model.Id }).WithSuccess("Yay!", "Sėkmingai atnaujinote nuomos objektą.") : RedirectToAction(nameof(Edit), new { id = model.Id }).WithWarning("Oops!", rental.ErrorMessage)); }
public void UpdateRental(RentalViewModel rental) { var dbRental = new Rental() { Id = rental.Id, BookingNumber = rental.BookingNumber, BoatNumber = rental.BoatNumber, PersonalNumber = rental.PersonalNumber, DeliveryDate = rental.DeliveryDate, Cost = rental.Cost }; rentalRepository.Update(dbRental); }