Ejemplo n.º 1
0
        public static List <UserDropDownModel> userDropDowns()
        {
            var users = new List <UserDropDownModel>();

            try
            {
                using (SqlConnection conn = new SqlConnection(DBConn))
                {
                    querry = $@"select UserID,Email from Users";
                    using (SqlCommand cmd = new SqlCommand(querry, conn))
                    {
                        conn.Open();
                        SqlDataReader rdr = cmd.ExecuteReader();
                        while (rdr.Read())
                        {
                            var user = new UserDropDownModel();
                            user.Email = rdr["Email"].ToString();
                            user.Id    = rdr["UserID"].ToString();
                            users.Add(user);
                        }
                    }
                }
            }catch (Exception e)
            {
                users = null;
            }
            return(users);
        }
Ejemplo n.º 2
0
        public UserDropDownModel GetUserDropDown(GraphServiceClient client)
        {
            UserDropDownModel retVal = null;

            try
            {
                if (client == null)
                {
                    _logger.LogWarn("UserService-GetUserDropDown: Graph client cannot be null");
                    return(retVal);
                }

                _logger.LogInfo("UserService-GetUserDropDown: Starting to get user drop down");

                retVal = new UserDropDownModel();

                // Password
                retVal.AutoPassword = GetRandomPassword();
                _logger.LogInfo("UserService-GetUserDropDown: Generated auto password for user drop down");

                //Groups
                GroupService groupService = new GroupService(_logger, null, null);
                retVal.Groups = groupService.GetGroups();

                //Roles
                retVal.UserRoles = GetUserRoles();

                //User Location
                CountryService countryService = new CountryService(_logger);
                var            countryResult  = countryService.GetCountries();

                if (countryResult != null)
                {
                    retVal.UserLocation = countryResult.Result.CountryModel;
                }

                // User Type
                retVal.UserTypes = GetUserTypes();

                //User Language
                retVal.UserLanguages = GetUserLanguage();

                //User Business Department
                retVal.UserBusinessDepartments = GetUserBusinessDepartments();

                _logger.LogInfo("UserService-GetUserDropDown: Completed getting user drop down");
            }
            catch (Exception ex)
            {
                retVal = null;
                _logger.LogError("UserService-GetUserDropDown: Exception occured....");
                _logger.LogError(ex);
            }
            return(retVal);
        }
Ejemplo n.º 3
0
        public async Task <UserDropDownModel> GetUserDropDownAsync()
        {
            UserDropDownModel retVal = null;

            try
            {
                retVal = new UserDropDownModel();

                var client = GraphClientUtility.GetGraphServiceClient();

                var loadUserDropDownTasks = new Task[]
                {
                    Task.Run(() => {
                        PasswordService.Logger = _logger;
                        retVal.AutoPassword    = PasswordService.GenerateNewPassword(GetRandomNumber(),
                                                                                     GetRandomNumber(), GetRandomNumber(), GetRandomNumber());
                    }),
                    Task.Run(() => {
                        GroupService groupService = new GroupService(_logger, null, null);
                        retVal.Groups             = groupService.GetGroups();
                    }),
                    Task.Run(() => retVal.UserRoles = GetUserRoles()),
                    Task.Run(() =>
                    {
                        CountryService countryService = new CountryService(_logger);
                        var countryResult             = countryService.GetCountries();

                        if (countryResult != null)
                        {
                            retVal.UserLocation = countryResult.Result.CountryModel;
                        }
                    }),
                    Task.Run(() => retVal.UserTypes               = GetUserTypes()),
                    Task.Run(() => retVal.UserLanguages           = GetUserLanguage()),
                    Task.Run(() => retVal.UserBusinessDepartments = GetUserBusinessDepartments()),
                };

                await Task.WhenAll(loadUserDropDownTasks);
            }
            catch (Exception ex)
            {
                retVal = null;
                _logger.LogError("UserService-GetUserDropDownAsync: Exception occured....");
                _logger.LogError(ex);
            }
            return(retVal);
        }
