public JsonResult Hospitals(string prefix) { OKTAServiceRepository okta = new OKTAServiceRepository(); var Okta = okta.GetUserProfile(HttpContext.GetOwinContext().Authentication.User.Claims); var IsSuperAdmin = db.IsSuperAdmin(Okta.email); ServiceRepository serviceObj = new ServiceRepository(); HttpResponseMessage response = null; List <HospitalModel> hosiptals = null; if (IsSuperAdmin && prefix.Length > 2) { response = serviceObj.GetResponse(string.Format("hospital/0?prefix={0}", prefix, Okta.email)); hosiptals = response.Content.ReadAsAsync <List <HospitalModel> >().Result; return(Json(hosiptals, JsonRequestBehavior.AllowGet)); } else if (!IsSuperAdmin) { response = serviceObj.GetResponse(string.Format("hospital/?email={0}", Okta.email)); hosiptals = response.Content.ReadAsAsync <List <HospitalModel> >().Result; return(Json(hosiptals, JsonRequestBehavior.AllowGet)); } else { return(Json(null, JsonRequestBehavior.AllowGet)); } }
public ActionResult Delete(int id) { Roles role = new Roles(); OKTAServiceRepository okta = new OKTAServiceRepository(); var Okta = okta.GetUserProfile(HttpContext.GetOwinContext().Authentication.User.Claims); var IsSuperAdmin = db.IsSuperAdmin(Okta.email); if (Okta.userName.Length > 0 && IsSuperAdmin) { if (id <= 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } role = db.GetRole(id); if (role == null) { return(HttpNotFound()); } } if (!IsSuperAdmin) { ViewBag.RoleExistMessage = "Please contact HANYS Admin to delete"; } return(View(role)); }
public ActionResult EditUser(int id) { OKTAServiceRepository okta = new OKTAServiceRepository(); var Okta = okta.GetUserProfile(HttpContext.GetOwinContext().Authentication.User.Claims); var IsSuperAdmin = db.IsSuperAdmin(Okta.email); if (!IsSuperAdmin) { ViewBag.RoleExistMessage = "Please contact HANYS Admin to edit"; } var user = new UserModel(); ServiceRepository serviceObj = new ServiceRepository(); HttpResponseMessage response = serviceObj.GetResponse("user/GetUserById?id=" + id); user = response.Content.ReadAsAsync <UserModel>().Result; var client = new HttpClient(); //assign the API URL call client.BaseAddress = new Uri(APIuri + "/v1/"); //Set up the header for the API call client.DefaultRequestHeaders.Clear(); //set up the API header by including the API key located at web.config client.DefaultRequestHeaders.Add("Authorization", "SSWS " + APIkey); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); string Geturl = ""; Geturl = "users?search=profile.email eq \"" + user.USR_Email + "\""; var response_okta = client.GetAsync(Geturl).Result; //initialized couple of variables var jsonResponse = ""; List <Web.Models.OktaUser.Users> user_okta = new List <Web.Models.OktaUser.Users>(); //user_okta = new Web.Models.OktaUser.Users(); if (response_okta.IsSuccessStatusCode) { //if the call was succesful get the results jsonResponse = response_okta.Content.ReadAsStringAsync().Result; //deserialized the JSON response into a list user_okta = Newtonsoft.Json.JsonConvert. DeserializeObject <List <Web.Models.OktaUser.Users> >(jsonResponse); user.USR_OKTAID = user_okta[0].id; } return(View(user)); }
public ActionResult Create() { //Roles role = new Roles(); OKTAServiceRepository okta = new OKTAServiceRepository(); var Okta = okta.GetUserProfile(HttpContext.GetOwinContext().Authentication.User.Claims); var IsSuperAdmin = db.IsSuperAdmin(Okta.email); if (!IsSuperAdmin) { ViewBag.RoleExistMessage = "Please contact HANYS Admin to create"; } return(View()); }
public ActionResult IsSuperAdminUser() { try { OKTAServiceRepository oktaSR = new OKTAServiceRepository(); var Okta = oktaSR.GetUserProfile(HttpContext.GetOwinContext().Authentication.User.Claims); ViewBag.IsSuperAdminUser = db.IsSuperAdmin(Okta.email) ? true : false; return(PartialView("admin")); } catch (Exception) { throw; } }
public ActionResult ReActivateUser(string id) { OKTAServiceRepository okta = new OKTAServiceRepository(); var Okta = okta.GetUserProfile(HttpContext.GetOwinContext().Authentication.User.Claims); var IsSuperAdmin = db.IsSuperAdmin(Okta.email); if (!IsSuperAdmin) { ViewBag.RoleExistMessage = "Please contact HANYS Admin to reactive user"; } //if (id == null) //{ // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); //} var client = new HttpClient(); //assign the API URL call client.BaseAddress = new Uri(APIuri + "/v1/"); //Set up the header for the API call client.DefaultRequestHeaders.Clear(); //set up the API header by including the API key located at web.config client.DefaultRequestHeaders.Add("Authorization", "SSWS " + APIkey); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); string json = ""; var httpContent = new StringContent(json, Encoding.Default, "application/json"); string Postuser; Postuser = "******" + id + "/lifecycle/reset_password?sendEmail=true"; //Call the Okta apps API to get a list of all available apps var response = client.PostAsync(Postuser, httpContent).Result; //initialized couple of variables var jsonResponse = ""; response.Content.ToString(); if (response.IsSuccessStatusCode) { //if the call was succesful get the results jsonResponse = response.Content.ReadAsStringAsync().Result; } return(RedirectToAction("GetUsers")); }
// GET: Reports public ActionResult Index() { ServiceRepository serviceObj = new ServiceRepository(); ViewBag.Years = serviceObj.GetYears(); OKTAServiceRepository okta = new OKTAServiceRepository(); var Okta = okta.GetUserProfile(HttpContext.GetOwinContext().Authentication.User.Claims); var IsSuperAdmin = db.IsSuperAdmin(Okta.email); return(View(new UserModel() { USR_IsAdmin = IsSuperAdmin })); }
public ActionResult DeleteConfirmed(int id) { OKTAServiceRepository okta = new OKTAServiceRepository(); var Okta = okta.GetUserProfile(HttpContext.GetOwinContext().Authentication.User.Claims); var IsSuperAdmin = db.IsSuperAdmin(Okta.email); if (Okta.userName.Length > 0 && IsSuperAdmin) { db.DeleteRole(id); } if (!IsSuperAdmin) { ViewBag.RoleExistMessage = "Please contact HANYS Admin to delete"; } return(RedirectToAction("Index")); }
public ActionResult Create(UserRoleModel objuserRole) { OKTAServiceRepository okta = new OKTAServiceRepository(); var Okta = okta.GetUserProfile(HttpContext.GetOwinContext().Authentication.User.Claims); var IsSuperAdmin = db.IsSuperAdmin(Okta.email); if (!IsSuperAdmin) { ViewBag.RoleExistMessage = "Please contact HANYS Admin to create"; } UserRole userRole = objuserRole.UserRole; ServiceRepository api = new ServiceRepository(); if (userRole.Id > 0) { ServiceRepository serviceObj = new ServiceRepository(); HttpResponseMessage response = serviceObj.PutResponse("userroles/PutUserRole", userRole); response.EnsureSuccessStatusCode(); return(new JsonResult { Data = new { status = true, message = "Role updated succesfully" } }); } else { var APIData = api.GetServiceResponse("userroles?id=" + userRole.UserID + "&roleId=" + userRole.RoleID); bool isUserRoleExist = JsonConvert.DeserializeObject <bool>(JsonConvert.DeserializeObject(APIData).ToString()); if (isUserRoleExist) { ViewBag.RoleExistMessage = "Role already assigned to this user"; //return View(); } else { ServiceRepository serviceObj = new ServiceRepository(); HttpResponseMessage response = serviceObj.PostResponse("userroles/PostUserRole", userRole); response.EnsureSuccessStatusCode(); } } return(RedirectToAction("Index", new { Id = userRole.UserID })); }
public ActionResult Edit([Bind(Include = "Id,Name,Description,Active,Current")] Roles role) { OKTAServiceRepository okta = new OKTAServiceRepository(); var Okta = okta.GetUserProfile(HttpContext.GetOwinContext().Authentication.User.Claims); var IsSuperAdmin = db.IsSuperAdmin(Okta.email); if (Okta.userName.Length > 0 && ModelState.IsValid && (role.Name == role.Current || (role.Name != role.Current && !IsRoleExists(role.Name))) && IsSuperAdmin) { role.CreatedBy = Okta.userName; role.UpdatedBy = Okta.userName; db.PutRole(role.Id, role); return(RedirectToAction("Index")); } if (!IsSuperAdmin) { ViewBag.RoleExistMessage = "Please contact HANYS Admin to edit"; } return(View(role)); }
public ActionResult HospitalSelection(int HosId = 0) { try { OKTAServiceRepository okta = new OKTAServiceRepository(); var Okta = okta.GetUserProfile(HttpContext.GetOwinContext().Authentication.User.Claims); if (!db.IsSuperAdmin(Okta.email)) { ViewBag.Hospitals = msr_db.GetHospitals(HosId, Okta.email); } else { ViewBag.Hospitals = msr_db.GetHospitals(HosId, string.Empty); } return(PartialView("HospitalSelection")); } catch (Exception) { throw; } }
public ActionResult Create() { OKTAServiceRepository okta = new OKTAServiceRepository(); var Okta = okta.GetUserProfile(HttpContext.GetOwinContext().Authentication.User.Claims); var IsSuperAdmin = db.IsSuperAdmin(Okta.email); if (!IsSuperAdmin) { ViewBag.RoleExistMessage = "Please contact HANYS Admin to create"; } List <Roles> objRoles = GetRoles(); objRoles.Add(new Roles() { Id = 0, Name = "Please Select a Role" }); return(View(new UserModel() { Roles = objRoles.OrderBy(o => o.Id).ToList() })); }
public ActionResult Delete(int id, int?usrId) { OKTAServiceRepository okta = new OKTAServiceRepository(); var Okta = okta.GetUserProfile(HttpContext.GetOwinContext().Authentication.User.Claims); var IsSuperAdmin = db.IsSuperAdmin(Okta.email); if (!IsSuperAdmin) { ViewBag.RoleExistMessage = "Please contact HANYS Admin to delete"; } ServiceRepository serviceObj = new ServiceRepository(); HttpResponseMessage response = serviceObj.DeleteResponse("userroles/DeleteUserRole?id=" + id); if (usrId == 0) { return(RedirectToAction("Index")); } else { return(RedirectToAction("Index", new { Id = usrId })); } }
// GET: Measures/Edit/1 public ActionResult Edit(int?id, int HosId = 0, int FromYear = 0) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } OKTAServiceRepository okta = new OKTAServiceRepository(); var Okta = okta.GetUserProfile(HttpContext.GetOwinContext().Authentication.User.Claims); if (!roleDB.IsSuperAdmin(Okta.email)) { ViewBag.Hospitals = db.GetHospitals(HosId, Okta.email); } else { ViewBag.Hospitals = db.GetHospitals(HosId, string.Empty); } ViewBag.FromYear = db.GetYears(FromYear); MeasuresData measuresData = new MeasuresData(); try { measuresData = db.GetMeasuresData((int)id, HosId, FromYear); } catch (Exception ex) { measuresData = new MeasuresData() { Measures = new List <Measure>() }; Console.WriteLine(ex); } return(View(measuresData)); }
// GET: UserRoles public ActionResult Index(string sortOrder, string currentFilter, string searchString, int?page, string Id) { OKTAServiceRepository okta = new OKTAServiceRepository(); var Okta = okta.GetUserProfile(HttpContext.GetOwinContext().Authentication.User.Claims); ServiceRepository api = new ServiceRepository(); var APIData = api.GetServiceResponse("userroles"); ViewBag.Id = Id; ViewBag.CurrentSort = sortOrder; ViewBag.UserNameSortParm = (string.IsNullOrEmpty(sortOrder) || sortOrder == "UserName") ? "UserName_desc" : "UserName"; ViewBag.RoleSortParm = sortOrder == "Role" ? "Role_desc" : "Role"; ViewBag.OrganizationNameSortParm = sortOrder == "OrganizationName" ? "OrganizationName_desc" : "OrganizationName"; if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; var userroles = JsonConvert.DeserializeObject <List <UserRole> >(JsonConvert.DeserializeObject(APIData).ToString()); if (Convert.ToInt32(Id) > 0) { userroles = userroles.Where(w => w.UserID == (Convert.ToInt32(Id))).ToList(); } if (!string.IsNullOrEmpty(searchString)) { userroles = userroles.Where(s => s.UserName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower()) || s.RoleName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower()) || s.OrganizationName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower())).ToList(); } switch (sortOrder) { case "UserName": userroles = userroles.OrderBy(m => m.UserName).ToList(); break; case "UserName_desc": userroles = userroles.OrderByDescending(m => m.UserName).ToList(); break; case "Role": userroles = userroles.OrderBy(m => m.RoleName).ToList(); break; case "Role_desc": userroles = userroles.OrderByDescending(m => m.RoleName).ToList(); break; case "OrganizationName": userroles = userroles.OrderBy(m => m.OrganizationName).ToList(); break; case "OrganizationName_desc": userroles = userroles.OrderByDescending(m => m.OrganizationName).ToList(); break; case "Default": userroles = userroles.OrderBy(m => m.UserName).ToList(); break; } int pageSize = 10; int pageNumber = (page ?? 1); UserRoleModel obj = new UserRoleModel() { UserRoles = userroles.ToPagedList(pageNumber, pageSize), UserRole = GetUserrole(Convert.ToInt32(Id)) }; if (!db.IsSuperAdmin(Okta.email)) { obj = new UserRoleModel(); } return(View(obj)); }
public ActionResult Index(string SortOrder, string CurrentFilter, string SearchString, int?Page, bool SearchRoleName = true, bool SearchDescription = true) { OKTAServiceRepository okta = new OKTAServiceRepository(); var Okta = okta.GetUserProfile(HttpContext.GetOwinContext().Authentication.User.Claims); ViewBag.CurrentSort = SortOrder; ViewBag.NameSortParm = (string.IsNullOrEmpty(SortOrder) || SortOrder == "Name") ? "Name_desc" : "Name"; ViewBag.DescriptionSortParm = SortOrder == "Description" ? "Description_desc" : "Description"; ViewBag.UserCountSortParm = SortOrder == "UserCount" ? "UserCount_desc" : "UserCount"; ViewBag.ActiveTextSortParm = SortOrder == "ActiveText" ? "ActiveText_desc" : "ActiveText"; if (SearchRoleName == false && SearchDescription == false) { SearchRoleName = true; SearchDescription = true; } if (SearchString != null) { Page = 1; } else { SearchString = CurrentFilter; } ViewBag.CurrentFilter = SearchString; ViewBag.RoleNameFilter = SearchRoleName; ViewBag.DescriptionFilter = SearchDescription; var roles = db.GetRoles(); if (!string.IsNullOrEmpty(SearchString)) { SearchString = SearchString.Replace(" ", string.Empty).ToLower(); if (SearchRoleName == true && SearchDescription == true) { roles = roles.Where(s => s.Name.Replace(" ", string.Empty).ToLower().Contains(SearchString) || s.Description.Replace(" ", string.Empty).ToLower().Contains(SearchString)).ToList(); } else if (SearchRoleName == true) { roles = roles.Where(s => s.Name.Replace(" ", string.Empty).ToLower().Contains(SearchString)).ToList(); } else if (SearchDescription == true) { roles = roles.Where(s => s.Description.Replace(" ", string.Empty).ToLower().Contains(SearchString)).ToList(); } } switch (SortOrder) { case "Name": roles = roles.OrderBy(s => s.Name).ToList(); break; case "Name_desc": roles = roles.OrderByDescending(s => s.Name).ToList(); break; case "Description": roles = roles.OrderBy(s => s.Description).ToList(); break; case "Description_desc": roles = roles.OrderByDescending(s => s.Description).ToList(); break; case "UserCount": roles = roles.OrderBy(s => s.UserCount).ToList(); break; case "UserCount_desc": roles = roles.OrderByDescending(s => s.UserCount).ToList(); break; case "ActiveText": roles = roles.OrderBy(s => s.Active).ToList(); break; case "ActiveText_desc": roles = roles.OrderByDescending(s => s.Active).ToList(); break; default: roles = roles.OrderBy(s => s.Name).ToList(); break; } if (!db.IsSuperAdmin(Okta.email)) { roles = new List <Roles>(); } int PageNumber = (Page ?? 1); int PageSize = 10; return(View(roles.ToPagedList(PageNumber, PageSize))); }
public ActionResult Delete(int id, string email) { OKTAServiceRepository okta = new OKTAServiceRepository(); var Okta = okta.GetUserProfile(HttpContext.GetOwinContext().Authentication.User.Claims); var IsSuperAdmin = db.IsSuperAdmin(Okta.email); if (!IsSuperAdmin) { ViewBag.RoleExistMessage = "Please contact HANYS Admin to delete"; } ServiceRepository serviceObj = new ServiceRepository(); HttpResponseMessage response = serviceObj.DeleteResponse("user/DeleteUserMaster?id=" + id); var client = new HttpClient(); //assign the API URL call client.BaseAddress = new Uri(APIuri + "/v1/"); //Set up the header for the API call client.DefaultRequestHeaders.Clear(); //set up the API header by including the API key located at web.config client.DefaultRequestHeaders.Add("Authorization", "SSWS " + APIkey); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); string oktaID = ""; string Geturl = ""; Geturl = "users?search=profile.email eq \"" + email + "\""; var response_okta = client.GetAsync(Geturl).Result; //initialized couple of variables var jsonResponse = ""; List <Web.Models.OktaUser.Users> user_okta = new List <Web.Models.OktaUser.Users>(); //user_okta = new Web.Models.OktaUser.Users(); if (response_okta.IsSuccessStatusCode) { //if the call was succesful get the results jsonResponse = response_okta.Content.ReadAsStringAsync().Result; //deserialized the JSON response into a list user_okta = Newtonsoft.Json.JsonConvert. DeserializeObject <List <Web.Models.OktaUser.Users> >(jsonResponse); oktaID = user_okta[0].id; } string Postuser = ""; Postuser = "******" + PFPGroupID + "/users/" + oktaID; //Call the Okta apps API to get a list of all available apps response = client.DeleteAsync(Postuser).Result; //initialized couple of variables jsonResponse = ""; response.Content.ToString(); if (response.IsSuccessStatusCode) { jsonResponse = response.Content.ReadAsStringAsync().Result; } return(RedirectToAction("GetUsers")); }
public ActionResult EditUser(UserModel user) { OKTAServiceRepository okta = new OKTAServiceRepository(); var Okta = okta.GetUserProfile(HttpContext.GetOwinContext().Authentication.User.Claims); var IsSuperAdmin = db.IsSuperAdmin(Okta.email); if (!IsSuperAdmin) { ViewBag.RoleExistMessage = "Please contact HANYS Admin to edit"; } if (ModelState.IsValid && !string.IsNullOrEmpty(user.USR_Email) && !IsUserExists(user) && ValidateHospital(user.USR_OrganizationName) && IsSuperAdmin) { ServiceRepository serviceObj = new ServiceRepository(); user.USR_Active = true; HttpResponseMessage response = serviceObj.PutResponse("user/PutUserMaster", user); var client = new HttpClient(); //assign the API URL call client.BaseAddress = new Uri(APIuri + "/v1/"); //Set up the header for the API call client.DefaultRequestHeaders.Clear(); //set up the API header by including the API key located at web.config client.DefaultRequestHeaders.Add("Authorization", "SSWS " + APIkey); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); CreateOktaUser OktaUser = new CreateOktaUser(); OktaUser.email = user.USR_Email; OktaUser.firstName = user.USR_FirstName; OktaUser.lastName = user.USR_LastName; OktaUser.login = user.USR_Email; OktaUser.secondEmail = null; OktaUser.middleName = null; OktaUser.mobilePhone = null; string json = Newtonsoft.Json.JsonConvert.SerializeObject(OktaUser); json = json.Replace("{", "{\"profile\": {"); json = json.Replace("}", "}}"); var httpContent = new StringContent(json, Encoding.Default, "application/json"); string Postuser; Postuser = "******" + user.USR_OKTAID; //Call the Okta apps API to get a list of all available apps response = client.PostAsync(Postuser, httpContent).Result; //initialized couple of variables var jsonResponse = ""; response.Content.ToString(); if (response.IsSuccessStatusCode) { //if the call was succesful get the results jsonResponse = response.Content.ReadAsStringAsync().Result; //Message on successful user creation //var messageModel = new MessageModel(); } return(RedirectToAction("Index", "Userroles", new { Id = user.USR_Id })); } else { return(View(user)); } }
// GET: User public ActionResult GetUsers(string sortOrder, string currentFilter, string searchString, int?page) { OKTAServiceRepository okta = new OKTAServiceRepository(); var Okta = okta.GetUserProfile(HttpContext.GetOwinContext().Authentication.User.Claims); ServiceRepository serviceObj = new ServiceRepository(); HttpResponseMessage response = serviceObj.GetResponse("user?GetUserMasters"); ViewBag.CurrentSort = sortOrder; ViewBag.FirstNameSortParm = (string.IsNullOrEmpty(sortOrder) || sortOrder == "FirstName") ? "FirstName_desc" : "FirstName"; ViewBag.LastNameSortParm = sortOrder == "LastName" ? "LastName_desc" : "LastName"; ViewBag.EmailSortParm = sortOrder == "Email" ? "Email_desc" : "Email"; ViewBag.PhoneSortParm = sortOrder == "Phone" ? "Phone_desc" : "Phone"; ViewBag.OrganizationNameSortParm = sortOrder == "OrganizationName" ? "OrganizationName_desc" : "OrganizationName"; bool firstNameSearch = Request.Form.GetValues("FirstNameCheckbox") != null?Request.Form.GetValues("FirstNameCheckbox")[0] == "on" : false; bool organizationNameSearch = Request.Form.GetValues("OrganizationNameCheckBox") != null?Request.Form.GetValues("OrganizationNameCheckBox")[0] == "on" : false; bool lastNameSearch = Request.Form.GetValues("LastNameCheckbox") != null?Request.Form.GetValues("LastNameCheckbox")[0] == "on" : false; bool emailSearch = Request.Form.GetValues("EmailCheckbox") != null?Request.Form.GetValues("EmailCheckbox")[0] == "on" : false; if (searchString != null) { page = 1; if (firstNameSearch) { ViewBag.firstNameSearch = "Checked"; } if (organizationNameSearch) { ViewBag.organizationNameSearch = "Checked"; } if (lastNameSearch) { ViewBag.lastNameSearch = "Checked"; } if (emailSearch) { ViewBag.emailSearch = "Checked"; } } else { searchString = currentFilter; ViewBag.firstNameSearch = "Checked"; ViewBag.organizationNameSearch = "Checked"; ViewBag.lastNameSearch = "Checked"; ViewBag.emailSearch = "Checked"; } ViewBag.CurrentFilter = searchString; var users = response.Content.ReadAsAsync <List <UserModel> >().Result; // OKTA Call to get user ID from Email address ******************************************************************* var client = new HttpClient(); //assign the API URL call client.BaseAddress = new Uri(APIuri + "/v1/"); //Set up the header for the API call client.DefaultRequestHeaders.Clear(); //set up the API header by including the API key located at web.config client.DefaultRequestHeaders.Add("Authorization", "SSWS " + APIkey); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); string oktaID = ""; string Geturl = ""; foreach (UserModel user in users) { Geturl = "users?search=profile.email eq \"" + user.USR_Email + "\""; var response_okta = client.GetAsync(Geturl).Result; //initialized couple of variables var jsonResponse = ""; List <Web.Models.OktaUser.Users> user_okta = new List <Web.Models.OktaUser.Users>(); //user_okta = new Web.Models.OktaUser.Users(); if (response_okta.IsSuccessStatusCode) { //if the call was succesful get the results jsonResponse = response_okta.Content.ReadAsStringAsync().Result; //deserialized the JSON response into a list user_okta = Newtonsoft.Json.JsonConvert. DeserializeObject <List <Web.Models.OktaUser.Users> >(jsonResponse); if (user_okta.Count >= 1) { user.USR_OKTAID = user_okta[0].id; } } } if (!string.IsNullOrEmpty(searchString)) { if (firstNameSearch && organizationNameSearch && lastNameSearch && emailSearch) { users = users.Where(s => s.USR_FirstName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower()) || s.USR_OrganizationName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower()) || s.USR_LastName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower()) || s.USR_Email.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower())).ToList(); } else if (firstNameSearch && organizationNameSearch && lastNameSearch) { users = users.Where(s => s.USR_FirstName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower()) || s.USR_OrganizationName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower()) || s.USR_LastName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower())).ToList(); } else if (firstNameSearch && organizationNameSearch && emailSearch) { users = users.Where(s => s.USR_FirstName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower()) || s.USR_OrganizationName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower()) || s.USR_Email.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower())).ToList(); } else if (firstNameSearch && emailSearch && lastNameSearch) { users = users.Where(s => s.USR_FirstName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower()) || s.USR_Email.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower()) || s.USR_LastName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower())).ToList(); } else if (emailSearch && organizationNameSearch && lastNameSearch) { users = users.Where(s => s.USR_Email.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower()) || s.USR_OrganizationName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower()) || s.USR_LastName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower())).ToList(); } else if (firstNameSearch && organizationNameSearch) { users = users.Where(s => s.USR_FirstName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower()) || s.USR_OrganizationName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower())).ToList(); } else if (firstNameSearch && emailSearch) { users = users.Where(s => s.USR_FirstName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower()) || s.USR_Email.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower())).ToList(); } else if (lastNameSearch && emailSearch) { users = users.Where(s => s.USR_LastName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower()) || s.USR_Email.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower())).ToList(); } else if (organizationNameSearch && emailSearch) { users = users.Where(s => s.USR_OrganizationName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower()) || s.USR_Email.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower())).ToList(); } else if (lastNameSearch && organizationNameSearch) { users = users.Where(s => s.USR_LastName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower()) || s.USR_OrganizationName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower())).ToList(); } else if (firstNameSearch && lastNameSearch) { users = users.Where(s => s.USR_FirstName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower()) || s.USR_LastName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower())).ToList(); } else if (firstNameSearch) { users = users.Where(s => s.USR_FirstName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower())).ToList(); } else if (lastNameSearch) { users = users.Where(s => s.USR_LastName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower())).ToList(); } else if (emailSearch) { users = users.Where(s => s.USR_Email.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower())).ToList(); } else if (organizationNameSearch) { users = users.Where(s => s.USR_OrganizationName.Replace(" ", string.Empty).ToLower().Contains(searchString.Replace(" ", string.Empty).ToLower())).ToList(); } } switch (sortOrder) { case "FirstName": users = users.OrderBy(m => m.USR_FirstName).ToList(); break; case "FirstName_desc": users = users.OrderByDescending(m => m.USR_FirstName).ToList(); break; case "LastName": users = users.OrderBy(m => m.USR_LastName).ToList(); break; case "LastName_desc": users = users.OrderByDescending(m => m.USR_LastName).ToList(); break; case "Email": users = users.OrderBy(m => m.USR_Email).ToList(); break; case "Email_desc": users = users.OrderByDescending(m => m.USR_Email).ToList(); break; case "Phone": users = users.OrderBy(m => m.USR_Email).ToList(); break; case "Phone_desc": users = users.OrderByDescending(m => m.USR_Email).ToList(); break; case "OrganizationName": users = users.OrderBy(m => m.USR_Email).ToList(); break; case "OrganizationName_desc": users = users.OrderByDescending(m => m.USR_Email).ToList(); break; case "Default": users = users.OrderBy(m => m.USR_FirstName).ToList(); break; } if (!db.IsSuperAdmin(Okta.email)) { users = new List <UserModel>(); } int pageSize = 10; int pageNumber = (page ?? 1); return(View(users.ToPagedList(pageNumber, pageSize))); }
public ActionResult Create(UserModel user) { OKTAServiceRepository okta = new OKTAServiceRepository(); var Okta = okta.GetUserProfile(HttpContext.GetOwinContext().Authentication.User.Claims); var IsSuperAdmin = db.IsSuperAdmin(Okta.email); if (!IsSuperAdmin) { ViewBag.RoleExistMessage = "Please contact HANYS Admin to create"; } // UserServiceRepository serviceObj = new UserServiceRepository(); // user.USR_Active = true; //HttpResponseMessage response = serviceObj.PostResponse("user/PostUserMaster", user); // response.EnsureSuccessStatusCode(); int flag = 0; // return RedirectToAction("GetUsers"); if (ModelState.IsValid && !string.IsNullOrEmpty(user.USR_Email) && !IsUserExists(user) && ValidateHospital(user.USR_OrganizationName) && IsSuperAdmin) { ServiceRepository serviceObj = new ServiceRepository(); user.USR_Active = true; HttpResponseMessage response = serviceObj.PostResponse("user/PostUserMaster", user); response.EnsureSuccessStatusCode(); var result = response.Content.ReadAsStringAsync().Result; user = JsonConvert.DeserializeObject <UserModel>(result); if (response.StatusCode == System.Net.HttpStatusCode.Created) { var client = new HttpClient(); //assign the API URL call client.BaseAddress = new Uri(APIuri + "/v1/"); //Set up the header for the API call client.DefaultRequestHeaders.Clear(); //set up the API header by including the API key located at web.config client.DefaultRequestHeaders.Add("Authorization", "SSWS " + APIkey); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); string Geturl = ""; Geturl = "users?search=profile.email eq \"" + user.USR_Email + "\""; var response_okta = client.GetAsync(Geturl).Result; //initialized couple of variables var jsonResponse = ""; List <Web.Models.OktaUser.Users> user_okta = new List <Web.Models.OktaUser.Users>(); //user_okta = new Web.Models.OktaUser.Users(); if (response_okta.IsSuccessStatusCode) { //if the call was succesful get the results jsonResponse = response_okta.Content.ReadAsStringAsync().Result; if (jsonResponse.Length > 2) { //deserialized the JSON response into a list user_okta = Newtonsoft.Json.JsonConvert. DeserializeObject <List <Web.Models.OktaUser.Users> >(jsonResponse); if (user_okta[0].status != "ACTIVE") { string PostuserActivation; PostuserActivation = "users/" + user_okta[0].id + "/lifecycle/activate?sendEmail=true"; string jsonActive = ""; var httpContent = new StringContent(jsonActive, Encoding.Default, "application/json"); response = client.PostAsync(PostuserActivation, httpContent).Result; //initialized couple of variables jsonResponse = ""; response.Content.ToString(); if (response.IsSuccessStatusCode) { //if the call was succesful get the results jsonResponse = response.Content.ReadAsStringAsync().Result; //Message on successful user creation //var messageModel = new MessageModel(); } } // assign user to pfp application string Postusergrp; Postusergrp = "groups/" + PFPGroupID + "/users/" + user_okta[0].id; string jsonuser = ""; StringContent httpContentuser = new StringContent(jsonuser, Encoding.Default, "application/json"); response = client.PutAsync(Postusergrp, httpContentuser).Result; //initialized couple of variables jsonResponse = ""; response.Content.ToString(); if (response.IsSuccessStatusCode) { //if the call was succesful get the results jsonResponse = response.Content.ReadAsStringAsync().Result; //Message on successful user creation //var messageModel = new MessageModel(); } } else { // New user Creation in OKTA CreateOktaUser OktaUser = new CreateOktaUser(); OktaUser.email = user.USR_Email; OktaUser.firstName = user.USR_FirstName; OktaUser.lastName = user.USR_LastName; OktaUser.login = user.USR_Email; string json = Newtonsoft.Json.JsonConvert.SerializeObject(OktaUser); json = json.Replace("{", "{\"profile\": {"); json = json.Replace("}", "}}"); var httpContent = new StringContent(json, Encoding.Default, "application/json"); string Postuser; Postuser = "******"; //Call the Okta apps API to get a list of all available apps response = client.PostAsync(Postuser, httpContent).Result; //initialized couple of variables jsonResponse = ""; response.Content.ToString(); if (response.IsSuccessStatusCode) { //if the call was succesful get the results jsonResponse = response.Content.ReadAsStringAsync().Result; //Message on successful user creation //var messageModel = new MessageModel(); } var obj = JObject.Parse(jsonResponse); var ID = (string)obj["id"]; // assign user to pfp application string Postusergrp; Postusergrp = "groups/" + PFPGroupID + "/users/" + ID; string jsonuser = ""; StringContent httpContentuser = new StringContent(jsonuser, Encoding.Default, "application/json"); response = client.PutAsync(Postusergrp, httpContentuser).Result; //initialized couple of variables jsonResponse = ""; response.Content.ToString(); if (response.IsSuccessStatusCode) { //if the call was succesful get the results jsonResponse = response.Content.ReadAsStringAsync().Result; //Message on successful user creation //var messageModel = new MessageModel(); } } } } return(RedirectToAction("Index", "Userroles", new { Id = user.USR_Id })); } else { return(View(user)); } }