Exemplo n.º 1
0
        //************************************ ORGANIZATION USER CLIENT (non-Global Admin)  ***************************************
        public IActionResult ManageUsers(int?id)
        {
            //********* id = OrgUserClientID

            string _UserIDX = _userManager.GetUserId(User);

            var model = new ManageUsersViewModel
            {
                ddl_AdminOfOrgClients = _DbPortal.GetT_PRT_ORG_USERS_CLIENT_AdminByUserID(_UserIDX).Select(x => new SelectListItem
                {
                    Value = x.ORG_USER_CLIENT_IDX.ToString(),
                    Text  = x.ORG_CLIENT_ALIAS + " - " + x.CLIENT_ID
                })
            };

            //get users currently listed for the org/client
            //get users for the organization
            if (id != null)
            {
                model.selOrgUserClient = id;

                T_PRT_ORG_USER_CLIENT _ouc = _DbPortal.GetT_PRT_ORG_USERS_CLIENT_ByID((int)id);
                if (_ouc != null)
                {
                    T_PRT_ORG_USERS _ou = _DbPortal.GetT_PRT_ORG_USERS_ByOrgUserID(_ouc.ORG_USER_IDX);
                    if (_ou != null)
                    {
                        model.client_id      = _ouc.CLIENT_ID;
                        model.selOrg         = _ou.ORG_ID;
                        model.OrgUserClients = _DbPortal.GetT_PRT_ORG_USERS_CLIENT_ByOrgIDandClientID(_ou.ORG_ID, _ouc.CLIENT_ID, false);
                        model.ddl_Users      = _DbPortal.GetT_PRT_ORG_USERS_ByOrgID(_ou.ORG_ID).Select(x => new SelectListItem
                        {
                            Value = x.ORG_USER_IDX.ToString(),
                            Text  = x.USER_NAME
                        });
                    }
                }
            }
            ;

            return(View(model));
        }
Exemplo n.º 2
0
        public JsonResult AccessRightsRequest(int?orgUser, string client)
        {
            string _UserIDX = _userManager.GetUserId(User);

            T_PRT_ORG_USERS _ou = _DbPortal.GetT_PRT_ORG_USERS_ByOrgUserID(orgUser ?? -1);

            if (_ou != null)
            {
                int SuccID = _DbPortal.InsertUpdateT_PRT_ORG_USERS_CLIENT(null, orgUser, client, false, "R", _UserIDX);

                //return response
                if (SuccID > 0)
                {
                    //send email
                    List <string> _emailRecipients = new List <string>();

                    //**************first try to send to org / client admins
                    List <OrgUserClientDisplayType> _orgUserClientAdmins = _DbPortal.GetT_PRT_ORG_USERS_CLIENT_ByOrgIDandClientID(_ou.ORG_ID, client, true);
                    if (_orgUserClientAdmins != null && _orgUserClientAdmins.Count > 0)
                    {
                        foreach (OrgUserClientDisplayType _orgUserClientAdmin in _orgUserClientAdmins)
                        {
                            ApplicationUser _u = _userManager.FindByIdAsync(_orgUserClientAdmin.UserID).Result;
                            if (_u != null)
                            {
                                _emailRecipients.Add(_u.Email);
                            }
                        }
                    }

                    //**************if none found, then send to org admins

                    //**************finally send to portal admins
                    if (_emailRecipients.Count == 0)
                    {
                        IdentityRole _r = _roleManager.FindByNameAsync("PortalAdmin").Result;

                        IEnumerable <ApplicationUser> _us = _DbPortal.GetT_PRT_USERS_BelongingToRole(_r.Id);
                        if (_us != null)
                        {
                            foreach (ApplicationUser _u in _us)
                            {
                                _emailRecipients.Add(_u.Email);
                            }
                        }
                    }

                    string _UserName = _userManager.GetUserName(User);

                    //construct email parameters
                    List <emailParam> emailParams = new List <emailParam>()
                    {
                        new emailParam()
                        {
                            PARAM_NAME = "userName", PARAM_VAL = _UserName
                        },
                        new emailParam()
                        {
                            PARAM_NAME = "client", PARAM_VAL = client
                        },
                        new emailParam()
                        {
                            PARAM_NAME = "orgID", PARAM_VAL = _ou.ORG_ID
                        }
                    };

                    foreach (string _emailRecipient in _emailRecipients)
                    {
                        _emailSender.SendEmail(null, _emailRecipient, null, null, null, null, "ACCESS_REQUEST", emailParams);
                    }


                    return(Json(new
                    {
                        msg = "Success",
                        redirectUrl = Url.Action("AccessRights", "Manage")
                    }));
                }
            }

            //if got this far, it failed
            return(Json(new { msg = "Unable to request access." }));
        }