Ejemplo n.º 1
0
        public async Task <Suggestion> AddNewSuggestionAsync(CreateNewSuggestion suggestionToCreate)
        {
            var topic = await _schedulearnContext.Topics.FindAsync(suggestionToCreate.TopicId);

            var suggester = await _schedulearnContext.Users.FindAsync(suggestionToCreate.SuggesterId);

            var suggestee = await _schedulearnContext.Users.FindAsync(suggestionToCreate.SuggesteeId);

            if (topic == null)
            {
                throw new NotFoundException(Error_TopicNotFound.ReplaceArgs(suggestionToCreate.TopicId));
            }
            if (suggester == null)
            {
                throw new NotFoundException(Error_UserNotFound.ReplaceArgs(suggestionToCreate.SuggesterId));
            }
            if (suggestee == null)
            {
                throw new NotFoundException(Error_UserNotFound.ReplaceArgs(suggestionToCreate.SuggesteeId));
            }

            var newSuggestion = suggestionToCreate.CreateSuggestion();

            await _schedulearnContext.Suggestions.AddAsync(newSuggestion);

            await _schedulearnContext.SaveChangesAsync();

            await _schedulearnContext.Entry(newSuggestion).ReloadAsync();

            return(newSuggestion);
        }
Ejemplo n.º 2
0
        public async Task <LearningDay> AddNewLearningDayAsync(CreateNewLearningDay learningDayToCreate)
        {
            var user = await _schedulearnContext.Users.FindAsync(learningDayToCreate.UserId);

            if (user == null)
            {
                throw new NotFoundException(Error_UserNotFound.ReplaceArgs(learningDayToCreate.UserId));
            }

            var topic = await _schedulearnContext.Topics.FindAsync(learningDayToCreate.TopicId);

            if (topic == null)
            {
                throw new NotFoundException(Error_TopicNotFound.ReplaceArgs(learningDayToCreate.TopicId));
            }

            CheckLimits(user, learningDayToCreate.DateFrom, learningDayToCreate.TimezoneMinutes);

            var newLearningDay = learningDayToCreate.CreateLearningDay();

            await _schedulearnContext.LearningDays.AddAsync(newLearningDay);

            await _schedulearnContext.SaveChangesAsync();

            await _schedulearnContext.Entry(newLearningDay).ReloadAsync();

            return(newLearningDay);
        }