Пример #1
0
    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));
    }
Пример #2
0
        public async Task AddAsync(Goal goal)
        {
            if (goal.EndDate < DateTime.Now)
            {
                throw new Exception();
            }
            await _goalRepository.AddAsync(goal);

            await _unitOfWork.CompleteAsync();
        }
Пример #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();
        }
Пример #4
0
 public async Task <IActionResult> AddGoalAsync()
 {
     return(Created(nameof(Goal), await _repo.AddAsync(await Request.GetRawBodyStringAsync())));
 }