public AbsencePlanningResponse SaveAbsencePlanning(AbsencePlanningResponse response) { // diction id of empluyees which absences or holidays number changed Dictionary <long, object> d_ids = new Dictionary <long, object>(); if (response.DeletedIds != null) { List <long> ids = new List <long>(response.DeletedIds); List <AbsenceTimePlanning> listAbsences = AbsenceTimePlanningService.FindByIDList(ids); if (listAbsences != null) { foreach (AbsenceTimePlanning a in listAbsences) { d_ids[a.EmployeeID] = a; } } AbsenceTimePlanningService.DeleteList(listAbsences);// DeleteListByID(ids); } if (response.ModifiedEntity != null) { List <EmployeeHolidaysInfo> lst = new List <EmployeeHolidaysInfo>(response.ModifiedEntity); EmployeeHolidaysInfoService.SaveOrUpdateList(lst); foreach (EmployeeHolidaysInfo o in lst) { d_ids[o.EmployeeID] = o; } } if (response.NewAbsences != null) { foreach (AbsenceTimeRange a in response.NewAbsences) { Debug.Assert(a.EmployeeID > 0); Debug.Assert(a.AbsenceID > 0); Debug.Assert(a.ID <= 0); d_ids[a.EmployeeID] = a; ClearEmployeePlanningTime(a.EmployeeID, a.Date, a.Date); AbsenceTimePlanning entity = new AbsenceTimePlanning(a.Begin, a.End, a.Time, a.AbsenceID, a.EmployeeID); entity.ID = 0; entity.Date = a.Date; AbsenceTimePlanningService.SaveOrUpdate(entity); a.ID = entity.ID; } } if (d_ids.Count > 0) { long[] ids = new long[d_ids.Count]; d_ids.Keys.CopyTo(ids, 0); ExEmployeeHolidays.CalculateAndUpdate(ids, response.Year); } return(response); }
public void SavePlanning2(long storeid, DateTime aBegin, DateTime aEnd, List <EmployeePlanningWeek> lstWeeks) { #region validate date Debug.Assert(aBegin < aEnd); Debug.Assert(aBegin.DayOfWeek == DayOfWeek.Monday); Debug.Assert(aEnd.DayOfWeek == DayOfWeek.Sunday); if (aEnd < DateTime.Today) { if (Log.IsWarnEnabled) { User user = ServerEnvironment.AuthorizationService.GetCurrentUser(); string username = String.Empty; if (user != null) { username = user.LoginName; } Log.Warn(string.Format("User - '{0}', try save planning date in date({1}) with input data {2}-{3} storeid={4}", new object[] { username, DateTime.Today, aBegin, aEnd, storeid })); } return; } #endregion try { HolidayCalculator calculatorHolidays = new HolidayCalculator(); calculatorHolidays.Calculate(storeid, aBegin, lstWeeks); WorkingTimePlanningService.SetWeekTimePlanning(lstWeeks); AbsenceTimePlanningService.SetWeekTimePlanning(lstWeeks); StoreWeekCalculater calculator = new StoreWeekCalculater(storeid, aBegin, aEnd, this); calculator.Process(); if (lstWeeks != null) { long[] ids = PlanningWeekProcessor.ListToEmployeeIds(lstWeeks); ExEmployeeHolidays.CalculateAndUpdate(ids, DateTimeHelper.GetYearByDate(aBegin)); } _storeService.LastEmployeeWeekTimePlanningUpdate(storeid, aBegin); } catch (EntityException) { throw; } catch (Exception ex) { CheckForDBValidationException(null, ex); throw new SaveException(ex); } }
public void ClearEmployeeTimeRange(long employeeId, DateTime aBegin, DateTime aEnd) { try { // week // day // working time // absence time // workingmodel EmployeePlanningWorkingModelService models = (EmployeePlanningWorkingModelService as EmployeePlanningWorkingModelService); models.ClearEmployeeByDateRange(employeeId, aBegin, aEnd); AbsenceTimePlanningService absences = (AbsenceTimePlanningService as AbsenceTimePlanningService); absences.ClearEmployeeByDateRange(employeeId, aBegin, aEnd); WorkingTimePlanningService times = (WorkingTimePlanningService as WorkingTimePlanningService); times.ClearEmployeeByDateRange(employeeId, aBegin, aEnd); EmployeeDayStatePlanningService daystate = (EmployeeDayStatePlanningService as EmployeeDayStatePlanningService); daystate.ClearEmployeeByDateRange(employeeId, aBegin, aEnd); EmployeeWeekTimePlanningService weekstate = (EmployeeWeekTimePlanningService as EmployeeWeekTimePlanningService); weekstate.ClearEmployeeByDateRange(employeeId, aBegin, aEnd); } catch (EntityException) { throw; } catch (Exception ex) { CheckForDBValidationException(null, ex); throw new SaveException(ex); } }