public ActionResult Create([Bind] Hre_ProfileModel model) { //var isAccess = CheckPermission(UserId, PrivilegeType.Create, ConstantPermission.GeneralProfile); //if (!isAccess) //{ // return PartialView("AccessDenied"); //} var service = new RestServiceClient <Hre_ProfileModel>(UserLogin); service.SetCookies(this.Request.Cookies, _hrm_Hr_Service); var result = service.Put(_hrm_Hr_Service, "api/Hre_Profile/", model); return(Json(result)); }
public Hre_ProfileModel Post([Bind] Hre_ProfileModel model) { string status = string.Empty; if (model != null) { ActionService service = new ActionService(UserLogin); BaseService BaseService = new BaseService(); if (!string.IsNullOrWhiteSpace(model.CodeAttendance)) { model.CodeAttendance = model.CodeAttendance.TrimAll(); } #region Validate string message = string.Empty; var checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Hre_ProfileModel>(model, "Hre_Profile", ref message); if (!checkValidate) { model.ActionStatus = message; return(model); } if (model.DateOfEffectOld != null) { checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Hre_ProfileModel>(model, "Hre_ProfileCheckDateOfEffect", ref message); if (!checkValidate) { model.ActionStatus = message; return(model); } } #endregion #region Xử lý cập nhật AbilityTitle khi chọn rank if (model.SalaryClassID != null) { var abilityTitleBySalaryClass = BaseService.GetData <Cat_AbilityTileEntity>(Common.DotNetToOracle(model.SalaryClassID.ToString()), ConstantSql.hrm_cat_sp_get_AbilityTileBySalaryClassId, UserLogin, ref status).FirstOrDefault(); if (abilityTitleBySalaryClass != null) { model.AbilityTileID = abilityTitleBySalaryClass.ID; } } #endregion #region Xử Lý Lưu field DateOfBirth var dateOfBirth = string.Empty; if (model.DayOfBirth == 00 && model.MonthOfBirth == 00) { model.ActionStatus = "ErrorDateOfBirth"; return(model); } if (model.DayOfBirth == null && model.MonthOfBirth == null && model.YearOfBirth == null) { dateOfBirth = string.Empty; } else { if (model.DayOfBirth == null) { model.DayOfBirth = DateTime.Now.Day; } if (model.MonthOfBirth == null) { model.MonthOfBirth = DateTime.Now.Month; } if (model.YearOfBirth == null) { model.ActionStatus = "ErrorDateOfBirth"; return(model); } } if (model.DayOfBirth >= 0 || model.MonthOfBirth >= 0 || model.YearOfBirth >= 0) { if (model.DayOfBirth == 30 && model.MonthOfBirth == 2) { model.ActionStatus = "ErrorDateOfBirth"; return(model); } if (model.DayOfBirth == 31 && model.MonthOfBirth == 2) { model.ActionStatus = "ErrorDateOfBirth"; return(model); } if (model.DayOfBirth > 31 || model.MonthOfBirth > 12) { model.ActionStatus = "ErrorDateOfBirth"; return(model); } dateOfBirth = model.MonthOfBirth + "/" + model.DayOfBirth + "/" + model.YearOfBirth; } model.DateOfBirth = string.IsNullOrEmpty(dateOfBirth) ? (DateTime?)null : DateTime.Parse(dateOfBirth); #endregion Hre_ProfileModel HreProfile = new Hre_ProfileModel(); if (model.ID != Guid.Empty) { HreProfile = GetById(model.ID); } if (HreProfile != null && (model.ID == HreProfile.ID) && model.ActionStatus != "1") { string[] listFieldName = new[] { "JobTitleID", "PositionID", "EmpTypeID", "DateOfEffect", "CostCentreID", "OrgStructureID", "WorkPlaceID", "SupervisorID" }; foreach (var item in listFieldName) { var value1 = model.GetPropertyValue(item); var value2 = HreProfile.GetPropertyValue(item); if ((value1 != null && value2 != null) && (value1.ToString() != value2.ToString())) { model.SetPropertyValue(Constant.ActionStatus, NotificationType.Change.ToString()); return(model); } } if (HreProfile.ProfileName != model.ProfileName) { if (model.ProfileName.Contains(' ')) { model.FirstName = model.ProfileName.Substring(model.ProfileName.LastIndexOf(' ') + 1); model.NameFamily = model.ProfileName.Substring(0, model.ProfileName.LastIndexOf(' ')); } else { model.FirstName = model.ProfileName; } } } if (model.ActionStatus == "1" || model.ActionStatus == "Success" || string.IsNullOrEmpty(model.ActionStatus)) { var serviceAddress = new Hre_AddressServices(); var serviceProfile = new Hre_ProfileServices(); var profileEntity = new Hre_ProfileEntity(); if (model.ID != Guid.Empty) { profileEntity = serviceProfile.GetData <Hre_ProfileEntity>(Common.DotNetToOracle(model.ID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref status).FirstOrDefault(); } #region Xử lý lưu CardCode Hre_CardHistoryServices cardservices = new Hre_CardHistoryServices(); Hre_WorkHistoryServices workHistoryservices = new Hre_WorkHistoryServices(); if (profileEntity != null && model.CodeAttendance != null && model.DateApplyAttendanceCode != null && (model.CodeAttendance != profileEntity.CodeAttendance || model.DateApplyAttendanceCode != profileEntity.DateApplyAttendanceCode)) { // Chỉ thay đổi mã chấm công if (model.DateApplyAttendanceCode == profileEntity.DateApplyAttendanceCode && model.CodeAttendance != profileEntity.CodeAttendance) { Hre_CardHistoryEntity history = cardservices.GetData <Hre_CardHistoryEntity>(Common.DotNetToOracle(model.ID.ToString()), ConstantSql.hrm_hr_sp_get_CardHistoryByProfileId, UserLogin, ref status).OrderByDescending(s => s.DateEffect).FirstOrDefault(); if (history != null) { history.CardCode = model.CodeAttendance; cardservices.Edit(history); } else { history = new Hre_CardHistoryEntity(); history.ProfileID = model.ID; history.CardCode = model.CodeAttendance; history.DateEffect = model.DateApplyAttendanceCode; cardservices.Add(history); } } // Chỉ thay đổi Ngày áp dụng mã chấm công else if (model.CodeAttendance == profileEntity.CodeAttendance && model.DateApplyAttendanceCode != profileEntity.DateApplyAttendanceCode) { if (model.DateApplyAttendanceCode < profileEntity.DateApplyAttendanceCode) { model.StatusVerify = "Invalid"; return(model); } Hre_CardHistoryEntity history = cardservices.GetData <Hre_CardHistoryEntity>(Common.DotNetToOracle(model.ID.ToString()), ConstantSql.hrm_hr_sp_get_CardHistoryByProfileId, UserLogin, ref status).OrderByDescending(s => s.DateEffect).FirstOrDefault(); if (history != null) { history.DateEffect = model.DateApplyAttendanceCode; cardservices.Edit(history); } else { history = new Hre_CardHistoryEntity(); history.ProfileID = model.ID; history.CardCode = model.CodeAttendance; history.DateEffect = model.DateApplyAttendanceCode; cardservices.Add(history); } } } // Tạo mới NV hoặc thay đổi cả 2( mã chấm công + ngày hiệu lực) Hre_CardHistoryEntity cardhistory = null; if (model != null && model.ID == Guid.Empty || (model != null && profileEntity != null && model.CodeAttendance != profileEntity.CodeAttendance && model.DateApplyAttendanceCode != profileEntity.DateApplyAttendanceCode)) { cardhistory = new Hre_CardHistoryEntity(); cardhistory.ProfileID = model.ID; cardhistory.CardCode = model.CodeAttendance; cardhistory.DateEffect = model.DateApplyAttendanceCode; } #endregion #region Xử lý lưu quá trình công tác Hre_WorkHistoryEntity workHistory = null; if (model != null && (model.JobTitleID != profileEntity.JobTitleID || model.PositionID != profileEntity.PositionID || model.EmpTypeID != profileEntity.EmpTypeID || (model.DateOfEffect != null && profileEntity.DateOfEffect != null && model.DateOfEffect.Value.ToString() != profileEntity.DateOfEffect.Value.ToString()) || model.CostCentreID != profileEntity.CostCentreID || model.SupervisorID != profileEntity.SupervisorID || model.OrgStructureID != profileEntity.OrgStructureID || model.WorkPlaceID != profileEntity.WorkPlaceID)) { workHistory = new Hre_WorkHistoryEntity(); var orgService = new Cat_OrgStructureServices(); var jobtitleService = new Cat_JobTitleServices(); var postitionService = new Cat_PositionServices(); var workPlaceService = new Cat_WorkPlaceServices(); workHistory.CostCentreID = model.CostCentreID; workHistory.OrganizationStructureID = model.OrgStructureID; workHistory.PositionID = model.PositionID; workHistory.JobTitleID = model.JobTitleID; workHistory.SalaryClassID = model.SalaryClassID; workHistory.CostSourceID = model.CostSourceID; workHistory.AbilityTileID = model.AbilityTileID; if (profileEntity != null) { var orgStructureOld = new Cat_OrgStructureEntity(); if (profileEntity.OrgStructureID != null && profileEntity.OrgStructureID != Guid.Empty) { orgStructureOld = orgService.GetData <Cat_OrgStructureEntity>(profileEntity.OrgStructureID, ConstantSql.hrm_cat_sp_get_OrgStructureById, UserLogin, ref status).FirstOrDefault(); } var jobtitleOld = new Cat_JobTitleEntity(); if (profileEntity.JobTitleID != null && profileEntity.JobTitleID != Guid.Empty) { jobtitleOld = jobtitleService.GetData <Cat_JobTitleEntity>(profileEntity.JobTitleID, ConstantSql.hrm_cat_sp_get_HDTJobTypeById, UserLogin, ref status).FirstOrDefault(); } var postitionOld = new Cat_PositionEntity(); if (profileEntity.PositionID != null && profileEntity.PositionID != Guid.Empty) { postitionOld = postitionService.GetData <Cat_PositionEntity>(profileEntity.PositionID, ConstantSql.hrm_cat_sp_get_PositionById, UserLogin, ref status).FirstOrDefault(); } var workPlace = new Cat_WorkPlaceEntity(); if (model.WorkPlaceID != null && model.WorkPlaceID != Guid.Empty) { workPlace = workPlaceService.GetData <Cat_WorkPlaceEntity>(model.WorkPlaceID, ConstantSql.hrm_cat_sp_get_WorkPlaceById, UserLogin, ref status).FirstOrDefault(); } var workPlaceOld = new Cat_WorkPlaceEntity(); if (profileEntity.WorkPlaceID != null && profileEntity.WorkPlaceID != Guid.Empty) { workPlaceOld = workPlaceService.GetData <Cat_WorkPlaceEntity>(profileEntity.WorkPlaceID, ConstantSql.hrm_cat_sp_get_WorkPlaceById, UserLogin, ref status).FirstOrDefault(); } workHistory.OrgOld = orgStructureOld != null ? orgStructureOld.OrgStructureName : ""; workHistory.JobTitleOld = jobtitleOld != null ? jobtitleOld.JobTitleName : ""; workHistory.PositionOld = postitionOld != null ? postitionOld.PositionName : ""; workHistory.WorkLocation = workPlace != null ? workPlace.WorkPlaceName : ""; workHistory.WorkLocationOld = workPlaceOld != null ? workPlaceOld.WorkPlaceName : ""; } if (workHistory.ID == Guid.Empty) { if (model.DateOfEffect != null) { workHistory.DateEffective = model.DateOfEffect.Value; } else { workHistory.DateEffective = DateTime.Now; } } if (model.DateQuit != null && (profileEntity == null || profileEntity.DateQuit != model.DateQuit)) { workHistory.DateEffective = model.DateQuit.Value; } } #region Ngày hiệu lực phải <= ngày hiện tại thì mới cập nhật lại quá trình công tác if (model.DateOfEffect > DateTime.Now && profileEntity != null && profileEntity.DateOfEffect != null) { model.DateOfEffect = profileEntity.DateOfEffect; model.OrgStructureID = profileEntity.OrgStructureID; model.ShopID = profileEntity.ShopID; model.JobTitleID = profileEntity.JobTitleID; model.PositionID = profileEntity.PositionID; model.SupervisorID = profileEntity.SupervisorID; model.HighSupervisorID = profileEntity.HighSupervisorID; model.IsHeadDept = profileEntity.IsHeadDept; model.EmpTypeID = profileEntity.EmpTypeID; model.LaborType = profileEntity.LaborType; model.SikillLevel = profileEntity.SikillLevel; model.PayrollGroupID = profileEntity.PayrollGroupID; model.SalaryClassID = profileEntity.SalaryClassID; model.CostCentreID = profileEntity.CostCentreID; model.LocationCode = profileEntity.LocationCode; model.WorkPlaceID = profileEntity.WorkPlaceID; } #endregion #endregion var profileModel = service.UpdateOrCreate <Hre_ProfileEntity, Hre_ProfileModel>(model); if (cardhistory != null && profileModel != null) { cardhistory.ProfileID = profileModel.ID; cardservices.Add(cardhistory); } if (workHistory != null && profileModel != null) { workHistory.EmployeeTypeID = profileModel.EmpTypeID; workHistory.ProfileID = profileModel.ID; workHistoryservices.Add(workHistory); } } } //Xóa cache lưu lại của cây phòng ban HttpContext.Current.Cache.Remove("List_OrgStructureTreeView"); HttpContext.Current.Cache.Remove("List_OrgStructureTreeViewSumProfile"); return(model); }
public JsonResult CreateContactInfo(Hre_ProfileModel model, string userLogin) { var id = Session[SessionObjects.ProfileID]; var serv = new Hre_ProfileServices(); string status = string.Empty; var profile = serv.GetData <Hre_ProfileModel>(HRM.Infrastructure.Utilities.Common.DotNetToOracle(id.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, userLogin, ref status).FirstOrDefault(); bool change = false; #region check change if (profile.Email != model.Email) { change = true; } if (profile.Email2 != model.Email2) { change = true; } if (profile.Cellphone != model.Cellphone) { change = true; } if (profile.HomePhone != model.HomePhone) { change = true; } if (profile.TCountryID != model.TCountryID) { change = true; } if (profile.TDistrictID != model.TDistrictID) { change = true; } if (profile.TProvinceID != model.TProvinceID) { change = true; } if (profile.TAVillageID != model.TAVillageID) { change = true; } if (profile.TAddress != model.TAddress) { change = true; } if (profile.PCountryID != model.PCountryID) { change = true; } if (profile.PDistrictID != model.PDistrictID) { change = true; } if (profile.PProvinceID != model.PProvinceID) { change = true; } if (profile.VillageID != model.VillageID) { change = true; } if (profile.PAddress != model.PAddress) { change = true; } if (profile.AddressEmergency != model.AddressEmergency) { change = true; } #endregion if (!change) { profile.ActionStatus = "Success"; return(Json(profile)); } if (profile.ID == model.ID) { profile.ActionStatus = model.ActionStatus; profile.Email = model.Email; profile.Email2 = model.Email2; profile.Cellphone = model.Cellphone; profile.HomePhone = model.HomePhone; profile.TCountryID = model.TCountryID; profile.TDistrictID = model.TDistrictID; profile.TProvinceID = model.TProvinceID; profile.TAVillageID = model.TAVillageID; profile.TAddress = model.TAddress; profile.PCountryID = model.PCountryID; profile.PDistrictID = model.PDistrictID; profile.PProvinceID = model.PProvinceID; profile.VillageID = model.VillageID; profile.PAddress = model.PAddress; profile.AddressEmergency = model.AddressEmergency; } var service = new RestServiceClient <Hre_ProfileModel>(UserLogin); service.SetCookies(this.Request.Cookies, _Hrm_Hre_Service); var result = service.Post(_Hrm_Hre_Service, "api/Hre_Profile/", profile); return(Json(result)); }
public JsonResult CreatePersonalInfo(Hre_ProfileModel model, string userLogin) { var id = Session[SessionObjects.ProfileID]; var serv = new Hre_ProfileServices(); string status = string.Empty; var profile = serv.GetData <Hre_ProfileModel>(HRM.Infrastructure.Utilities.Common.DotNetToOracle(id.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, userLogin, ref status).FirstOrDefault(); bool change = false; #region check change if (profile.NameEnglish != model.NameEnglish) { change = true; } if (profile.Gender != model.Gender) { change = true; } if (profile.DayOfBirth != model.DayOfBirth) { change = true; } if (profile.MonthOfBirth != model.MonthOfBirth) { change = true; } if (profile.YearOfBirth != model.YearOfBirth) { change = true; } if (profile.NationalityID != model.NationalityID) { change = true; } if (profile.PlaceOfBirth != model.PlaceOfBirth) { change = true; } if (profile.MarriageStatus != model.MarriageStatus) { change = true; } if (profile.IDNo != model.IDNo) { change = true; } if (profile.IDDateOfIssue != model.IDDateOfIssue) { change = true; } if (profile.IDPlaceOfIssue != model.IDPlaceOfIssue) { change = true; } if (profile.Origin != model.Origin) { change = true; } //if (profile.TypeOfVehicle != model.TypeOfVehicle) // change = true; //if (profile.LockerName != model.LockerName) // change = true; if (profile.EducationLevelID != model.EducationLevelID) { change = true; } if (profile.EthnicID != model.EthnicID) { change = true; } if (profile.Notes != model.Notes) { change = true; } if (profile.BloodType != model.BloodType) { change = true; } if (profile.Height != model.Height) { change = true; } if (profile.Weight != model.Weight) { change = true; } if (profile.PassportNo != model.PassportNo) { change = true; } if (profile.PassportPlaceOfIssue != model.PassportPlaceOfIssue) { change = true; } if (profile.PassportDateOfIssue != model.PassportDateOfIssue) { change = true; } if (profile.PassportDateOfExpiry != model.PassportDateOfExpiry) { change = true; } #endregion if (!change) { profile.ActionStatus = "Success"; return(Json(profile)); } if (profile.ID == model.ID) { profile.ActionStatus = model.ActionStatus; profile.NameEnglish = model.NameEnglish; profile.Gender = model.Gender; profile.DayOfBirth = model.DayOfBirth; profile.MonthOfBirth = model.MonthOfBirth; profile.YearOfBirth = model.YearOfBirth; profile.NationalityID = model.NationalityID; profile.PlaceOfBirth = model.PlaceOfBirth; profile.MarriageStatus = model.MarriageStatus; profile.IDNo = model.IDNo; profile.IDDateOfIssue = model.IDDateOfIssue; profile.IDPlaceOfIssue = model.IDPlaceOfIssue; profile.Origin = model.Origin; profile.EducationLevelID = model.EducationLevelID; profile.EthnicID = model.EthnicID; profile.Notes = model.Notes; profile.BloodType = model.BloodType; profile.Height = model.Height; profile.Weight = model.Weight; profile.PassportNo = model.PassportNo; profile.PassportPlaceOfIssue = model.PassportPlaceOfIssue; profile.PassportDateOfIssue = model.PassportDateOfIssue; profile.PassportDateOfExpiry = model.PassportDateOfExpiry; } var service = new RestServiceClient <Hre_ProfileModel>(UserLogin); service.SetCookies(this.Request.Cookies, _Hrm_Hre_Service); var result = service.Post(_Hrm_Hre_Service, "api/Hre_Profile/", profile); return(Json(result)); }
public JsonResult CreateBasicInfo(Hre_ProfileModel model, string userLogin) { var id = Session[SessionObjects.ProfileID]; var serv = new Hre_ProfileServices(); string status = string.Empty; var profile = serv.GetData <Hre_ProfileModel>(HRM.Infrastructure.Utilities.Common.DotNetToOracle(id.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, userLogin, ref status).FirstOrDefault(); bool change = false; #region check change if (profile.ProfileName != model.ProfileName) { change = true; } if (profile.CodeAttendance != model.CodeAttendance) { change = true; } if (profile.CodeEmp != model.CodeEmp) { change = true; } if (profile.DateApplyAttendanceCode != model.DateApplyAttendanceCode) { change = true; } if (profile.WorkPlaceName != model.WorkPlaceName) { change = true; } if (profile.CodeTax != model.CodeTax) { change = true; } if (profile.DateOfIssuedTaxCode != model.DateOfIssuedTaxCode) { change = true; } if (profile.DateHire != model.DateHire) { change = true; } if (profile.DateEndProbation != model.DateEndProbation) { change = true; } if (profile.JobTitleID != model.JobTitleID) { change = true; } if (profile.PositionID != model.PositionID) { change = true; } if (profile.EmpTypeID != model.EmpTypeID) { change = true; } if (profile.PayrollGroupID != model.PayrollGroupID) { change = true; } if (profile.JobTitleID != model.JobTitleID) { change = true; } if (profile.PositionID != model.PositionID) { change = true; } if (profile.EmpTypeID != model.EmpTypeID) { change = true; } if (profile.PayrollGroupID != model.PayrollGroupID) { change = true; } if (profile.DateOfEffect != model.DateOfEffect) { change = true; } if (profile.LaborType != model.LaborType) { change = true; } if (profile.WorkPlaceID != model.WorkPlaceID) { change = true; } if (profile.SupervisorID != model.SupervisorID) { change = true; } if (profile.HighSupervisorID != model.HighSupervisorID) { change = true; } #endregion if (!change) { profile.ActionStatus = "Success"; return(Json(profile)); } if (profile.ID == model.ID) { profile.ActionStatus = model.ActionStatus; profile.ProfileName = model.ProfileName; profile.CodeAttendance = model.CodeAttendance; profile.CodeEmp = model.CodeEmp; profile.DateApplyAttendanceCode = model.DateApplyAttendanceCode; profile.LocationCode = model.LocationCode; profile.WorkPlaceName = model.WorkPlaceName; profile.CodeTax = model.CodeTax; profile.DateOfIssuedTaxCode = model.DateOfIssuedTaxCode; profile.DateHire = model.DateHire; //profile.PromotionCondition = model.PromotionCondition; profile.DateEndProbation = model.DateEndProbation; profile.JobTitleID = model.JobTitleID; profile.PositionID = model.PositionID; profile.EmpTypeID = model.EmpTypeID; profile.PayrollGroupID = model.PayrollGroupID; profile.DateOfEffect = model.DateOfEffect; profile.LaborType = model.LaborType; profile.WorkPlaceID = model.WorkPlaceID; profile.SupervisorID = model.SupervisorID; profile.HighSupervisorID = model.HighSupervisorID; } var service = new RestServiceClient <Hre_ProfileModel>(UserLogin); service.SetCookies(this.Request.Cookies, _Hrm_Hre_Service); var result = service.Post(_Hrm_Hre_Service, "api/Hre_Profile/", profile); return(Json(result)); }