Exemplo n.º 1
0
        //public IQueryable<Sys_User> GetEmployees()
        //{
        //    var unitOfWork = (IUnitOfWork)(new UnitOfWork(new VnrHrmDataContext()));
        //    var repo = new Sys_UserRepository(unitOfWork);
        //    return repo.GetAllUsers();

        //}

        public bool EditEmployees(Sys_UserInfoEntity userInfo)
        {
            var unitOfWork = (IUnitOfWork)(new UnitOfWork(new VnrHrmDataContext()));
            var repo = new Sys_UserRepository(unitOfWork);
            try
            {
                Sys_UserInfo userRoot = new Sys_UserInfo();
                userRoot = userInfo.CopyData<Sys_UserInfo>();
                repo.Edit(userRoot);
                repo.SaveChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Lưu dữ liệu xuống database, với tham số đầu vào là Model tương ứng
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public EmployeeModel Put(EmployeeModel model)
 {
     //Chuyển model thành Model tương dứng dưới database
     var modelEmp = new Sys_UserInfoEntity()
     {
         UserLogin = model.LoginName,
         Code = model.Code,
         IsCheckLDAP = true,
         LDAPDatasource="1"
     };
     var service = new EmployeeServices();
     if (model.ID!= Guid.Empty)
     {
         modelEmp.ID = model.ID;
         service.EditEmployees(modelEmp);
     }
     else
     {
        service.Add<Sys_UserInfoEntity>(modelEmp);
     }
     return model;
 }
Exemplo n.º 3
0
        public JsonResult GetEmployeesId(Guid id)
        {
            EmployeeServices service = new EmployeeServices();
            var emp = service.GetById<Sys_UserInfoEntity>(id, ref status);
            var emp1 = new Sys_UserInfoEntity()
            {
                ID = emp.ID,
                UserLogin = emp.UserLogin,
                UserInfoName = emp.UserInfoName
            };
            return Json(emp1);

            #region code cũ
            //EmployeeServices service = new EmployeeServices();
            //var emp = service.GetEmployeesById(id);
            //var emp1 = new Data.HrmSystem.Model.Sys_User()
            //{
            //    Id = emp.Id,
            //    UserLogin = emp.UserLogin,
            //    UserName = emp.UserName
            //};
            //return Json(emp1); 
            #endregion
        }
Exemplo n.º 4
0
        public Sys_UserInfoEntity Login(string userName, string password, string googleEmail, string googleProfileName, bool isSignIn)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo = new Sys_UserRepository(unitOfWork);
                var userInfoEntity = new Sys_UserInfoEntity();
                var status = string.Empty;

                if (isSignIn)
                {
                    //neu signIn bằng google mail => kt email co tồn tại trong hệ thống VNR không, nếu không thì tạo mới user
                    userInfoEntity = CheckEmailExisted(googleEmail, googleProfileName);
                }
                else
                {
                    //login he thong VNR
                    userInfoEntity = repo.Login(userName, password);
                }

                #region Kiem tra có dự Án không?

                if (userInfoEntity != null)
                {
             
                    
                    var vesionLastName = unitOfWork.CreateQueryable<Sys_Version>(s => s.IsDelete == null).OrderByDescending(s => s.DateCreate).Select(s => s.Value).FirstOrDefault();
                    var vesionLastNameFile = GetVesionLastNameFile();
                    if (!string.IsNullOrEmpty(vesionLastNameFile) && vesionLastName != vesionLastNameFile)
                    {
                        userInfoEntity.IsRunScriptNew = true;
                        userInfoEntity.VesionLastName = vesionLastName;
                    }
                    var masterDataGroups = unitOfWork.CreateQueryable<Sys_UserMasterData>(d =>
                        d.UserID == userInfoEntity.ID).Select(d => d.MasterDataGroups).ToList();

                    if (masterDataGroups.Any(d => d != null && d.ToNumbers().Count() > 0))
                    {
                        userInfoEntity.HasMasterDataGroup = true;
                    }
                }
                else
                {
                    userInfoEntity = new Sys_UserInfoEntity();
                    userInfoEntity.UserLogin = userName;
                    userInfoEntity.Password = password;
                    var vesionLastName = unitOfWork.CreateQueryable<Sys_Version>(s => s.IsDelete == null).OrderByDescending(s => s.DateCreate).Select(s => s.Value).FirstOrDefault();
                    var vesionLastNameFile = GetVesionLastNameFile();
                    if (!string.IsNullOrEmpty(vesionLastNameFile) && vesionLastName != vesionLastNameFile)
                    {
                        userInfoEntity.IsRunScriptNew = true;
                        userInfoEntity.VesionLastName = vesionLastName;
                    }
                    else
                    {
                        return null;
                    }
                }

                #endregion


                return userInfoEntity;
            }
        }
