Пример #1
0
        public async Task <IActionResult> Update(
            Guid exerciseSessionId, Guid id, [FromBody] ExerciseRecordAddApi exerciseRecordAddApi)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var exerciseRecord = new ExerciseRecord
            {
                Id             = Guid.NewGuid(),
                Set            = exerciseRecordAddApi.Set,
                Reps           = exerciseRecordAddApi.Reps,
                Value          = exerciseRecordAddApi.Value,
                Unit           = exerciseRecordAddApi.Unit,
                DropSet        = exerciseRecordAddApi.DropSet,
                EpochTimestamp = exerciseRecordAddApi.Datetime.ToEpoch(),
                Note           = exerciseRecordAddApi.Note
            };

            await _exerciseRecordRepository.Update(exerciseRecord);

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> Post(
            Guid exerciseSessionId, [FromBody] ExerciseRecordAddApi exerciseRecordAddApi)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var exerciseRecord = new ExerciseRecord
            {
                Id             = Guid.NewGuid(),
                Set            = exerciseRecordAddApi.Set,
                Reps           = exerciseRecordAddApi.Reps,
                Value          = exerciseRecordAddApi.Value,
                Unit           = exerciseRecordAddApi.Unit,
                DropSet        = exerciseRecordAddApi.DropSet,
                EpochTimestamp = exerciseRecordAddApi.Datetime.ToEpoch(),
                Note           = exerciseRecordAddApi.Note
            };

            var er = await _exerciseRecordRepository.Add(exerciseRecord, exerciseSessionId);

            return(CreatedAtRoute("GetExerciseSession",
                                  new { Controller = "ExerciseSession", id = exerciseSessionId },
                                  new ExerciseRecordApi
            {
                Id = er.Id,
                Set = er.Set,
                Reps = er.Reps,
                Value = er.Value,
                Unit = er.Unit,
                DropSet = er.DropSet,
                Datetime = er.Datetime,
                Note = er.Note
            }));
        }