Esempio n. 1
0
        public async Task <ProgressResponse> SaveAsync(Progress progress)
        {
            try
            {
                await _progressRepository.AddAsync(progress);

                await _unitOfWork.CompleteAsync();

                return(new ProgressResponse(progress));
            }
            catch (Exception ex)
            {
                return(new ProgressResponse($"An error ocurred while saving progress: {ex.Message}"));
            }
        }
        public async Task <IResult <long> > AddAsync(ProgressModel model)
        {
            var validation = await new AddProgressModelValidator().ValidateAsync(model);

            if (validation.Failed)
            {
                return(Result <long> .Fail(validation.Message));
            }
            var user = await _userRepository.GetAsync(model.UserId);

            var Progress = ProgressFactory.CreateProgress(model, user);
            await _ProgressRepository.AddAsync(Progress);

            await _unitOfWork.SaveChangesAsync();

            return(Result <long> .Success(Progress.Id));
        }