コード例 #1
0
ファイル: Sys_UserServices.cs プロジェクト: radtek/vnr
 /// <summary>Kiểm tra googleEmail co tồn tại trong hệ thống VNR chưa</summary>
 /// <param name="googleEmail">Google Email</param>
 /// <param name="googleProfileName">ProfileName của google</param>
 /// <returns></returns>
 public Sys_UserInfoEntity CheckEmailExisted(string googleEmail, string googleProfileName)
 {
     using (var context = new VnrHrmDataContext())
     {
         var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         var repo = new Sys_UserRepository(unitOfWork);
         var userInfo = unitOfWork.CreateQueryable<Sys_UserInfo>(Guid.Empty, m => m.UserLogin == googleEmail).FirstOrDefault();
         var userInfoEntity = userInfo.CopyData<Sys_UserInfoEntity>();
         if (userInfo == null && !string.IsNullOrEmpty(googleEmail))
         {
             //neu chua co googleEmail => tao moi user
             Sys_UserInfo usr = new Sys_UserInfo
             {
                 Email = googleEmail,
                 FullName = googleProfileName,
                 UserLogin = googleEmail,
                 UserInfoName = googleProfileName,
                 Password = "******",
                 IsActivate = true
             };
             repo.Add(usr);
             repo.SaveChanges();
             userInfoEntity = usr.CopyData<Sys_UserInfoEntity>();
         }
         else
         {
             return userInfoEntity;
         }
         return userInfoEntity;
     }
 }
コード例 #2
0
ファイル: Sys_UserServices.cs プロジェクト: radtek/vnr
 public DateTime CurrentDateTime()
 {
     using (var context = new VnrHrmDataContext())
     {
         var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         var repo = new Sys_UserRepository(unitOfWork);
         return repo.CurrentDateTime();
     }
 }
コード例 #3
0
ファイル: Sys_UserServices.cs プロジェクト: radtek/vnr
        /// <summary> Thay đổi mật khẩu </summary>
        /// <param name="id">id của User</param>
        /// <param name="oldPassword">Mật Khẩu Cũ</param>
        /// <param name="newPassword">Mật Khẩu Mới</param>
        /// <returns></returns>
        public bool ChangePassword(Guid id, string oldPassword, string newPassword)
        {
            var success = true;
            var status = string.Empty;
            var passwordEncrypt = string.Empty;

            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoUserInfo = new Sys_UserRepository(unitOfWork);
                if (id != Guid.Empty)
                {
                    var userInfo = repoUserInfo.GetById(id);

                    #region change password

                    if (userInfo != null)
                    {
                        //kt password
                        if (EncryptUtil.MD5(oldPassword) != userInfo.Password)
                        {
                            return false;
                        }

                        // neu password nhap vao co su thay doi => change password cho user
                        if (newPassword != userInfo.Password)
                        {
                            #region Change Password
                            //ma hoa password
                            if (!string.IsNullOrEmpty(newPassword))
                            {
                                passwordEncrypt = EncryptUtil.MD5(newPassword);//mã hoá giống bản 7
                            }
                            userInfo.Password = passwordEncrypt;
                            #endregion

                            repoUserInfo.Edit(userInfo);
                            var result = repoUserInfo.SaveChanges();
                            if (result != DataErrorCode.Success)
                            {
                                success = false;
                            }
                        }
                    }
                    #endregion
                }
            }
            return success;
        }
コード例 #4
0
ファイル: Sys_UserServices.cs プロジェクト: radtek/vnr
 public bool IsDuplicationUser(string loginName, Guid id)
 {
     using (var context = new VnrHrmDataContext())
     {
         var isExistedUser = false;
         var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         var repo = new Sys_UserRepository(unitOfWork);
         var existedUser = repo.FindBy(p => p.UserLogin == loginName && (p.ID != id)).FirstOrDefault();
         if (existedUser != null)
         {
             isExistedUser = true;
         }
         return isExistedUser;
     }
 }
コード例 #5
0
ファイル: EmployeeServices.cs プロジェクト: dtafe/vnr
        //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;
            }
        }
コード例 #6
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);
            }
        }
コード例 #7
0
        public async Task <JsonResult> DelRole(int rid)
        {
            using (Sys_RoleRepository rep = new Sys_RoleRepository())
            {
                using (Sys_UserRepository userRepo = new Sys_UserRepository())
                {
                    var userTotal = await userRepo.GetUserListCountByRoleID(rid);

                    if (userTotal > 0)
                    {
                        return(Json(new { isOk = false, msg = "请先删除该角色下的用户" }));
                    }
                    var result = await rep.DeleteRoleAsync(rid);

                    return(Json(new { isOk = result }));
                }
            }
        }
