Ejemplo n.º 1
0
        public async Task <IActionResult> UpdateRoleMenus(string roleId, string menus)
        {
            Guid rId = new Guid(roleId);
            var  rms = _scontext.SecurityRoleMenus.Where(rr => rr.RoleId == rId).ToList();

            _scontext.RemoveRange(rms);
            await _scontext.SaveChangesAsync();


            var menuar = menus.Split('|');

            foreach (string menuId in menuar)
            {
                SecurityRoleMenus r = new SecurityRoleMenus();
                r.RoleId     = rId;
                r.MenuId     = int.Parse(menuId);
                r.EditedBy   = new Guid(HttpContext.Session.GetString("memberId"));
                r.EditedDate = DateTime.Now;
                _scontext.Add(r);
            }
            await _scontext.SaveChangesAsync();

            return(Json(new { result = "success" }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> LogOff()
        {
            var memberId = HttpContext.Session.GetString("memberId");

            if (memberId != null)
            {
                var smr = _scontext.SecurityMemberRoles.SingleOrDefault(smrr => smrr.MemberId == new Guid(memberId));
                smr.LoggedOutDate = DateTime.Now;
                _scontext.Update(smr);
                await _scontext.SaveChangesAsync();

                HttpContext.Session.Clear();
            }

            _logger.LogInformation(4, "User: "******" logged out.");
            return(RedirectToAction(nameof(HomeController.Index), "Home"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Suspend(string id, string status)
        {
            var mr = _scontext.SecurityMemberRoles.SingleOrDefault(mrr => mrr.MemberId == new Guid(id));

            if (mr != null)
            {
                mr.x_status   = status;
                mr.EditedDate = DateTime.Now;
                mr.EditedBy   = new Guid(HttpContext.Session.GetString("memberId"));
                _scontext.Update(mr);
                await _scontext.SaveChangesAsync();

                return(Json(new { result = "success" }));
            }
            else
            {
                return(Json(new { result = "fail" }));
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> CreateRole([Bind("RoleName")] SecurityRoles securityRoles)
        {
            if (ModelState.IsValid)
            {
                securityRoles.RoleId      = Guid.NewGuid();
                securityRoles.CreatedBy   = new Guid(HttpContext.Session.GetString("memberId"));
                securityRoles.CreatedDate = DateTime.Now;
                securityRoles.EditedBy    = new Guid(HttpContext.Session.GetString("memberId"));
                securityRoles.EditedDate  = DateTime.Now;
                securityRoles.x_status    = "Y";
                securityRoles.RoleName    = securityRoles.RoleName.Trim();

                _scontext.Add(securityRoles);

                SecurityRoleMenus rm1 = new SecurityRoleMenus();
                rm1.RoleId     = securityRoles.RoleId;
                rm1.MenuId     = 951000;
                rm1.EditedBy   = securityRoles.EditedBy;
                rm1.EditedDate = securityRoles.EditedDate;
                _scontext.Add(rm1);

                SecurityRoleMenus rm2 = new SecurityRoleMenus();
                rm2.RoleId     = securityRoles.RoleId;
                rm2.MenuId     = 951030;
                rm2.EditedBy   = securityRoles.EditedBy;
                rm2.EditedDate = securityRoles.EditedDate;
                _scontext.Add(rm2);

                SecurityRoleMenus rm3 = new SecurityRoleMenus();
                rm3.RoleId     = securityRoles.RoleId;
                rm3.MenuId     = 951040;
                rm3.EditedBy   = securityRoles.EditedBy;
                rm3.EditedDate = securityRoles.EditedDate;
                _scontext.Add(rm3);

                SecurityRoleMenus rm4 = new SecurityRoleMenus();
                rm4.RoleId     = securityRoles.RoleId;
                rm4.MenuId     = 951050;
                rm4.EditedBy   = securityRoles.EditedBy;
                rm4.EditedDate = securityRoles.EditedDate;
                _scontext.Add(rm4);

                try
                {
                    await _scontext.SaveChangesAsync();
                }
                catch (Exception e)
                {
                    //"Violation of UNIQUE KEY constraint 'UK_SecurityRoles'. Cannot insert duplicate key in object 'dbo.SecurityRoles'. The duplicate key value is (??????).\r\nThe statement has been terminated."
                    if (e.InnerException.Message.Contains("UNIQUE"))
                    {
                        return(Json(new { result = "dup", RoleName = securityRoles.RoleName }));
                    }
                    else
                    {
                        return(Json(new { result = "fail" }));
                    }
                }
                return(Json(new { result = "success" }));
            }
            return(Json(new { result = "fail" }));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Login(string uname, string upwd)
        {
            upwd = Utils.EncodeMd5(upwd.Trim());
            var m = await _context.member.SingleOrDefaultAsync(mm => (mm.mem_username == uname.Trim()) && (mm.mem_password == upwd));

            if (m != null)
            {
                var smr = await _scontext.SecurityMemberRoles.SingleOrDefaultAsync(smrr => (smrr.MemberId == m.id) && (smrr.x_status != "N"));

                if (smr != null)
                {
                    HttpContext.Session.SetString("memberId", m.id.ToString());
                    HttpContext.Session.SetString("roleId", m.mem_role_id.ToString());
                    HttpContext.Session.SetString("username", m.mem_username);
                    HttpContext.Session.SetString("displayname", (m.fname + " " + m.lname).Trim());

                    var memberId    = HttpContext.Session.GetString("memberId");
                    var roleId      = HttpContext.Session.GetString("roleId");
                    var displayName = HttpContext.Session.GetString("displayname");

                    var rms = _scontext.SecurityRoleMenus.Where(rmss => rmss.RoleId == m.mem_role_id).OrderByDescending(rmss => rmss.MenuId).ToList();
                    if (rms != null)
                    {
                        string menuHtml = "<ul class='nav navbar-top-links navbar-left'>_menuleft_</ul><ul class='nav navbar-top-links navbar-right'>_menuright_</ul>";
                        string menuLeft = ""; string menuRight = "";
                        string link = ""; string menuTemp = ""; int prevLevel = 0;
                        foreach (SecurityRoleMenus rm in rms)
                        {
                            SecurityMenus menu = await _scontext.SecurityMenus.SingleOrDefaultAsync(me => me.MenuId == rm.MenuId);

                            if (menu != null)
                            {
                                if (menu.HaveChild == 1)
                                {
                                    menuTemp = "<li class='dropdown'><a class='dropdown-toggle' data-toggle='dropdown' href='#'>" + menu.MenuDisplay + "</a><ul class='dropdown-menu'>" + menuTemp + "</ul></li>";
                                    if (menu.Level == 1)
                                    {
                                        if (menu.IsRightAlign != 1)
                                        {
                                            menuLeft = menuTemp + menuLeft;
                                        }
                                        else
                                        {
                                            menuRight = menuTemp + menuRight;
                                        }
                                        menuTemp = "";
                                    }
                                }
                                else
                                {
                                    if (menu.Level != prevLevel)
                                    {
                                        if (menu.IsRightAlign != 1)
                                        {
                                            menuLeft = menuTemp + menuLeft;
                                        }
                                        else
                                        {
                                            menuRight = menuTemp + menuRight;
                                        }
                                        menuTemp = "";
                                    }

                                    if (menu.MenuUrl != null)
                                    {
                                        link = menu.MenuUrl;
                                    }
                                    else
                                    {
                                        link = Url.Action(menu.MenuAction, menu.MenuController);
                                    }
                                    if (menu.MenuName != "-")
                                    {
                                        if (menu.Level != 1)
                                        {
                                            menuTemp = "<li><a href='" + link + "'>" + menu.MenuDisplay.Replace(@"""", @"\""") + "</a></li>" + menuTemp;
                                        }
                                        else
                                        {
                                            menuTemp = "<li><a class='dropdown-toggle' href='" + link + "'>" + menu.MenuDisplay.Replace(@"""", @"\""") + "</a></li>" + menuTemp;
                                        }
                                    }
                                    else
                                    {
                                        menuTemp = "<li class='divider'></li>" + menuTemp;
                                    }
                                    if (menu.Level == 1)
                                    {
                                        if (menu.IsRightAlign != 1)
                                        {
                                            menuLeft = menuTemp + menuLeft;
                                        }
                                        else
                                        {
                                            menuRight = menuTemp + menuRight;
                                        }
                                        menuTemp = "";
                                    }
                                }
                                prevLevel = menu.Level;
                            }
                        }
                        menuRight = menuRight.Replace("_displayname_", "<span id='_displayname_'>" + displayName + "</span>");
                        menuHtml  = menuHtml.Replace("_menuright_", menuRight);
                        menuHtml  = menuHtml.Replace("_menuleft_", menuLeft);
                        HttpContext.Session.SetString("mainmenu", menuHtml);
                    }

                    smr.LoggedInDate = DateTime.Now;
                    _scontext.Update(smr);
                    await _scontext.SaveChangesAsync();

                    var returnUrl = "";
                    //if (roleId != "c5a644a2-97b0-40e5-aa4d-e2afe4cdf428") //Not Administrators role
                    //{
                    //    if (roleId != "17822a90-1029-454a-b4c7-f631c9ca6c7d") //Not Member
                    //    {
                    //        //returnUrl = Url.Action("Index", "members");
                    //        returnUrl = Url.Action("DetailsPersonal", "members");
                    //    }
                    //    else //Is Member
                    //    {
                    //        returnUrl = Url.Action("DetailsPersonal", "members");
                    //    }
                    //}
                    //else //Have Administrators role
                    //{
                    //    returnUrl = Url.Action("ManageMembers", "Security");
                    //}
                    returnUrl = Url.Action("Home", "Security");
                    return(Json(new { result = "success", url = returnUrl }));
                }
                else
                {
                    return(Json(new { result = "fail" }));
                }
            }
            else
            {
                return(Json(new { result = "fail" }));
            }
        }