Esempio n. 1
0
        public async Task <IActionResult> PutExerciseMuscle([FromRoute] int id, [FromBody] ExerciseMuscle exerciseMuscle)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != exerciseMuscle.ExerciseMuscleID)
            {
                return(BadRequest());
            }

            _context.Entry(exerciseMuscle).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ExerciseMuscleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <IActionResult> PutSplitDay([FromRoute] int id, [FromBody] SplitDay splitDay)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != splitDay.ID)
            {
                return(BadRequest());
            }

            _context.Entry(splitDay).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SplitDayExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 3
0
        public async Task <IActionResult> PutDay([FromRoute] int id, [FromBody] Day Day)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != Day.ID)
            {
                return(BadRequest());
            }

            try
            {
                var ctxDay = _context.Days.Include(x => x.DaysMuscles).ThenInclude(x => x.Muscle).
                             FirstOrDefault(x => x.ID == id);
                AutoMapper.Mapper.Map(Day, ctxDay);

                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DayExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 4
0
        public async Task <IActionResult> PutSplit([FromRoute] int id, [FromBody] Split split)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != split.ID)
            {
                return(BadRequest());
            }
            try
            {
                var ctxSplit = _context.Splits.Include(x => x.SplitDays)
                               .ThenInclude(x => x.Day)
                               .ThenInclude(x => x.DaysMuscles).
                               FirstOrDefault(x => x.ID == id);

                AutoMapper.Mapper.Map(split, ctxSplit);

                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SplitExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(NoContent());
        }
Esempio n. 5
0
        public async Task <IActionResult> PutExercise([FromRoute] int id, [FromBody] Exercise exercise)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                if (id != exercise.ExerciseID)
                {
                    return(BadRequest());
                }

                var ctxExercise = _context.Exercises.Include(x => x.ExerciseMuscles).FirstOrDefault(x => x.ExerciseID == id);


                Mapper.Map(exercise, ctxExercise);

                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ExerciseExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(NoContent());
        }