Пример #1
0
        /// <summary>
        /// Tìm ca làm việc trong Roster
        /// </summary>
        /// <param name="roster"></param>
        /// <param name="workday"></param>
        /// <returns></returns>
        private Guid?SearchShift(Att_RosterEntity roster, DateTime workday)
        {
            if (roster != null)
            {
                //Lấy ra thứ của WorkDate và tìm ca của thứ tương ứng
                switch (workday.DayOfWeek)
                {
                case DayOfWeek.Monday:
                    return(roster.MonShiftID);

                case DayOfWeek.Tuesday:
                    return(roster.TueShiftID);

                case DayOfWeek.Wednesday:
                    return(roster.WedShiftID);

                case DayOfWeek.Thursday:
                    return(roster.ThuShiftID);

                case DayOfWeek.Friday:
                    return(roster.FriShiftID);

                case DayOfWeek.Saturday:
                    return(roster.SatShiftID);

                case DayOfWeek.Sunday:
                    return(roster.SunShiftID);
                }
            }

            return(null);
        }
Пример #2
0
        public Att_RosterModel Post([Bind] Att_RosterModel model)
        {
            ActionService service               = new ActionService(UserLogin);
            var           baseService           = new BaseService();
            string        status                = string.Empty;
            var           hrService             = new Hre_ProfileServices();
            string        strMessages           = string.Empty;
            var           rosterService         = new Att_RosterServices();
            var           sysAllSetttingService = new Sys_AllSettingServices();

            #region Validate
            string message       = string.Empty;
            var    checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Att_RosterModel>(model, "Att_Roster", ref message);
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return(model);
            }
            checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Att_RosterModel>(model, "Att_ProfileNotRoster", ref message);
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return(model);
            }
            if (string.IsNullOrEmpty(model.OrgStructureIDs) && string.IsNullOrEmpty(model.ProfileIds) && model.ProfileID == Guid.Empty)
            {
                message            = string.Format(ConstantMessages.FieldNotAllowNull.TranslateString(), ("ProfileID").TranslateString());
                model.ActionStatus = message;
                return(model);
            }
            #endregion

            List <Guid> lstProfileIDs = new List <Guid>();

            if (!string.IsNullOrEmpty(model.OrgStructureIDs))
            {
                List <object> listObj = new List <object>();
                listObj.Add(model.OrgStructureIDs);
                listObj.Add(string.Empty);
                listObj.Add(string.Empty);
                var lstProfile = hrService.GetData <Hre_ProfileEntity>(listObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrgStructure, UserLogin, ref status).Select(s => s.ID).ToList();
                lstProfileIDs.AddRange(lstProfile);
            }
            else if (model.ProfileIds != null && model.ProfileIds != "")
            {
                var listGuid = model.ProfileIds.Split(',').Select(s => Guid.Parse(s)).ToArray();
                lstProfileIDs.AddRange(listGuid);
            }
            var lstRosterEntity_Validate = new List <Att_RosterEntity>();
            foreach (var item in lstProfileIDs)
            {
                Att_RosterEntity rosterEntity = model.CopyData <Att_RosterEntity>();
                rosterEntity.ProfileID = item;
                if (rosterEntity.ID != null && rosterEntity.ID != Guid.Empty)
                {
                }
                else
                {
                    rosterEntity.ID = Guid.NewGuid();
                }
                lstRosterEntity_Validate.Add(rosterEntity);
            }
            var key = AppConfig.HRM_ATT_ALLOWSAVEDUPLICATE.ToString();
            var lstSysAllSetting = sysAllSetttingService.GetData <Sys_AllSettingEntity>(key, ConstantSql.hrm_sys_sp_get_AllSettingByKey, UserLogin, ref status).FirstOrDefault();


            var ValidateLess12Hour = AppConfig.HRM_ATT_VALIDATE_ROSTER_NON_CONTINUE_12HOUR.ToString();
            var lstSysSetting_ValidateLess12Hour = sysAllSetttingService.GetData <Sys_AllSettingEntity>(ValidateLess12Hour, ConstantSql.hrm_sys_sp_get_AllSettingByKey, UserLogin, ref status).FirstOrDefault();
            if (lstSysSetting_ValidateLess12Hour != null && lstSysSetting_ValidateLess12Hour.Value1 == bool.TrueString)
            {
                string Err = string.Empty;
                Err = rosterService.ValidateShiftHourContinue(lstRosterEntity_Validate);
                if (Err != string.Empty)
                {
                    model.SetPropertyValue(Constant.ActionStatus, NotificationType.Error + "," + Err);
                    return(model);
                }
            }

            if (!string.IsNullOrEmpty(model.OrgStructureIDs))
            {
                List <object> listObj = new List <object>();
                listObj.Add(model.OrgStructureIDs);
                listObj.Add(string.Empty);
                listObj.Add(string.Empty);
                var lstProfile = hrService.GetData <Hre_ProfileEntity>(listObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrgStructure, UserLogin, ref status).Select(s => s.ID).ToList();
                if (lstProfile.Count == 0 || lstProfile == null)
                {
                    model.SetPropertyValue(Constant.ActionStatus, NotificationType.Info + "," + strMessages + ConstantMessages.FieldDuplicate);
                    return(model);
                }
                if (lstProfile != null && model.ProfileIds != null)
                {
                    Guid[] listGuid = null;
                    listGuid   = model.ProfileIds.Split(',').Select(s => Guid.Parse(s)).ToArray();
                    lstProfile = lstProfile.Where(s => !listGuid.Contains(s)).ToList();
                }
                List <Att_RosterEntity> lstRosterEntity = new List <Att_RosterEntity>();
                List <object>           paraRoster      = new List <object>();
                paraRoster.AddRange(new object[4]);
                paraRoster[0] = (object)model.OrgStructureIDs;
                paraRoster[1] = null;
                paraRoster[2] = null;
                paraRoster[3] = null;
                var listRosterData = rosterService.GetData <Att_RosterEntity>(paraRoster, ConstantSql.hrm_att_getdata_Roster, UserLogin, ref status);
                foreach (var item in lstProfile)
                {
                    Att_RosterModel modelSave  = model.CopyData <Att_RosterModel>();
                    var             listRoster = listRosterData.Where(s => s.ProfileID == item);
                    if (modelSave.Type != RosterType.E_CHANGE_SHIFT.ToString() &&
                        modelSave.Type != RosterType.E_TIME_OFF.ToString() &&
                        listRoster != null &&
                        listRoster.Any(d => d.DateStart <= model.DateEnd && d.DateEnd >= model.DateStart))
                    {
                        strMessages += listRoster.FirstOrDefault().ProfileName + ", ";
                        continue;
                    }
                    modelSave.ProfileID = item;
                    Att_RosterEntity rosterEntity = modelSave.CopyData <Att_RosterEntity>();
                    lstRosterEntity.Add(rosterEntity);
                }
                if (strMessages == "" && lstRosterEntity.Count > 0)
                {
                    model.ActionStatus = rosterService.Add(lstRosterEntity);
                }
                else
                {
                    if (lstSysAllSetting != null && lstSysAllSetting.Value1 == bool.TrueString && lstRosterEntity.Count > 0)
                    {
                        model.ActionStatus = rosterService.Add(lstRosterEntity);
                    }
                    else if (lstSysAllSetting.Value1 == bool.FalseString)
                    {
                        model.SetPropertyValue(Constant.ActionStatus, NotificationType.Error + "," + strMessages + ConstantMessages.FieldDuplicate);
                        return(model);
                    }
                    else if (lstRosterEntity.Count == 0)
                    {
                        model.SetPropertyValue(Constant.ActionStatus, NotificationType.Info + "," + strMessages + ConstantMessages.FieldDuplicate);
                        return(model);
                    }
                }
                return(model);
            }
            //Xử lý khi chọn nhiều nhân viên
            if (model.ProfileIds != null && model.ProfileIds.IndexOf(',') > 0 && model.OrgStructureIDs == null)
            {
                Guid[] listGuid = null;
                listGuid = model.ProfileIds.Split(',').Select(s => Guid.Parse(s)).ToArray();
                List <Att_RosterEntity> lstRosterEntity = new List <Att_RosterEntity>();
                foreach (var item in listGuid)
                {
                    Att_RosterModel modelSave  = model.CopyData <Att_RosterModel>();
                    var             listRoster = service.GetData <Att_RosterEntity>(item, ConstantSql.hrm_att_sp_get_RosterByProfileId, ref status);
                    if (modelSave.Type != RosterType.E_CHANGE_SHIFT.ToString() &&
                        modelSave.Type != RosterType.E_TIME_OFF.ToString() &&
                        listRoster != null &&
                        listRoster.Any(d => d.DateStart <= model.DateEnd && d.DateEnd >= model.DateStart))
                    {
                        strMessages += listRoster.FirstOrDefault().ProfileName + ", ";
                        continue;
                    }
                    modelSave.ProfileID = item;
                    Att_RosterEntity rosterEntity = modelSave.CopyData <Att_RosterEntity>();
                    lstRosterEntity.Add(rosterEntity);
                }
                if (strMessages == "")
                {
                    model.ActionStatus = rosterService.Add(lstRosterEntity);
                }
                else
                {
                    if (lstSysAllSetting != null && lstSysAllSetting.Value1 == bool.TrueString)
                    {
                        model.ActionStatus = rosterService.Add(lstRosterEntity);
                    }
                    else
                    {
                        model.SetPropertyValue(Constant.ActionStatus, NotificationType.Error + "," + strMessages + ConstantMessages.FieldDuplicate);
                        return(model);
                    }
                }
                return(model);
            }
            //Xử lý khi chỉ chọn 1 nhân viên
            if (model.ID == Guid.Empty)
            {
                var lstRoster = service.GetData <Att_RosterEntity>(model.ProfileID, ConstantSql.hrm_att_sp_get_RosterByProfileId, ref status);
                if (model.Type != RosterType.E_CHANGE_SHIFT.ToString() &&
                    model.Type != RosterType.E_TIME_OFF.ToString() &&
                    lstRoster != null &&
                    lstRoster.Any(d => d.DateStart <= model.DateEnd && d.DateEnd >= model.DateStart))
                {
                    strMessages = lstRoster.FirstOrDefault().ProfileName + ",";
                    model.SetPropertyValue(Constant.ActionStatus, NotificationType.Error + "," + strMessages + ConstantMessages.FieldDuplicate);
                    return(model);
                }
                return(service.UpdateOrCreate <Att_RosterEntity, Att_RosterModel>(model));
            }
            return(service.UpdateOrCreate <Att_RosterEntity, Att_RosterModel>(model));
        }