コード例 #1
0
ファイル: RoleController.cs プロジェクト: zxgdll/UMember
        public ActionResult Edit(RoleView rolevView)
        {
            if (ModelState.IsValid)
            {
                tbRole role = db.tbRole.Find(rolevView.Role_ID);
                role.Role_Name       = rolevView.Role_Name;
                role.Is_Delete       = rolevView.Is_Delete;
                role.Is_Hide         = rolevView.Is_Hide;
                db.Entry(role).State = EntityState.Modified;

                var query = from s in db.tbRoleMenu
                            where s.Role_ID == role.Role_ID
                            select s;

                foreach (tbRoleMenu m in query.ToList())
                {
                    db.tbRoleMenu.Remove(m);
                }

                foreach (string s in rolevView.Menu_Name)
                {
                    tbRoleMenu roleMenu = new tbRoleMenu();
                    roleMenu.Role_ID   = role.Role_ID;
                    roleMenu.Menu_Name = s;
                    db.tbRoleMenu.Add(roleMenu);
                }
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(rolevView));
        }
コード例 #2
0
        public static string GetRoleById(int Id)
        {
            string str = string.Empty;

            try
            {
                IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
                timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                tbRole            temp        = new tbRole();
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                List <tbRole>     templist    = myDbContext.tbRole.Where(p => p.Id == Id).ToList();
                if (templist != null && templist.Count > 0)
                {
                    temp = templist[0];
                    str  = JsonConvert.SerializeObject(temp, Formatting.Indented, timeFormat);
                    str  = ResponseHelper.ResponseMsg("1", "取数成功", str);
                }
                else
                {
                    str = JsonConvert.SerializeObject(temp, Formatting.Indented, timeFormat);
                    str = ResponseHelper.ResponseMsg("-1", "角色不存在", str);
                }
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
コード例 #3
0
        public static string UpdateRole(string Rolestr)
        {
            string str = string.Empty;

            try
            {
                tbRole            tb          = JsonConvert.DeserializeObject <tbRole>(Rolestr);
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                tbRole            data        = myDbContext.tbRole.Where(p => p.Id == tb.Id).FirstOrDefault();

                data.Description = tb.Description;
                data.RoleName    = tb.RoleName;
                data.UpdateBy    = tb.UpdateBy;
                data.UpdateTime  = DateTime.Now;


                int DataCount = myDbContext.tbRole.Where(p => p.RoleName == data.RoleName && p.Id != data.Id).Count <tbRole>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("角色名:{0}重复,请重新输入", data.RoleName));
                }


                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "更新成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
コード例 #4
0
        public static string AddRole(string Rolestr)
        {
            string str = string.Empty;

            try
            {
                tbRole tb = JsonConvert.DeserializeObject <tbRole>(Rolestr);

                tbRole newtb = new tbRole()
                {
                    RoleName    = tb.RoleName,
                    CreateBy    = tb.CreateBy,
                    CreateTime  = DateTime.Now,
                    Description = tb.Description,
                    UpdateTime  = DateTime.Now,
                    UpdateBy    = tb.CreateBy
                };
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                int DataCount = myDbContext.tbRole.Where(p => p.RoleName == newtb.RoleName).Count <tbRole>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("角色名:{0}重复,请重新输入", newtb.RoleName));
                }

                myDbContext.tbRole.Add(newtb);
                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "保存成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
コード例 #5
0
        public static string GetNoticeById(string Code)
        {
            string str = string.Empty;

            try
            {
                IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
                timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                tbRole temp = new tbRole();
                //NoticeModel returnModel = new NoticeModel();
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                tbNotice          main        = myDbContext.tbNotice.Where(p => p.Code == Code).ToList().FirstOrDefault();



                if (main != null)
                {
                    str = JsonConvert.SerializeObject(main, Formatting.Indented, timeFormat);
                    str = ResponseHelper.ResponseMsg("1", "取数成功", str);
                }
                else
                {
                    str = JsonConvert.SerializeObject(main, Formatting.Indented, timeFormat);
                    str = ResponseHelper.ResponseMsg("-1", "通知信息不存在", str);
                }
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
コード例 #6
0
        public static string GetNoticeItemById(string Code)
        {
            string str = string.Empty;

            try
            {
                IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
                timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                tbRole temp = new tbRole();
                //NoticeModel returnModel = new NoticeModel();
                AchieveDBEntities myDbContext = new AchieveDBEntities();



                var query = from nu in myDbContext.tbNoticeUser
                            join u in myDbContext.tbUser on nu.UserId equals u.ID
                            where nu.NoticeCode == Code
                            orderby nu.id
                            select new NoticeUserModel
                {
                    AccountName = u.AccountName,
                    CreateBy    = nu.CreateBy,
                    CreateTime  = nu.CreateTime,
                    id          = nu.id,
                    NoticeCode  = nu.NoticeCode,
                    SendFlag    = nu.SendFlag,
                    SendTime    = nu.SendTime,
                    UpdateBy    = nu.UpdateBy,
                    UpdateTime  = nu.UpdateTime,
                    UserId      = nu.UserId,
                    RealName    = u.RealName
                };

                List <NoticeUserModel> item = new List <NoticeUserModel>();
                if (query != null)
                {
                    item = query.ToList();



                    str = JsonConvert.SerializeObject(item, Formatting.Indented, timeFormat);
                    str = ResponseHelper.ResponseMsg("1", "取数成功", str);
                }
                else
                {
                    str = JsonConvert.SerializeObject(item, Formatting.Indented, timeFormat);
                    str = ResponseHelper.ResponseMsg("-1", "通知信息不存在", str, 0);
                }
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
コード例 #7
0
        public ActionResult RegisterUser(RegisterUserRoleViewModel obj)
        {
            User u = new User();

            u.UserName = obj.UserName;
            u.Password = obj.Password;
            db.Users.Add(u);
            db.SaveChanges();

            tbRole r = new tbRole();

            r.RoleName = obj.RoleName;
            r.UserId   = u.UserID;
            db.tbRoles.Add(r);
            db.SaveChanges();

            return(RedirectToAction("Login", "Account"));
        }
コード例 #8
0
ファイル: RoleController.cs プロジェクト: zxgdll/UMember
        //
        // GET: /Role/Edit/5

        public ActionResult Edit(int id = 0)
        {
            tbRole   tbrole = db.tbRole.Find(id);
            RoleView rv     = new RoleView();

            rv.Role_ID   = id;
            rv.Role_Name = tbrole.Role_Name;
            if (tbrole.Is_Hide == true)
            {
                rv.Is_Hide = true;
            }
            if (tbrole.Is_Delete == true)
            {
                rv.Is_Delete = true;
            }

            var query = from s in db.tbRoleMenu
                        where s.Role_ID == id
                        select s;

            if (query.ToList().Count > 0)
            {
                int      i     = 0;
                string[] menus = new string[query.ToList().Count];
                foreach (tbRoleMenu rm in query.ToList())
                {
                    menus[i] = rm.Menu_Name;
                    i++;
                }
                rv.Menu_Name = menus;
            }
            else
            {
                string[] menus = new string[1];
                menus[0]     = "";
                rv.Menu_Name = menus;
            }

            if (tbrole == null)
            {
                return(HttpNotFound());
            }
            return(View(rv));
        }
コード例 #9
0
ファイル: RoleController.cs プロジェクト: zxgdll/UMember
        public ActionResult Create(RoleView rolevView)
        {
            if (ModelState.IsValid)
            {
                tbRole role = new tbRole();
                role.Role_Name = rolevView.Role_Name;
                role.Is_Delete = rolevView.Is_Delete;
                role.Is_Hide   = rolevView.Is_Hide;
                db.tbRole.Add(role);

                foreach (string s in rolevView.Menu_Name)
                {
                    tbRoleMenu roleMenu = new tbRoleMenu();
                    roleMenu.Role_ID   = role.Role_ID;
                    roleMenu.Menu_Name = s;
                    db.tbRoleMenu.Add(roleMenu);
                }
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(rolevView));
        }
コード例 #10
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                string secretPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(model.Admin_Password, "SHA1");
                var    result         = from s in db.tbAdmin
                                        where s.Admin_Name == model.Admin_Name && s.Admin_Password == secretPassword && (s.Is_Delete == false || s.Is_Delete == null)
                                        select s;

                if (Session["ValidateCode"].ToString() != model.ValidateCode)
                {
                    ModelState.AddModelError("ValidateCode", "验证码错误");
                    return(View());
                }
                if (result.ToList().Count > 0)
                {
                    FormsAuthentication.SetAuthCookie(model.Admin_Name, true);
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                        !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        System.Web.HttpContext.Current.Session["Admin_ID"]   = result.ToList()[0].Admin_ID;
                        System.Web.HttpContext.Current.Session["Admin_Name"] = result.ToList()[0].Admin_Name;
                        System.Web.HttpContext.Current.Session["BackUp"]     = 0;
                        tbAdmin admin = db.tbAdmin.Find(result.ToList()[0].Admin_ID);
                        tbRole  role  = db.tbRole.Find(admin.Role_ID);
                        System.Web.HttpContext.Current.Session["Role_Name"] = role.Role_Name;
                        System.Web.HttpContext.Current.Session["Role_ID"]   = role.Role_ID;

                        StringBuilder sb    = new StringBuilder();
                        var           query = from s in db.tbRoleMenu
                                              where s.Role_ID == role.Role_ID
                                              select s;
                        foreach (tbRoleMenu RoleMenu in query.ToList())
                        {
                            if (RoleMenu.Menu_Name != null)
                            {
                                sb.Append(",").Append(RoleMenu.Menu_Name);
                            }
                        }
                        if (sb.ToString() == string.Empty)
                        {
                            System.Web.HttpContext.Current.Session["Menu_Name"] = string.Empty;
                        }
                        else
                        {
                            System.Web.HttpContext.Current.Session["Menu_Name"] = sb.ToString().Substring(1);
                        }

                        IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName());
                        string      myip    = IpEntry.AddressList[1].ToString();
                        if (IpEntry.AddressList.Length > 2)
                        {
                            myip = IpEntry.AddressList[2].ToString();
                        }
                        //tbLog log = new tbLog();
                        //log.Admin_ID = result.ToList()[0].Admin_ID;
                        //log.Login_Time = DateTime.Now;
                        //log.IP = myip;
                        //db.tbLog.Add(log);

                        db.SaveChanges();
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View());
        }