public List <TimeBookingType> GetAllowedActionsList(DateTime dateTime, int refUserId) { List <TimeBookingType> allowedActions = new List <TimeBookingType>(); List <TimeBooking> bookingsForSelectedDay = TimeBookings.GetDataForDay(dateTime, refUserId); if (bookingsForSelectedDay.Count > 0) { if (bookingsForSelectedDay.Last().TimeBookingType == TimeBookingType.Login) { allowedActions.Add(TimeBookingType.StartBreak); allowedActions.Add(TimeBookingType.Logout); } if (bookingsForSelectedDay.Last().TimeBookingType == TimeBookingType.StartBreak) { allowedActions.Add(TimeBookingType.EndBreak); } if (bookingsForSelectedDay.Last().TimeBookingType == TimeBookingType.EndBreak) { allowedActions.Add(TimeBookingType.StartBreak); allowedActions.Add(TimeBookingType.Logout); } if (bookingsForSelectedDay.Last().TimeBookingType == TimeBookingType.Logout) { allowedActions.Add(TimeBookingType.Login); } } else { allowedActions.Add(TimeBookingType.Login); } return(allowedActions); }
public bool ValidateBooking(TimeBooking timeBooking) { if (timeBooking.RefUserId == 0) { return(false); } List <TimeBooking> bookingsForSelectedDay = TimeBookings.GetDataForDay(timeBooking.BookingTime, timeBooking.RefUserId); if (bookingsForSelectedDay?.Count > 0) { if (bookingsForSelectedDay.Last().TimeBookingType == timeBooking.TimeBookingType) { return(false); } if (bookingsForSelectedDay.Last().TimeBookingType == TimeBookingType.Login && (timeBooking.TimeBookingType != TimeBookingType.StartBreak && timeBooking.TimeBookingType != TimeBookingType.Logout)) { return(false); } if (bookingsForSelectedDay.Last().TimeBookingType == TimeBookingType.StartBreak && timeBooking.TimeBookingType != TimeBookingType.EndBreak) { return(false); } if (bookingsForSelectedDay.Last().TimeBookingType == TimeBookingType.EndBreak && (timeBooking.TimeBookingType != TimeBookingType.StartBreak && timeBooking.TimeBookingType != TimeBookingType.Logout)) { return(false); } } else { if (timeBooking.TimeBookingType != TimeBookingType.Login) { return(false); } } return(true); }
private void SaveBalance(TimeBooking timeBooking) { var bookings = TimeBookings.GetDataForDay(timeBooking.BookingTime, timeBooking.RefUserId); var hours = timeBooking.BookingTime - bookings.First().BookingTime; var obligatoryHours = TimeObligatoryHours.GetByRefUserId(timeBooking.RefUserId); if (obligatoryHours.Count > 0) { var day = obligatoryHours.SingleOrDefault(x => x.DayOfWeek == timeBooking.BookingTime.DayOfWeek); if (day != null) { var dayItem = CreateDayItem(bookings, day); var balanceValue = dayItem.WorkingHours.TotalHours - day.HoursPerDay; var lastItem = TimeBalances.GetLastByDateAndRefUserId(timeBooking.BookingTime, timeBooking.RefUserId); if (lastItem != null) { balanceValue += lastItem.Balance; } var existingItem = TimeBalances.GetByDateAndRefUserId(timeBooking.BookingTime, timeBooking.RefUserId); if (existingItem != null) { existingItem.Balance = balanceValue; TimeBalances.Update(existingItem); } else { TimeBalance timeBalance = new TimeBalance(timeBooking.RefUserId, timeBooking.BookingTime, balanceValue); TimeBalances.Insert(timeBalance); } } } }
private void LoadTimeBookingsForDay() { BookingsForSelectedDay = TimeBookings.GetDataForDay(bookingTime, RefUserId); }