Exemple #1
0
        public bool SaveTimeBooking(TimeBooking timeBooking)
        {
            if (!ValidateBooking(timeBooking))
            {
                return(false);
            }

            TimeBookings.Insert(timeBooking);

            if (timeBooking.TimeBookingType == TimeBookingType.Logout)
            {
                SaveBalance(timeBooking);
            }

            var date        = timeBooking.BookingTime.Date;
            var allBookings = TimeBookings.GetDataSinceDayForRefUserId(timeBooking.BookingTime, timeBooking.RefUserId);

            while (date.Date < DateTime.Now.Date)
            {
                var booking = allBookings.SingleOrDefault(x => x.BookingTime.Date == date.Date && x.TimeBookingType == TimeBookingType.Logout);

                if (booking != null)
                {
                    SaveBalance(booking);
                }
                else
                {
                    SaveBalanceWithoutBookings(date, timeBooking.RefUserId);
                }

                date = date.AddDays(1);
            }

            return(true);
        }
        private void CreateNewBooking(TimeBookingType timeBookingType)
        {
            TimeBooking timeBooking = new TimeBooking();

            timeBooking.BookingTime     = DateTime.Now;
            timeBooking.TimeStamp       = DateTime.Now;
            timeBooking.TimeBookingType = timeBookingType;
            timeBooking.RefUserId       = Globals.ActiveUser.UserId;
            TimeBookings.Insert(timeBooking);
            Validate();
        }