예제 #1
0
        private IdentityModel ConvertUser(MD.tbl_Common_User user)
        {
            if (user == null)
            {
                return(null);
            }

            var result   = new IdentityModel();
            var roleUser = user.tbl_Common_RoleUser.FirstOrDefault();
            int roleId   = roleUser == null ? 0 : roleUser.RoleId.Value;
            var role     = ctx.Role.Where(r => r.RoleId == roleId).FirstOrDefault();

            result.Id             = user.UserId.ToString();
            result.LogonName      = user.LogonName;
            result.RoleId         = roleId;
            result.RoleName       = role == null ? "" : role.Name;
            result.RoleSelectList =
                (from m in ctx.ModulePermissionDefine
                 join pi in ctx.RolePermissionConfig.DefaultIfEmpty() on m.ModuleId equals pi.ModuleId into inner
                 from p in inner.DefaultIfEmpty()
                 where (p.RoleId == roleId || p.RoleId == null)
                 select new RolePermission
            {
                Action = string.IsNullOrEmpty(m.Action) ? "index" : m.Action,
                Area = m.Area ?? string.Empty,
                Controller = m.Controller ?? string.Empty,
                ModuleId = m.ModuleId,
                IsAvailable = (m.Value & p.Value) == m.Value ? true : false
            }).ToList();

            MD.tbl_Common_UserOfGasStation userGas = ctx.UserOfGasStation.Where(m => m.UserId == user.UserId).FirstOrDefault();
            return(result);
        }
예제 #2
0
        public bool UpdatePasswordDb(VM.UserInfoItem model)
        {
            MD.tbl_Common_User date = Ctx.tbl_Common_User.Where(c => c.UserId == model.UserId).FirstOrDefault();

            date.Password    = model.Password;
            date.UpdatedBy   = model.UpdatedBy;
            date.UpdatedDate = DateTime.Now;
            Ctx.SaveChanges();


            return(true);
        }
예제 #3
0
        public bool UpdatePassword(IdentityModel model)
        {
            MD.tbl_Common_User date = Ctx.tbl_Common_User.Where(c => c.UserId.ToString() == model.Id).FirstOrDefault();

            date.Password    = model.PasswordHash;
            date.UpdatedBy   = model.UpdateBy;
            date.UpdatedDate = DateTime.Now;
            Ctx.SaveChanges();


            return(true);
        }
예제 #4
0
        public bool Update(VM.UserInfoItem model)
        {
            MD.tbl_Common_User date = Ctx.tbl_Common_User.First(u => u.UserId == model.UserId);
            date.UserName  = model.UserName;
            date.LogonName = model.LogonName;
            if (model.StrStatus.ToString() == UserStatus.Normal.strValue)
            {
                date.Status = UserStatus.Normal.intValue;
            }
            else
            {
                date.Status = UserStatus.Disable.intValue;
            }
            date.DomainAccount = model.DomainAccount;
            date.EmailAddress  = model.EmailAddress;
            date.UpdatedBy     = model.UpdatedBy;
            date.UpdatedDate   = DateTime.Now;
            //Ctx.SaveChanges();
            //修改公司关系
            updateUserOfCompany(date.UserId, model.UserCompanyValue, model.UpdatedBy);
            //UpdateUserCompany(model.UserCompanyValue, date.UserId, model.UpdatedBy);

            Ctx.SaveChanges();

            //修改 角色


            if (Ctx.tbl_Common_RoleUser.Where(m => m.UserId == model.UserId).Count() == 0)
            {
                MD.tbl_Common_RoleUser roleUser = new MD.tbl_Common_RoleUser();
                roleUser.RoleId      = model.RoleId.Value;
                roleUser.UserId      = date.UserId;
                roleUser.CreatedDate = DateTime.Now;
                roleUser.CreatedBy   = model.UpdatedBy;
                //roleUser.UpdatedDate = DateTime.Now;
                //roleUser.UpdatedBy = model.UpdatedBy;

                Ctx.tbl_Common_RoleUser.Add(roleUser);
                Ctx.SaveChanges();
            }
            else
            {
                MD.tbl_Common_RoleUser roleUser = Ctx.tbl_Common_RoleUser.First(m => m.UserId == model.UserId);
                roleUser.RoleId      = model.RoleId.Value;
                roleUser.IsDeleted   = false;
                roleUser.UpdatedDate = DateTime.Now;
                roleUser.UpdatedBy   = model.UpdatedBy;
                Ctx.SaveChanges();
            }

            updateUserOfGasStation(date.UserId, model.UserGasStationValue, model.UpdatedBy);
            return(true);
        }
예제 #5
0
        public bool UserUpdate(VM.UserInfoItem model)
        {
            MD.tbl_Common_User date = Ctx.tbl_Common_User.First(u => u.UserId == model.UserId);
            date.UserName     = model.UserName;
            date.EmailAddress = model.EmailAddress;
            date.UpdatedBy    = model.UpdatedBy;
            date.UpdatedDate  = DateTime.Now;

            Ctx.SaveChanges();

            return(true);
        }
