Example #1
0
        private double CalculateCost(VideoBooking selectedBooking)
        {
            const double cost = 50;

            var selectedVideo = GetVideo().FirstOrDefault(v => v.Id.Equals(selectedBooking.VideoId));

            if (selectedVideo != null)
            {
                var daysToBeRent = selectedVideo.DaysToBeRent;

                var rentTillDate = selectedBooking.RentDate.AddDays(Convert.ToDouble(daysToBeRent));
                var dateCompare = DateTime.Compare(selectedBooking.ReturnDate, rentTillDate);

                if (dateCompare > 0)
                {
                    TimeSpan timeSpan = selectedBooking.ReturnDate - rentTillDate;
                    return (cost +
                            (Convert.ToDouble(timeSpan.Days * 20)));

                }
                else
                {
                    return cost;
                }
            }
            return 0;
        }
Example #2
0
        private double CalculateCost(VideoBooking selectedBooking)
        {
            const double cost = 50;
            const double penaltyPerDay = 20;

            var selectedVideo = GetVideo().FirstOrDefault(v => v.Id.Equals(selectedBooking.VideoId));

            if (selectedVideo != null)
            {
                var daysToBeRent = selectedVideo.DaysToBeRent;

                var rentTillDate = selectedBooking.RentDate.AddDays(Convert.ToDouble(daysToBeRent));
                var dateCompare = DateTime.Compare(selectedBooking.ReturnDate, rentTillDate);

                if (dateCompare > 0)
                {
                    TimeSpan timeSpan = selectedBooking.ReturnDate - rentTillDate;
                    return (cost +
                            (Convert.ToDouble(timeSpan.Days * penaltyPerDay)));    //TODO: Since you declared the cost as a constant you should do the same with the penalty cost

                }
                else
                {
                    return cost;
                }
            }
            return 0;
        }
Example #3
0
 public bool ReturnVideo(VideoBooking videoBooking)
 {
     try
     {
         return Db.ReturnVideo(videoBooking);
     }
     catch
     {
         throw;
     }
 }
Example #4
0
        public bool ReturnVideo(VideoBooking videoBooking)
        {
            try
            {
                var videos = GetVideo().ToList();

                if (!videos.Any(v=>v.Id.Equals(videoBooking.VideoId)))
                 throw new VideoRentalException(new Video() { Name = videoList[videoBooking.VideoId].Name });

                if(!bookingList.Any(bk=>bk.Key.Equals(videoBooking.Id)))
                    throw new VideoRentalException(new Video() { Name = videoList[videoBooking.VideoId].Name });

                bookingList[videoBooking.Id].ReturnDate = videoBooking.ReturnDate;
                bookingList[videoBooking.Id].Cost = videoBooking.Cost;

                var selectedVideo = videos.First(v => v.Id.Equals(videoBooking.VideoId));
                if (selectedVideo != null)
                {
                    videoList[selectedVideo.Id].IsRented = false;
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception)
            {

                throw new VideoRentalException(new Video() { Name = videoList[videoBooking.VideoId].Name });
            }
        }