Пример #1
0
        protected override Task <AddStudyGroupResponseDto> ExecuteAsync(AddStudyGroupRequestDto request, RequestContext context)
        {
            var longName     = request.StudyGroupName;
            var shortName    = request.StudyGroupShortcut;
            var universityId = request.UniversityId;

            // Check if the name of the group is uniq
            if (!_studyGroupRepository.IsStudyGroupNameUniq(universityId, longName))
            {
                throw new RequestException(_textService.Error_StudyGroupNameIsTaken(longName));
            }

            // Create url for the study group
            var studyGroupUrl = _stringStandardizationService.CreateUrl(shortName, url => _studyGroupRepository.TryGetStudyGroup(url) == null);

            // Create the study group
            var studyGroup = _studyGroupRepository.AddStudyGroup(universityId, shortName, longName, studyGroupUrl, request.PrimaryLanguage);

            // Create study group DTO
            // var studyGroupDto = studyGroup.;

            // Create the response
            var response = studyGroup.Include(g => g.University).Select(g => new AddStudyGroupResponseDto(g.Id /*, g.ShortName, g.University.LongName, g.University.Url*/)).Single();

            return(Task.FromResult(response));
        }
Пример #2
0
        protected override Task <AddCourseResponseDto> ExecuteAsync(AddCourseRequestDto request, RequestContext context)
        {
            // Get course information
            var name         = request.CourseName;
            var code         = request.CourseCode;
            var studyGroupId = request.StudyGroupId;

            // Get study group with university
            var faculty = _uniwikiContext
                          .StudyGroups
                          .Include(g => g.University)
                          .Single(g => g.Id == request.StudyGroupId);

            // Check if the course name is unique
            if (!_courseRepository.IsNameUnique(faculty.Id, name))
            {
                throw new RequestException(_textService.Error_CourseNameTaken(name));
            }

            // Create url for the course
            var url = _stringStandardizationService.CreateUrl(name, u => _courseRepository.IsCourseUrlUnique(faculty.Id, u));

            // Create the course
            var course = _courseRepository.AddCourse(code, name, context.UserId !.Value, faculty.Id, faculty.University.Url, url, faculty.Url);

            return(Task.FromResult(new AddCourseResponseDto(course.Id, course.Url, course.Url, course.Url)));
        }
        private void TestCreateUrlMethod(string input, string expected)
        {
            // Arrange
            var stringStandardizationService = new StringStandardizationService();

            // Act
            var actualString = stringStandardizationService.CreateUrl(input, s => true);

            // Assert
            Assert.AreEqual(expected, actualString);
        }
Пример #4
0
        protected override async Task <RegisterResponseDto> ExecuteAsync(RegisterRequestDto request, RequestContext context)
        {
            // Try to get profile
            var profile = _profileRepository.TryGetProfileByEmail(request.Email);

            // Email is already registered and confirmed
            if (profile != null && profile.IsConfirmed)
            {
                throw new RequestException(_textService.Error_EmailIsAlreadyUsed(request.Email));
            }

            // Register user if he is not registered yet
            if (profile == null)
            {
                // Get the name and surname
                var names = request.NameAndSurname.Split(new[] { ' ' }, 2);

                // Create url for the new profile
                var url = _stringStandardizationService.CreateUrl(request.NameAndSurname,
                                                                  u => _profileRepository.TryGetProfileByUrl(u) == null);

                // Get the hash from the password
                var password = _hashService.HashPassword(request.Password);

                // Create the profile
                profile = _profileRepository.AddProfile(request.Email, names[0], names[1], url, password.hashedPassword, password.salt, $"/img/profilePictures/no-profile-picture.jpg", _timeService.Now, false, AuthenticationLevel.PrimaryToken, request.HomeFacultyId);

                _uniwikiContext.SaveChanges();
            }

            // TODO: Set the recent courses
            // _recentCoursesService.SetAsRecentCourses(request.RecentCourses, profile.Id);

            // Send the confirmation email
            await _emailConfirmationSenderService.SendConfirmationEmail(profile.Id, profile.Email);

            return(new RegisterResponseDto(request.Email, profile.Id));
        }