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); } } } }
public static bool Update(TimeBalance TimeBalance) { return(WebApi <bool> .PutAsync(controllerName, TimeBalance, "Put").Result); }
public static int Insert(TimeBalance TimeBalance) { return(WebApi <int> .PostAsync(controllerName, TimeBalance, "SinglePost").Result); }