public DeveloperPageDeveloper ToDeveloperPageDeveloper(Account account)
        {
            Require.NotNull(account, nameof(account));

            var role = _userRoleAnalyzer.GetUserCommonRole(account.UserId);

            var projectCount =
                _projectProvider.GetProjects(
                    project => project.ProjectMemberships.Any(
                        membership => membership.DeveloperId == account.UserId))
                    .Count;

            return new DeveloperPageDeveloper(
                account.UserId,
                account.Firstname,
                account.Lastname,
                account.Profile?.Image?.SmallPhotoUri,
                role,
                account.RegistrationTime,
                projectCount,
                account.Profile?.VkProfileUri,
                account.Role,
                account.ConfirmationStatus,
                account.IsHidden);
        }
        public Developer ToDeveloper(Account account)
        {
            Require.NotNull(account, nameof(account));

            var userProjects = _projectProvider.GetProjects(
                project => project.ProjectMemberships.Any(
                    membership => membership.DeveloperId == account.UserId));
            var projectPreviews = GetDeveloperProjectPreviews(account, userProjects);

            return new Developer(
                account.UserId,
                account.Firstname,
                account.Lastname,
                account.Email.Address,
                account.RedmineUserId,
                account.GitlabUserId,
                account.ConfirmationStatus,
                account.Profile.Image?.BigPhotoUri,
                account.RegistrationTime,
                account.Profile.VkProfileUri,
                account.Profile.PhoneNumber,
                account.Profile.StudentAccessionYear,
                account.Profile.StudyingDirection,
                account.Profile.InstituteName,
                account.Profile.Specialization,
                _userRoleAnalyzer.GetUserCommonRole(account.UserId),
                projectPreviews.ToArray());
        }
        public void ChangeUserPassword(Account account, string newPassword)
        {
            Require.NotNull(account, nameof(account));
            Require.NotEmpty(newPassword, nameof(newPassword));

            var user = new UserUpsert
            {
                Password = newPassword
            };

            _gitLabClient.Users.Update(account.GitlabUserId, user);
        }
        public void ChangeUserPassword(Account account, string newPassword)
        {
            Require.NotNull(account, nameof(account));

            var user = new RedmineUser
            {
                Id = account.RedmineUserId,
                Password = newPassword
            };

            var client = new HttpClient();
            var address = _redmineSettings.RedmineHost + $"/users/{account.RedmineUserId}.json";
            var authHeaderByteArray = Encoding.ASCII.GetBytes($"{_redmineSettings.ApiKey}:pass");
            client.DefaultRequestHeaders.Authorization
                = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(authHeaderByteArray));
            client.PutAsync(
                address,
                user,
                new XmlMediaTypeFormatter { UseXmlSerializer = true });
        }
        public int RegisterUser(Account account)
        {
            Require.NotNull(account, nameof(account));

            var user = new RedmineUser
            {
                Email = account.Email.Address,
                Login = GetLoginForLastname(account.Lastname),
                FirstName = account.Firstname,
                LastName = account.Lastname,
                Password = account.Password.Value,
                MustChangePassword = false
            };

            var client = new HttpClient();
            var address = _redmineSettings.RedmineHost + "/users.json";
            var authHeaderByteArray = Encoding.ASCII.GetBytes($"{_redmineSettings.ApiKey}:pass");
            client.DefaultRequestHeaders.Authorization
                = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(authHeaderByteArray));
            var response = client.PostAsync(
                address,
                user,
                new XmlMediaTypeFormatter {UseXmlSerializer = true}).Result;
            var createdUserString = response.Content.ReadAsStringAsync().Result;
            var createdUser = JObject.Parse(createdUserString);
            return (int)createdUser["user"]["id"];
        }
        public int RegisterUser(Account account)
        {
            var user = new UserUpsert
            {
                Email = account.Email.Address,
                IsAdmin = false,
                Password = account.Password.Value, //todo
                ProjectsLimit = 0,
                Name = account.Firstname + " " + account.Lastname,
                CanCreateGroup = false,
                Confirm = "no",
                Username = GetUserNameByLastName(account.Lastname)
            };

            var addedUser = _gitLabClient.Users.Create(user);
            return addedUser.Id;
        }
        public GuestDeveloper ToGuestDeveloper(Account account)
        {
            Require.NotNull(account, nameof(account));

            var projectList = _projectProvider.GetProjects(
                project => project.ProjectMemberships.Any(
                    membership => membership.DeveloperId == account.UserId))
                .Where(ProjectsPolicies.OnlyDoneOrInProgress)
                .Where(ProjectsPolicies.OnlyPublic);
            var projectPreviews = GetDeveloperProjectPreviews(account, projectList.ToList());

            return new GuestDeveloper(
                account.UserId,
                account.Firstname,
                account.Lastname,
                account.Profile?.Image?.BigPhotoUri,
                account.RegistrationTime,
                account.Profile?.VkProfileUri,
                account.Profile?.StudentAccessionYear,
                account.Profile?.StudyingDirection,
                account.Profile?.InstituteName,
                account.Profile?.Specialization,
                _userRoleAnalyzer.GetUserCommonRole(account.UserId),
                projectPreviews.ToArray());
        }
 private IEnumerable<DeveloperPageProjectPreview> GetDeveloperProjectPreviews(
     Account account,
     List<Project> userProjects)
 {
     var projectPreviews = userProjects.Select(
         project => ToDeveloperPageProjectPreview(account.UserId, project));
     return projectPreviews;
 }
        public IndexPageDeveloper ToIndexPageDeveloper(Account account)
        {
            Require.NotNull(account, nameof(account));

            var role = _userRoleAnalyzer.GetUserCommonRole(account.UserId);
            return new IndexPageDeveloper(
                account.UserId,
                account.Firstname,
                account.Lastname,
                account.Profile.Image?.SmallPhotoUri,
                role);
        }