示例#1
0
        public ActionResult <IEnumerable <Exercise> > GetExercises(string gymnastEmail, string name = null)
        {
            var gymnast = _gymnasts.GetByEmail(gymnastEmail);

            if (gymnast == null)
            {
                return(NotFound("Geen gymnast met dit ID"));
            }

            try {
                var oefeningen = new List <Exercise>();

                if (name == null)
                {
                    oefeningen = _exercises.GetExercisesFromGymnast(gymnastEmail).ToList();

                    if (oefeningen == null)
                    {
                        return(Ok());
                    }

                    return(oefeningen);
                }

                oefeningen = _exercises.GetByName(gymnastEmail, name).ToList();

                return(Ok(oefeningen));
            } catch (Exception e) {
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }
        public ActionResult <Training> CreateTraining([FromBody] TrainingDTO trainingDTO, string email)
        {
            Gymnast  gymnast  = _gymnasts.GetByEmail(email);
            Category category = _categories.GetbyId(trainingDTO.CategoryId);


            if (gymnast == null)
            {
                return(NotFound("Geen gymnast met dit ID."));
            }


            if (category == null && trainingDTO.Category != null)
            {
                category = new Category(trainingDTO.Category, ""); // tijdelijke geen beschrijving
                _categories.SaveChanges();
            }

            if (category == null && trainingDTO.Category == null)
            {
                return(NotFound("Geen category met dit ID"));
            }

            try {
                Training training = new Training(category, trainingDTO.Date, trainingDTO.FeelingBeforeTraining, trainingDTO.FeelingAfterTraining);
                gymnast.AddTraining(training);
                _gymnasts.SaveChanges();

                return(CreatedAtAction(nameof(GetTraining), new { trainingId = training.Id }, training));
            } catch (Exception e) {
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }
        public ActionResult <Gymnast> GetGymnast(string email)
        {
            var g = _gymnasts.GetByEmail(email);

            if (g == null)
            {
                return(NotFound("Geen gebruiker met deze email."));
            }

            try {
                return(Ok(g));
            } catch (ArgumentNullException e) {
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }