Beispiel #1
0
        private TimeBookingDayItem CreateDayItem(IEnumerable <TimeBooking> timeBookings, TimeObligatoryHour timeObligatoryHour)
        {
            if (timeBookings == null || timeObligatoryHour == null)
            {
                return(null);
            }

            List <TimeBooking> timeBookingList = timeBookings.ToList();

            if (!timeBookings.Any(x => x.TimeBookingType == TimeBookingType.Logout))
            {
                return(null);
            }

            DateTime login          = DateTime.MinValue;
            DateTime logout         = DateTime.MinValue;
            DateTime startBreak     = DateTime.MinValue;
            DateTime endBreak       = DateTime.MinValue;
            TimeSpan sumWorkingTime = new TimeSpan(0);
            TimeSpan sumBreakTime   = new TimeSpan(0);

            for (int i = 0; i < timeBookingList.Count; i++)
            {
                switch (timeBookingList[i].TimeBookingType)
                {
                case TimeBookingType.Login:
                    login = timeBookingList[i].BookingTime;
                    break;

                case TimeBookingType.Logout:
                    logout = timeBookingList[i].BookingTime;
                    if (logout > login)
                    {
                        sumWorkingTime += logout.Subtract(login);
                    }
                    break;

                case TimeBookingType.StartBreak:
                    startBreak = timeBookingList[i].BookingTime;
                    break;

                case TimeBookingType.EndBreak:
                    endBreak = timeBookingList[i].BookingTime;
                    if (logout > login)
                    {
                        sumBreakTime += logout.Subtract(login);
                    }
                    break;
                }
            }

            TimeBookingDayItem timeBookingDayItem = CorrectWorkingTime(sumWorkingTime, sumBreakTime);

            timeBookingDayItem.BookingDate     = timeBookingList[0].BookingTime.Date;
            timeBookingDayItem.ObligatoryHours = timeObligatoryHour.HoursPerDay;

            var timeBalance = TimeBalances.GetByDateAndRefUserId(timeBookingList[0].BookingTime, timeBookingList[0].RefUserId);

            if (timeBalance != null)
            {
                timeBookingDayItem.Balance = timeBalance.Balance;
            }

            return(timeBookingDayItem);
        }
 public static int Insert(TimeObligatoryHour TimeObligatoryHour)
 {
     return(WebApi <int> .PostAsync(controllerName, TimeObligatoryHour, "SinglePost").Result);
 }