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); }
public async Task <IActionResult> PutJobTitle(int id, JobTitle jobTitle) { System.Diagnostics.Debug.WriteLine("PutJobTitle " + id); if (id != jobTitle.Id) { return(BadRequest()); } _schedulearnContext.Entry(jobTitle).State = EntityState.Modified; try { await _schedulearnContext.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!JobTitleExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
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); }