Esempio n. 1
0
        public RentOutViewModel RequestRentingOut(RentOutInputModel rentOutInputModel)
        {
            var boat = _repository.GetAllBoats().FirstOrDefault(x => x.Id == rentOutInputModel.BoatNumber);

            if (boat == null)
            {
                throw new Exception("Boat is not found");
            }

            var rent = _repository.GetAllRents().FirstOrDefault(x => x.StartTime != null && x.EndTime == null && x.Boat.Id == rentOutInputModel.BoatNumber);

            if (rent != null)
            {
                throw new Exception("Boat is already rented");
            }

            var update = new Rent()
            {
                CustomerName = rentOutInputModel.CustomerName,
                StartTime    = DateTime.Now,
                EndTime      = null,
                BoatId       = rentOutInputModel.BoatNumber
            };

            _repository.Add(update);

            return(new RentOutViewModel()
            {
            });
        }
Esempio n. 2
0
        public ActionResult RequestRentingOut(RentOutInputModel rentOutInputModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    return(View("RentOutWasSuccesful", WorkerService.RequestRentingOut(rentOutInputModel)));
                }
                catch (Exception exception)
                {
                    ModelState.AddModelError("", exception.Message);
                }
            }

            return(View());
        }