Esempio n. 1
0
        public bool UpdateUserRole(string allSelectList, int currRoleId, string deleteUserIds, string logonName)
        {
            if (allSelectList != null)
            {
                string[] selectId = allSelectList.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                for (int i = 0; i < selectId.Length; i++)
                {
                    if (selectId[i] != "")
                    {
                        int num = Convert.ToInt32(selectId[i].ToString().Trim());
                        if (Ctx.tbl_Common_RoleUser.Where(m => m.UserId == num).Count() == 0)
                        {
                            MD.tbl_Common_RoleUser roleUser = new MD.tbl_Common_RoleUser();
                            roleUser.UserId      = num;
                            roleUser.RoleId      = currRoleId;
                            roleUser.CreatedDate = DateTime.Now;
                            roleUser.CreatedBy   = logonName;

                            Ctx.tbl_Common_RoleUser.Add(roleUser);
                            Ctx.SaveChanges();
                        }
                        else
                        {
                            MD.tbl_Common_RoleUser date = Ctx.tbl_Common_RoleUser.First(u => u.UserId == num);
                            date.RoleId      = currRoleId;
                            date.IsDeleted   = false;
                            date.UpdatedBy   = logonName;
                            date.UpdatedDate = DateTime.Now;
                            Ctx.SaveChanges();
                        }
                    }
                }
            }

            if (deleteUserIds != null)
            {
                string[] delectId = deleteUserIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < delectId.Length; i++)
                {
                    if (delectId[i] != "")
                    {
                        int num = Convert.ToInt32(delectId[i].ToString().Trim());
                        MD.tbl_Common_RoleUser date = Ctx.tbl_Common_RoleUser.First(u => u.UserId == num);
                        date.RoleId      = null;
                        date.IsDeleted   = true;
                        date.UpdatedBy   = logonName;
                        date.UpdatedDate = DateTime.Now;
                        Ctx.SaveChanges();
                    }
                }
            }

            return(true);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }