public ReturnBoatViewModel MarkAsRenturned(ReturnBoatInputModel rentOutInputModel)
        {
            var rent = _repository.GetAllBoats().Include("Rents").First(x => x.Id == rentOutInputModel.BoatNumber).Rents.FirstOrDefault();

            if (rent == null)
            {
                throw new Exception("Can not find the rent record.");
            }

            rent.EndTime = DateTime.Now;

            _repository.MarkAsRenturned(rentOutInputModel.BoatNumber, rent.EndTime.Value);

            if (rent.StartTime == null || rent.EndTime == null)
            {
                throw new Exception("Cloun't mark as rented");
            }

            TimeSpan ts = rent.EndTime.Value - rent.StartTime.Value;

            return(new ReturnBoatViewModel()
            {
                RentTime = ts,
                Price = decimal.Round(ts.Seconds * rent.Boat.HourlyRate / 60 / 60, 2)
            });
        }
Beispiel #2
0
        public ActionResult MarkAsRenturned(ReturnBoatInputModel returnBoatInputModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    return(View("ReturnBoatWasSuccessful", WorkerService.MarkAsRenturned(returnBoatInputModel)));
                }
                catch (Exception exception)
                {
                    ModelState.AddModelError("", exception.Message);
                }
            }

            return(View());
        }