public void NUnit_CardHistory_Domain_Add() { Att_RosterServices service = new Att_RosterServices(); string result = string.Empty; int countSC = 0; for (int i = 1; i <= 10; i++) { var model = new Att_Roster { ProfileID = 1, Comment = "Comment " + i }; result = service.Add(model); if (result != string.Empty) { countSC += 1; Console.WriteLine("Process Success >>> Create >>> " + model.Id + " | " + model.Comment ); } } Console.WriteLine("Total success record: " + countSC); }
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)); }