Ejemplo n.º 4
0
        public async Task <UserDropDownModel> GetUserDropDown()
        {
            UserDropDownModel userDropDownModel = new UserDropDownModel();

            try
            {
                userDropDownModel = await _userService.GetUserDropDownAsync();

                if (userDropDownModel == null)
                {
                    userDropDownModel = new UserDropDownModel();
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("UsersController-GetUserDropDown: Exception occurred...");
                _logger.LogError(ex);
            }

            return(userDropDownModel);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> GetUserDropDown()
        {
            try
            {
                UserDropDownModel retVal = new UserDropDownModel();

                _logger.LogInfo("UserController-GetUserDropDown: [Started] for getting users drop down");

                var client = GraphClientUtility.GetGraphServiceClient();

                if (client == null)
                {
                    _logger.LogError("UserController-GetUserDropDown:Unable to create object for graph client ");
                    return(NotFound());
                }

                UserService userService = new UserService(_logger);

                retVal = await userService.GetUserDropDownAsync(client);

                _logger.LogInfo($"UserController-GetUsers: Completed getting user drop down");

                return(Ok(retVal));
            }
            catch (ServiceException ex)
            {
                _logger.LogError("UserController-GetUserDropDown: Exception occured....");
                _logger.LogError(ex);
                if (ex.StatusCode == HttpStatusCode.BadRequest)
                {
                    return(BadRequest());
                }
                else
                {
                    return(NotFound());
                }
            }
        }
        public async Task OnGetAsync()
        {
            try
            {
                #region Default Selected List
                var gItems                 = new SelectList(new List <SelectListItem>());
                var roleItems              = new SelectList(new List <SelectListItem>());
                var userLocationItems      = new SelectList(new List <SelectListItem>());
                var userTypeItems          = new SelectList(new List <SelectListItem>());
                var languageItems          = new SelectList(new List <SelectListItem>());
                var userBusDepartmentItems = new SelectList(new List <SelectListItem>());
                #endregion

                UserDropDownModel userDropDownModel = null;
                HttpClient        httpClient        = new HttpClient();

                //var httpResponse = await httpClient.GetAsync("https://localhost:44366/api/User/userdropdown");
                var httpResponse = await httpClient.GetAsync($"{CareStreamConst.Base_Url}{CareStreamConst.Base_API}{CareStreamConst.Users_DropDown_Url}");

                if (httpResponse.IsSuccessStatusCode)
                {
                    var data = await httpResponse.Content.ReadAsStringAsync();

                    userDropDownModel = JsonConvert.DeserializeObject <UserDropDownModel>(data);
                }


                if (userDropDownModel != null)
                {
                    userModel.AutoGeneratePassword = true;
                    userModel.Password             = userDropDownModel.AutoPassword;

                    #region Group

                    if (userDropDownModel.Groups != null)
                    {
                        var itemList = new List <SelectListItem>();
                        foreach (var group in userDropDownModel.Groups)
                        {
                            try
                            {
                                var groupListItem = new SelectListItem
                                {
                                    Text  = group.Key,
                                    Value = group.Key
                                };

                                itemList.Add(groupListItem);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Error while assign group key {0}", group.Key);
                                Console.WriteLine(ex);
                            }
                        }

                        gItems = new SelectList(itemList, "Value", "Text");
                    }

                    #endregion

                    #region Roles

                    if (userDropDownModel.UserRoles != null)
                    {
                        var itemList = new List <SelectListItem>();
                        foreach (var role in userDropDownModel.UserRoles)
                        {
                            try
                            {
                                var roleListItem = new SelectListItem
                                {
                                    Text  = role.Value,
                                    Value = role.Key
                                };

                                itemList.Add(roleListItem);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Error while assign role for key {0}", role.Key);
                                Console.WriteLine(ex);
                            }
                        }

                        roleItems = new SelectList(itemList, "Value", "Text");
                    }

                    #endregion

                    #region User Location

                    if (userDropDownModel.UserLocation != null)
                    {
                        var itemList = new List <SelectListItem>();
                        foreach (var location in userDropDownModel.UserLocation)
                        {
                            try
                            {
                                var locationListItem = new SelectListItem
                                {
                                    Text  = location.CountryName,
                                    Value = location.CountryCode
                                };

                                itemList.Add(locationListItem);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Error while assign user location for key {0}", location.CountryCode);
                                Console.WriteLine(ex);
                            }
                        }

                        userLocationItems = new SelectList(itemList, "Value", "Text");
                    }

                    #endregion

                    #region User Types

                    if (userDropDownModel.UserTypes != null)
                    {
                        var itemList = new List <SelectListItem>();
                        foreach (var userType in userDropDownModel.UserTypes)
                        {
                            try
                            {
                                var userTypeListItem = new SelectListItem
                                {
                                    Text  = userType.Value,
                                    Value = userType.Key
                                };

                                itemList.Add(userTypeListItem);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Error while assign user type for key {0}", userType.Key);
                                Console.WriteLine(ex);
                            }
                        }

                        userTypeItems = new SelectList(itemList, "Value", "Text");
                    }

                    #endregion

                    #region Langauage

                    if (userDropDownModel.UserLanguages != null)
                    {
                        var itemList = new List <SelectListItem>();
                        foreach (var langauage in userDropDownModel.UserLanguages)
                        {
                            try
                            {
                                var langauageListItem = new SelectListItem
                                {
                                    Text  = langauage.Value,
                                    Value = langauage.Key
                                };

                                itemList.Add(langauageListItem);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Error while assign user langauage for key {0}", langauage.Key);
                                Console.WriteLine(ex);
                            }
                        }

                        languageItems = new SelectList(itemList, "Value", "Text");
                    }

                    #endregion

                    #region User Business Department

                    if (userDropDownModel.UserBusinessDepartments != null)
                    {
                        var itemList = new List <SelectListItem>();
                        foreach (var userBusinessDepartment in userDropDownModel.UserBusinessDepartments)
                        {
                            try
                            {
                                var userBusinessDepartmentListItem = new SelectListItem
                                {
                                    Text  = userBusinessDepartment.Value,
                                    Value = userBusinessDepartment.Key
                                };

                                itemList.Add(userBusinessDepartmentListItem);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Error while assign user business department for key {0}", userBusinessDepartment.Key);
                                Console.WriteLine(ex);
                            }
                        }

                        userBusDepartmentItems = new SelectList(itemList, "Value", "Text");
                    }

                    #endregion

                    ViewData["Group"]        = gItems;
                    ViewData["Roles"]        = roleItems;
                    ViewData["UserLocation"] = userLocationItems;
                    ViewData["UserType"]     = userTypeItems;
                    ViewData["Language"]     = languageItems;
                    ViewData["UserBusDep"]   = userBusDepartmentItems;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Expection occured while getting user drop down details");
                Console.WriteLine(ex);
            }
        }