Exemplo n.º 5
0
        public List<Sys_UserInfoEntity> ResourceUserApproved(Guid orgEmp, string type)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoSys_UserApprove = new CustomBaseRepository<Sys_UserApprove>(unitOfWork);
                var repoCat_OrgStructure = new CustomBaseRepository<Cat_OrgStructure>(unitOfWork);
                var repoSys_UserInfo = new CustomBaseRepository<Sys_UserInfo>(unitOfWork);

                List<object> listObj = new List<object>();
                listObj.Add(null);
                listObj.Add(string.Empty);
                listObj.Add(string.Empty);

                string status = string.Empty;
                //var dataProfile = GetData<Hre_Profile>(listObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, ref status).ToList();
                var dataUA = repoSys_UserApprove.FindBy(s => s.IsDelete == null && s.Type == type).ToList();

                // lấy UserInfo của Người Duyệt
                var lstUserInfo = dataUA.Select(s => s.UserApproveID).Distinct().ToList();
                // Lấy guid Nhân Viên từ UserInfo
                var lstUser = repoSys_UserInfo.FindBy(s => lstUserInfo.Contains(s.ID)).ToList();
                //var lstProGuid = lstUser.Select(s => s.ProfileID).Distinct().ToList();
                var dataCat_OrgStructure = repoCat_OrgStructure.FindBy(s => s.OrderNumber != null).ToList();

                List<Sys_UserInfoEntity> lstReturn = new List<Sys_UserInfoEntity>();
                foreach (var item in dataUA)
                {
                    var user = lstUser.Where(d => d.ID == item.UserApproveID).FirstOrDefault();
                    //var idUser = lstUserInfo.Where(s => s == item.UserApproveID).FirstOrDefault();
                    //var idOrg = lstUser.Where(s => s.ID == idUser).Select(s => s.OrgStructureID).FirstOrDefault();

                    if (item.OrgStructureID != null && IsParentOrgStructure(orgEmp, item.OrgStructureID.Value, dataCat_OrgStructure))
                    {
                        Sys_UserInfoEntity entity = new Sys_UserInfoEntity()
                        {
                            ID = item.UserApproveID,
                            UserInfoName = user.UserInfoName,
                            UserLogin = user.UserLogin

                        };
                        lstReturn.Add(entity);
                    }
                }
                return lstReturn;
            }
        }
Exemplo n.º 6
0
        public string Post([Bind]Sys_UserModel user)
        {
            #region chuyển string sang list<guid> (MasterDataGroup)
            if (user != null && !string.IsNullOrEmpty(user.MasterDataGroupIDstr))
            {
                var lstDataGroupIDstr = user.MasterDataGroupIDstr.Split(',');
                Guid dataGroupId = Guid.Empty;
                user.MasterDataGroupID = new List<Guid?>();
                foreach (var item in lstDataGroupIDstr)
                {
                    Guid.TryParse(item, out dataGroupId);
                    if (dataGroupId != Guid.Empty)
                    {
                        user.MasterDataGroupID.Add(dataGroupId);
                    }
                }
            }

            #endregion

            var success = string.Empty;
            var passwordEncrypt = string.Empty;

            #region Validate

            string message = string.Empty;
            var checkValidate = ValidatorService.OnValidateData<Sys_UserModel>(user, "Sys_UserInfo", ref message);
            if (!checkValidate)
            {
                user.ActionStatus = message;
                return message;
            }
            else
            {
                user.UserInfoName = user.UserInfoName1;
            }
            #endregion

            if (user == null)
            {
                return string.Empty;
            }

            var model = new Sys_UserInfoEntity
            {
                ID = user.ID,
                Code = user.Code,
                UserType = user.UserType,
                ProfileID = user.ProfileID,
                UserLogin = user.UserLogin,
                UserInfoName = user.UserInfoName,
                Email = user.Email,
                IsActivate = user.IsActivate,
                IsCheckLDAP = user.IsCheckLDAP,
                LDAPDatasource = user.LDAPDatasource,
                DateEnd = user.EffectedDate,
                DateStart = DateTime.Now,
                FullName = user.UserInfoName
            };

            var service = new Sys_UserServices();

            #region change password

            ActionService actionService = new ActionService(UserLogin);
            var userInfo = actionService.GetByIdUseStore<Sys_UserInfoEntity>(user.ID, ConstantSql.hrm_sys_sp_get_UserbyId, ref status);

            if (userInfo != null)
            {
                // neu password nhap vao co su thay doi => change password cho user
                if (user.Password != userInfo.Password)
                {
                    #region Change Password
                    //ma hoa password
                    if (user != null && !string.IsNullOrEmpty(user.Password))
                    {
                        passwordEncrypt = EncryptUtil.MD5(user.Password);//mã hoá giống bản 7
                    }
                    model.Password = passwordEncrypt;
                    #endregion
                }
                else
                {
                    //neu khong co su thay doi password => set giá tri password là password cua db vào model
                    model.Password = userInfo.Password;
                }
            }
            else
            {
                //tạo mới password cho user
                model.Password = passwordEncrypt;
            }
            #endregion

            if (user.ID != Guid.Empty)
            {
                model.ID = user.ID;
                success = service.Edit<Sys_UserInfoEntity>(model) + ",0";
            }
            else
            {
                success = service.Add<Sys_UserInfoEntity>(model) + ",1";
            }

            if (user != null && user.MasterDataGroupID != null)
            {
                service.UpdateUserMasterDataGroup(user.ID, user.MasterDataGroupID);
            }

            return success;
        }
Exemplo n.º 7
0
        public Sys_UserModel Put(Sys_UserModel model)
        {
            var Sys_UserEntity = new Sys_UserInfoEntity
            {
                ID = model.ID,
                Code = model.Code,
                UserType = model.UserType,
                UserInfoName = model.UserInfoName,
                UserLogin = model.UserLogin,
                Password = model.Password,
                IsActivate = model.IsActivate,
                IsCheckLDAP = model.IsCheckLDAP,
                LDAPDatasource = model.LDAPDatasource,
            };
            var service = new Sys_UserServices();
            if (model.ID != Guid.Empty)
            {
                Sys_UserEntity.ID = model.ID;
                service.Edit<Sys_UserInfoEntity>(Sys_UserEntity);
            }
            else
            {
                service.Add<Sys_UserInfoEntity>(Sys_UserEntity);
            }

            return model;
        }