public async Task <ApiResult> CheckCourseAsync(int userId, int courseId)
        {
            var result = default(ApiResult);

            // find user
            var user = await users.GetByIdAsync(userId);

            if (user == null)
            {
                var message       = "User not found";
                var loggerMessage = "Unable to fetch course data";
                var errors        = new string[] { message };
                result = ApiResult.GetErrorResult(ApiResultStatus.NotFound, loggerMessage, message, errors);
            }
            else
            {
                // find course
                var course = await courses.GetByIdAsync(courseId);

                if (course == null)
                {
                    var message       = "Course not found";
                    var loggerMessage = "Unable to fetch course data";
                    var errors        = new string[] { "Course not found" };
                    result = ApiResult.GetErrorResult(ApiResultStatus.NotFound, loggerMessage, message, errors);
                }
                else
                {
                    // check if user has course
                    var userCourse = user.SystemUsersTrainingCourses
                                     .FirstOrDefault(x => x.TrainingCourseId
                                                     .Equals(courseId));

                    var courseData = new CourseData();

                    // set course data
                    if (userCourse == null)
                    {
                        courseData.IsPresent = false;
                    }
                    else
                    {
                        courseData.IsPresent = true;
                        courseData.StudyDate = userCourse.StudyDate
                                               .ToShortDateString();
                    }

                    result = ApiResult.GetOkResult(ApiResultStatus.Ok, data: courseData);
                }
            }

            return(result);
        }
        public async Task <ApiResult> ConfirmEmailAsync(ConfirmEmailData confirmEmailData)
        {
            var result = default(ApiResult);
            var userId = confirmEmailData.Id;
            var user   = await users.GetByIdAsync(userId);

            if (user == null)
            {
                result = ApiResult.GetErrorResult(ApiResultStatus.NotFound, $"User with id = {userId} was not found", message: "User not found");
            }
            else
            {
                result = await GetConfirmEmailResultAsync(user, confirmEmailData.Token);
            }

            return(result);
        }
        public async Task <ApiResult> GetUserByIdAsync(int id)
        {
            var result = default(ApiResult);
            var user   = await users.GetByIdAsync(id);

            if (user == null)
            {
                var message       = "User was not found";
                var loggerMessage = $"User id = {id} was not found";
                var errors        = new string[] { message };
                result = ApiResult.GetErrorResult(ApiResultStatus.NotFound, loggerMessage, message, errors);
            }
            else
            {
                var data = mapperWrapper.MapModel(user);
                result = ApiResult.GetOkResult(ApiResultStatus.Ok, data: data);
            }

            return(result);
        }
Beispiel #4
0
        public async Task <ApiResult> AddCourseToUserAsync(SystemUsersTrainingCoursesDTO userCourseDTO)
        {
            var courseId = userCourseDTO.TrainingCourseId;
            var userId   = userCourseDTO.SystemUserId;

            var userCourse = mapperWrapper.MapEntity(userCourseDTO);

            var course = await courses.GetByIdAsync(courseId);

            var user = await users.GetByIdAsync(userId);

            var result = await GetAddCourseToUserResultAsync(user, course, userCourse);

            return(result);
        }