public async Task <UsersResponseModel> Get()
        {
            var resultUsers = new List <UserResponseModel>();

            foreach (var user in _userManager.Users)
            {
                var roles = await _userManager.GetRolesAsync(user);

                resultUsers.Add(new UserResponseModel
                {
                    Id       = user.Id,
                    UserName = user.UserName,
                    Roles    = roles.ToList(),
                    Customer = _mapper.Map <Customer, CustomerResponseModel>(user.Customer)
                });
            }

            var result = new UsersResponseModel
            {
                Users        = resultUsers,
                AllRoles     = _roleManager.Roles.Select(e => e.Name),
                AllCustomers =
                    _mapper.Map <IEnumerable <Customer>, IEnumerable <CustomerResponseModel> >(_databaseContext.Customers)
            };

            return(result);
        }
Esempio n. 2
0
        public UsersResponseModel deleteorModifyEmployee(EmployeeDeleteRequestModel employeeDeleteRequest, out ErrorModel errorModel)
        {
            errorModel = null;
            UsersResponseModel usersResponseModel = null;
            SqlConnection      connection         = null;

            try
            {
                using (connection = new SqlConnection(Database.getConnectionString()))
                {
                    SqlCommand command = new SqlCommand(SqlCommands.SP_deleteorModifyEmployee, connection);
                    command.CommandType = System.Data.CommandType.StoredProcedure;

                    #region Commands Parameters

                    command.Parameters.Add(new SqlParameter("@isDelete", System.Data.SqlDbType.Bit));
                    command.Parameters["@isDelete"].Value = employeeDeleteRequest.isDelete;

                    command.Parameters.Add(new SqlParameter("@userId", System.Data.SqlDbType.Int));
                    command.Parameters["@userId"].Value = employeeDeleteRequest.userId;

                    #endregion
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();

                    usersResponseModel = new UsersResponseModel();
                    if (reader.Read())
                    {
                        if (reader.isColumnExists("ErrorCode"))
                        {
                            errorModel              = new ErrorModel();
                            errorModel.ErrorCode    = reader["ErrorCode"].ToString();
                            errorModel.ErrorMessage = reader["ErrorMessage"].ToString();
                        }
                        else
                        {
                            usersResponseModel.UserId   = Convert.ToInt32(reader["UserId"].ToString());
                            usersResponseModel.UserType = Convert.ToInt32(reader["UserTypeId"].ToString());
                        }
                    }
                    command.Dispose();
                    return(usersResponseModel);
                }
            }
            catch (Exception exception)
            {
                errorModel = new ErrorModel();
                errorModel.ErrorMessage = exception.Message;
                return(null);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
        }
Esempio n. 3
0
        public List <UsersResponseModel> getUsers(int userType, /*string email,*/ out ErrorModel errorModel)
        {
            errorModel = null;
            List <UsersResponseModel> users      = null;
            SqlConnection             connection = null;

            try
            {
                using (connection = new SqlConnection(Database.getConnectionString()))
                {
                    SqlCommand command = new SqlCommand(SqlCommands.SP_getUsers, connection);
                    command.CommandType = System.Data.CommandType.StoredProcedure;

                    #region Query Parameters


                    command.Parameters.Add(new SqlParameter("@userTypeId", System.Data.SqlDbType.Int));
                    command.Parameters["@userTypeId"].Value = userType;

                    #endregion
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    users = new List <UsersResponseModel>();
                    while (reader.Read())
                    {
                        if (reader.isColumnExists("ErrorCode"))
                        {
                            errorModel              = new ErrorModel();
                            errorModel.ErrorCode    = reader["ErrorCode"].ToString();
                            errorModel.ErrorMessage = reader["ErrorMessage"].ToString();
                        }
                        else
                        {
                            UsersResponseModel user = new UsersResponseModel();
                            user.UserId        = Convert.ToInt32(reader["Id"].ToString());
                            user.FirstName     = reader["FirstName"].ToString();
                            user.LastName      = reader["LastName"].ToString();
                            user.Email         = reader["Email"].ToString();
                            user.Phone         = reader["Phone"].ToString();
                            user.Image         = reader["Image"].ToString();
                            user.UserType      = Convert.ToInt32(reader["UserType"].ToString());
                            user.Gender        = reader["Gender"].ToString();
                            user.UserTypeTitle = reader["UserTypeTitle"].ToString();



                            users.Add(user);
                        }
                    }
                    command.Dispose();
                    connection.Close();
                }

                return(users);
            }
            catch (Exception exception)
            {
                errorModel = new ErrorModel();
                errorModel.ErrorMessage = exception.Message;
                return(null);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
        }