コード例 #1
0
        public async Task <IActionResult> GetCourseProgress(string progressId)
        {
            var result = await progressRepository.GetAsync(progressId);

            if (result == null)
            {
                return(NotFound($"Invalid progressId = {progressId}"));
            }

            var userId = result.UserId;

            if (!IdIsValid(userId))
            {
                return(Forbid($"The user has no rights or the id = {userId} is invalid"));
            }

            return(Ok(result));
        }
コード例 #2
0
        public async Task <IResult> UpdateAsync(ProgressModel model)
        {
            var validation = await new UpdateProgressModelValidator().ValidateAsync(model);

            if (validation.Failed)
            {
                return(Result.Fail(validation.Message));
            }

            var Progress = await _ProgressRepository.GetAsync(model.Id);

            if (Progress == default)
            {
                return(Result.Success());
            }

            Progress.ChangeWeight(model.Weight);

            await _ProgressRepository.UpdateWeightAsync(Progress);

            await _unitOfWork.SaveChangesAsync();

            return(Result.Success());
        }