public async Task <ActionResult <Goal> > CreateGoal(Goal goal)
    {
        if (!ModelState.IsValid)
        {
            return(BadRequest());
        }

        if (string.IsNullOrWhiteSpace(goal.StudentId))
        {
            return(BadRequest("Student must be set to create goal."));
        }

        var student = await GetStudent(goal.StudentId);

        if (student == null)
        {
            return(BadRequest("Student does not exist."));
        }

        var goalResponse = await _goalRepository.AddAsync(goal);

        await AddGoalToStudent(student, goal);

        return(Ok(goalResponse));
    }
Beispiel #2
0
        public async Task AddAsync(Goal goal)
        {
            if (goal.EndDate < DateTime.Now)
            {
                throw new Exception();
            }
            await _goalRepository.AddAsync(goal);

            await _unitOfWork.CompleteAsync();
        }
Beispiel #3
0
        public async Task <GoalResponse> SaveAsync(Goal goal)
        {
            try
            {
                await _goalRepository.AddAsync(goal);

                await _unitOfWork.CompleteAsync();

                return(new GoalResponse(goal));
            }
            catch (Exception ex)
            {
                return(new GoalResponse($"An error ocurred while saving the Goal : {ex.Message}"));
            }
            throw new NotImplementedException();
        }
Beispiel #4
0
 public async Task <IActionResult> AddGoalAsync()
 {
     return(Created(nameof(Goal), await _repo.AddAsync(await Request.GetRawBodyStringAsync())));
 }