Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        public void SaveActualEmployeeTimeRange(long storeid, DateTime aBegin,
                                                DateTime aEnd, long[] employeeids, List <EmployeeTimeRange> lst)
        {
            #region validate date
            Debug.Assert(aBegin < aEnd);
            Debug.Assert(aBegin.DayOfWeek == DayOfWeek.Monday);
            Debug.Assert(aEnd.DayOfWeek == DayOfWeek.Sunday);

            if (aBegin >= 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 recording date in date({1}) with input data {2}-{3} storeid={4}",
                                           new object[] { username, DateTime.Today, aBegin, aEnd, storeid }));
                }
                return;
            }
            #endregion

            try
            {
                if (employeeids == null || employeeids.Length == 0)
                {
                    return;
                }

                if (lst != null)
                {
                    lst.Sort();
                }
                List <EmployeeTimeRange> lstWorks    = new List <EmployeeTimeRange>();
                List <EmployeeTimeRange> lstAbsences = new List <EmployeeTimeRange>();

                EmployeeTimeRangeHelper.GetWorkingAndAbsenceTimeRange(lst, lstWorks, lstAbsences);



                (WorkingTimeRecordingService as IServerEmployeeTimeRangeService).SaveEmployeeTimeRanges(employeeids, lstWorks, aBegin, aEnd);

                (AbsenceTimeRecordingService as IServerEmployeeTimeRangeService).SaveEmployeeTimeRanges(employeeids, lstAbsences, aBegin, aEnd);

                SrvRecordingStoreWeekCalculator calculator = new SrvRecordingStoreWeekCalculator(storeid, aBegin, aEnd, this);
                calculator.Process();

                _storeService.LastEmployeeWeekTimeRecordingUpdate(storeid, aBegin);

                ExEmployeeHolidays.CalculateAndUpdate(employeeids, DateTimeHelper.GetYearByDate(aBegin));
            }
            catch (EntityException)
            {
                throw;
            }
            catch (Exception ex)
            {
                CheckForDBValidationException(null, ex);
                throw new SaveException(ex);
            }
        }