コード例 #8
0
        public async Task <string> CreateReport(List <int> userIDs, DateTime reportDate)
        {
            DateTime      nowTime    = reportDate;
            var           weekStart  = CommonHelper.GetTimeStartByType(ETimeType.Week, nowTime).Value;
            var           weekEnd    = CommonHelper.GetTimeEndByType(ETimeType.Week, nowTime).Value;
            int           weekOfYear = CommonHelper.GetWeekOfYear(weekStart);//当前第几周
            StringBuilder sbWeekly   = new StringBuilder();

            using (PersonTaskRepository ptaskRepo = new PersonTaskRepository())
            {
                using (Sys_UserRepository userRepo = new Sys_UserRepository())
                {
                    var vTaskList = await ptaskRepo.GetPersonTaskDailyListAsync(userIDs, weekStart, weekEnd); //把本周的任务一次性查出来

                    var vTaskListDistinct = GetDistinct(vTaskList);                                           //去重复
                    foreach (var uid in userIDs)
                    {
                        var user = await userRepo.GetUserDicAsync(uid);

                        var myTaskDaily = vTaskListDistinct.Where(p => p.handlerID == uid).ToList();//个人本周任务列表
                        if (myTaskDaily.Count == 0)
                        {
                            sbWeekly.AppendLine("<br>-------" + user.Name + "第" + weekOfYear + "周周报----------");
                            continue;
                        }
                        var myTaskGroupByProd = myTaskDaily.GroupBy(p => p.ProdName).Select(p => new { p.Key }).ToList();//按产品分组

                        sbWeekly.AppendLine("<br>-------" + user.Name + "第" + weekOfYear + "周周报----------");
                        foreach (var prod in myTaskGroupByProd)
                        {
                            sbWeekly.AppendLine("<br>产品:" + prod.Key);
                            var myProdTaskList = myTaskDaily.Where(p => p.ProdName == prod.Key).ToList();
                            sbWeekly.AppendLine(GetContent(myProdTaskList, weekStart));
                        }
                    }
                }
            }
            return(sbWeekly.ToString());
        }
コード例 #9
0
        public async Task <string> CreateReport(List <int> userIDs, DateTime reportDate)
        {
            DateTime      nowTime   = reportDate;
            DateTime      yesterDay = nowTime.AddDays(-1);
            StringBuilder sbDaily   = new StringBuilder();

            using (PersonTaskRepository ptaskRepo = new PersonTaskRepository())
            {
                using (Sys_UserRepository userRepo = new Sys_UserRepository())
                {
                    var vTaskList = await ptaskRepo.GetPersonTaskDailyListAsync(userIDs, yesterDay, nowTime);//把昨天和今天的任务一次性查出来

                    foreach (var uid in userIDs)
                    {
                        var user = await userRepo.GetUserDicAsync(uid);

                        if (vTaskList.Where(p => p.handlerID == uid).FirstOrDefault() == null)
                        {
                            sbDaily.AppendLine("<br>-------" + user.Name + nowTime.ToString("yyyy-MM-dd") + "日报----------");
                            sbDaily.AppendLine("<br>昨天:");
                            sbDaily.AppendLine("<br>今天:");
                            continue;
                        }
                        sbDaily.AppendLine("<br>-------" + user.Name + nowTime.ToString("yyyy-MM-dd") + "日报----------");
                        sbDaily.AppendLine("<br>昨天:");
                        var y_source = (from j in vTaskList
                                        where j.handlerID == uid && j.DateLine == yesterDay
                                        select j).ToList();
                        sbDaily.AppendLine(GetContent(y_source, yesterDay));
                        sbDaily.AppendLine("<br>今天:");
                        var t_source = (from j in vTaskList
                                        where j.handlerID == uid && j.DateLine == nowTime
                                        select j).ToList();
                        sbDaily.AppendLine(GetContent(t_source, nowTime));
                    }
                }
            }
            return(sbDaily.ToString());
        }
コード例 #10
0
 public override void SetCurrentRepository()
 {
     CurrentRepository = new Sys_UserRepository();
 }
コード例 #11
0
ファイル: Sys_UserServices.cs プロジェクト: radtek/vnr
        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;
            }
        }
コード例 #12
0
ファイル: Sys_UserServices.cs プロジェクト: radtek/vnr
        /// <summary>Reset Password (random 8 ki tu) theo ds User</summary>
        /// <param name="userIDs">Ds User</param>
        /// <returns></returns>
        public List<UserPasswordResetEntity> ResetPassword(List<Guid> userIDs)
        {
            var success = true;
            var status = string.Empty;
            var passwordEncrypt = string.Empty;
            var lstUserPassResets = new List<UserPasswordResetEntity>();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoUserInfo = new Sys_UserRepository(unitOfWork);
                if (userIDs.Any())
                {
                    //lay ds users
                    var lstUserInfo = new List<Sys_UserInfo>();
                    var users = unitOfWork.CreateQueryable<Sys_UserInfo>(Guid.Empty, m => userIDs.Contains(m.ID)).ToList();
                    var newPasswordReset = string.Empty;
                    foreach (var usr in users)
                    {
                        #region Change Password
                        //tu sinh password
                        newPasswordReset = GetRandomString();

                        //ma hoa password
                        if (!string.IsNullOrEmpty(newPasswordReset))
                        {
                            passwordEncrypt = EncryptUtil.MD5(newPasswordReset);//mã hoá giống bản 7
                        }
                        usr.Password = passwordEncrypt;
                        if (!string.IsNullOrEmpty(usr.Email))
                        {
                            var userPassReset = new UserPasswordResetEntity
                            {
                                Email = usr.Email,
                                Password = newPasswordReset,
                                UserInfoName = usr.UserInfoName,
                                UserLogin = usr.UserLogin,
                            };
                            lstUserPassResets.Add(userPassReset);

                            usr.DateChangePasssword = null;
                            lstUserInfo.Add(usr);
                        }
                        #endregion
                    }

                    if (lstUserInfo.Any())
                    {
                        repoUserInfo.Edit(lstUserInfo);
                        var result = repoUserInfo.SaveChanges();
                        if (result != DataErrorCode.Success)
                        {
                            return new List<UserPasswordResetEntity>();
                        }
                        else
                        {
                            ResetPasswordResponseEmail(lstUserPassResets);
                        }
                    }
                }
            }
            return lstUserPassResets;
        }