Exemplo n.º 1
0
        public IActionResult OrgUserClientEdit(int org_user_idx, string client_id, string AdminInd, string StatusInd, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                //int newID = _DbPortal.InsertUpdateT_PRT_ORG_USERS_CLIENT(null, org_user_idx, client_id, (AdminInd == "1" ? true : false), StatusInd, User.Identity.Name);
                int newID = _DbPortal.InsertUpdateT_PRT_ORG_USERS_CLIENT(null, org_user_idx, client_id, (AdminInd == "True" ? true : false), StatusInd, User.Identity.Name);

                if (newID == 0)
                {
                    TempData["Error"] = "Error adding user";
                }
                else
                {
                    TempData["Success"] = "Record successfully added";
                }
            }
            else
            {
                TempData["Error"] = "Error adding user";
            }

            return(RedirectToAction(returnUrl, "Admin", new { id = org_user_idx }));
        }
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." }));
        }