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());
        }
Example #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);
        }
Example #3
0
        public async Task <Team> AddNewTeamAsync(CreateNewTeam teamToCreate)
        {
            var newTeam = teamToCreate.CreateTeam();

            await _schedulearnContext.Teams.AddAsync(newTeam);

            await _schedulearnContext.SaveChangesAsync();

            return(newTeam);
        }
Example #4
0
        public async Task <Topic> UpdateNameAndDescriptionAsync(int id, ModifiedTopic modifiedTopic)
        {
            var topic = await GetTopicAsync(id);

            topic.Name        = modifiedTopic.Name ?? topic.Name;
            topic.Description = modifiedTopic.Description ?? modifiedTopic.Description;

            _schedulearnContext.Update(topic);
            await _schedulearnContext.SaveChangesAsync();

            return(topic);
        }
Example #5
0
        public async Task <User> AddNewUserAsync(CreateNewUser userData)
        {
            var manager = await GetUserAsync(userData.ManagingUserId);

            if (manager == null)
            {
                throw new NotFoundException($"Manager with id ({userData.ManagingUserId}) does not exist");
            }

            var userWithEmail = await _schedulearnContext.Users.Where(user => user.Email == userData.Email.ToLower()).FirstOrDefaultAsync();

            if (userWithEmail != null)
            {
                throw new UniqueConstraintViolatedException("User with this email already exists");
            }

            User newUser = userData.CreateUser();

            if (manager.ManagedTeam == null)
            {
                var newTeam = await _teamService.AddNewTeamAsync
                              (
                    new CreateNewTeam()
                {
                    ManagerId = manager.Id,
                    LimitId   = manager.Team?.LimitId ?? manager.LimitId.Value
                }
                              );

                newUser.TeamId = newTeam.Id;
            }
            else
            {
                newUser.TeamId = manager.ManagedTeam.Id;
            }

            Guid newUserGuid = Guid.NewGuid();

            newUser.RegistrationGuid = newUserGuid;

            var link = Regex.Replace(userData.RegisterAddress, "{GUID}", newUserGuid.ToString());

            await _schedulearnContext.Users.AddAsync(newUser);

            await _schedulearnContext.SaveChangesAsync();

            await _emailService.SendRegistrationEmail(newUser.Email, newUser.Name, manager.Name, link);

            return(newUser);
        }
Example #6
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);
        }
Example #7
0
        public async Task <Limit> AddNewLimitAsync(LimitToCreate limitData)
        {
            Limit newLimit = limitData.CreateLimit();

            await _schedulearnContext.Limits.AddAsync(newLimit);

            await _schedulearnContext.SaveChangesAsync();

            return(newLimit);
        }