Esempio n. 1
0
        public async Task <IActionResult> AddGoal([FromBody] GoalRequestModel model)
        {
            try
            {
                var employee = await _employeeRepository.GetById(model.EmployeeId);

                if (employee == null)
                {
                    return(BadRequest("Employee does not exist"));
                }

                var subject = await _subjectRepository.GetById(model.SubjectId);

                if (subject == null)
                {
                    return(BadRequest("Subject does not exist"));
                }

                var goal = new Goal(model.EmployeeId, model.SubjectId);

                _repository.AddGoal(goal);
                await _repository.SaveChanges();

                return(Ok());
            }
            catch (Exception exception)
            {
                return(BadRequest(exception.Message));
            }
        }
        public async Task DeleteGoal(Guid id)
        {
            try
            {
                var goal = await _repository.GetById(id);

                _repository.Remove(goal);
                await _repository.SaveChanges();
            }
            catch (DBConcurrencyException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw e;
            }
        }