예제 #6
0
        //public List<SelectListItem> GetAllGasStationSelectList()
        //{
        //    var allGasStation = (from gasStation in Ctx.tbl_Gs_GasStationInfo
        //                         where gasStation.IsDelete != true
        //                         select new SelectListItem
        //                         {
        //                             Text = gasStation.Name,
        //                             Value = gasStation.GasStationId.ToString(),
        //                             Selected = true
        //                         });
        //    return allGasStation.ToList();

        //}

        public bool Create(VM.UserInfoItem model)
        {
            MD.tbl_Common_User date = new MD.tbl_Common_User();
            date.UserName  = model.UserName;
            date.LogonName = model.LogonName;
            //model.StatusList.First().
            if (model.StrStatus.ToString() == UserStatus.Normal.strValue)
            {
                date.Status = UserStatus.Normal.intValue;
            }
            else
            {
                date.Status = UserStatus.Disable.intValue;
            }

            date.DomainAccount = model.DomainAccount;
            date.EmailAddress  = model.EmailAddress;
            date.CreatedDate   = DateTime.Now;
            date.CreatedBy     = model.CreatedBy;
            date.UpdatedDate   = DateTime.Now;
            date.UpdatedBy     = model.UpdatedBy;

            //生成密码
            //IPasswordPolicy Password = new RandomPassword();
            //string orginalPassword = Password.GeneratePassword();
            //date.Password = HashEncrypt.SHA512Encrypt(orginalPassword);
            date.Password = model.Password;

            Ctx.tbl_Common_User.Add(date);

            //生成角色关系
            MD.tbl_Common_RoleUser roleUser = new MD.tbl_Common_RoleUser();
            roleUser.RoleId      = model.RoleId.Value;
            roleUser.UserId      = date.UserId;
            roleUser.CreatedDate = DateTime.Now;
            roleUser.CreatedBy   = model.CreatedBy;
            //roleUser.UpdatedDate = DateTime.Now;
            //roleUser.UpdatedBy = model.UpdatedBy;

            Ctx.tbl_Common_RoleUser.Add(roleUser);
            Ctx.SaveChanges();

            //生成公司关系
            updateUserOfCompany(roleUser.UserId, model.UserCompanyValue, model.CreatedBy);

            //生成 气站关系
            // updateUserOfGasStation(roleUser.UserId, model.UserGasStationValue, model.CreatedBy);
            //发送邮件
            //if(date.Status==1)
            //    SendEmail(date, orginalPassword, "User_New");
            return(true);
        }
예제 #7
0
        public bool ResetPassword(string name, string emailTo)
        {
            MD.tbl_Common_User date = Ctx.tbl_Common_User.First(u => u.LogonName == name);

            IPasswordPolicy Password        = new RandomPassword();
            string          orginalPassword = Password.GeneratePassword();

            date.Password    = HashEncrypt.SHA512Encrypt(orginalPassword);
            date.UpdatedBy   = null;
            date.UpdatedDate = null;
            Ctx.SaveChanges();
            //发送邮件
            SendEmail(date, orginalPassword, "User_ResetPassword", emailTo);


            return(true);
        }
예제 #8
0
        private void SendEmail(MD.tbl_Common_User model, string password, string emailTemplateName, string emailTo)
        {
            bool isSendEmailtoIIS = false;
            var  sendEmailInfo    = new SendEmailInfo();
            var  email            = Ctx.tbl_EmailTemplate.FirstOrDefault(t => t.Name == emailTemplateName);

            string[] emailSendTo = { emailTo };

            string url = string.Format("{0}/", EmailTemplateParam.GetHostName());

            sendEmailInfo.mailSubject = email.EmailSubject.Replace(EmailTemplateParam.SystemName, EmailTemplateParam.SystemNameBasic);
            sendEmailInfo.mailBody    = email.EmailContent.Replace(EmailTemplateParam.UserDisplayName, model.UserName)
                                        .Replace(EmailTemplateParam.URL, url)
                                        .Replace(EmailTemplateParam.UserName, model.LogonName)
                                        .Replace(EmailTemplateParam.Password, password)
                                        .Replace("[DateTime]", DateTime.Now.ToString("yyyy年MM月dd日"));

            //MailHelper.SendMail(emailSendTo, sendEmailInfo.mailSubject, sendEmailInfo.mailBody, 0, isSendEmailtoIIS, true);
        }
예제 #9
0
 public bool ResetPassword(int id, string userName)
 {
     MD.tbl_Common_User date = Ctx.tbl_Common_User.First(u => u.UserId == id);
     if (date.Status == 1)
     {
         IPasswordPolicy Password        = new RandomPassword();
         string          orginalPassword = Password.GeneratePassword();
         date.Password    = HashEncrypt.SHA512Encrypt(orginalPassword);
         date.UpdatedBy   = userName;
         date.UpdatedDate = DateTime.Now;
         Ctx.SaveChanges();
         //发送邮件
         //SendEmail(date, orginalPassword, "User_ResetPassword");
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #10
0
        public bool Delete(int id, string userName)
        {
            MD.tbl_Common_User date = Ctx.tbl_Common_User.First(u => u.UserId == id);
            date.IsDeleted   = true;
            date.UpdatedBy   = userName;
            date.UpdatedDate = DateTime.Now;
            Ctx.SaveChanges();

            MD.tbl_Common_RoleUser roleUser = Ctx.tbl_Common_RoleUser.First(u => u.UserId == id);
            roleUser.IsDeleted   = true;
            roleUser.UpdatedBy   = userName;
            roleUser.UpdatedDate = DateTime.Now;
            Ctx.SaveChanges();

            var userOfGasItem = Ctx.tbl_Common_UserOfGasStation.Where(u => u.IsDeleted != true && u.UserId == id);

            foreach (var userOfGas in userOfGasItem)
            {
                userOfGas.IsDeleted   = true;
                userOfGas.UpdatedBy   = userName;
                userOfGas.UpdatedDate = DateTime.Now;
            }
            Ctx.SaveChanges();

            var userOfCompanyItem = Ctx.tbl_Common_UserOfCompany.Where(u => u.IsDeleted != true && u.UserId == id);

            foreach (var userOfCompany in userOfCompanyItem)
            {
                userOfCompany.IsDeleted   = true;
                userOfCompany.UpdatedBy   = userName;
                userOfCompany.UpdatedDate = DateTime.Now;
            }
            Ctx.SaveChanges();

            return(true);
        }