Ejemplo n.º 1
0
        public async Task <ActionResult <HateoasResponse> > RemoveExerciseFromRoutine(Guid id)
        {
            try
            {
                RemoveExerciseFromRoutineCommand command = new(id);

                bool result = await _mediator.Send(command);

                return(Ok(_sender.SendResult(new { ExerciseRemoved = result }, GenericLinks.GetRoutineLinks(), "The exercise has been removed!")));
            }
            catch (Exception ex)
            {
                var errorResponse = _sender.SendError(ex, GenericLinks.GetRoutineLinks());

                Response.StatusCode = errorResponse.StatusCode;

                return(errorResponse);
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <HateoasResponse> > SetDone(SetDoneRequest request)
        {
            try
            {
                SetDoneCommand command = new(request);

                bool result = await _mediator.Send(command);

                return(Ok(_sender.SendResult(new { SetDoneCreated = result }, GenericLinks.GetRoutineLinks(), "The set done has been registered!")));
            }
            catch (Exception ex)
            {
                var errorResponse = _sender.SendError(ex, GenericLinks.GetRoutineLinks());

                Response.StatusCode = errorResponse.StatusCode;

                return(errorResponse);
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <HateoasResponse> > AddExerciseToRoutine(AddExerciseToRoutineRequest request)
        {
            try
            {
                AddExerciseToRoutineCommand command = new(request);

                bool result = await _mediator.Send(command);

                return(Ok(_sender.SendResult(new { ExerciseCreated = result }, GenericLinks.GetRoutineLinks(), "The exercise has been added to your Routine!")));
            }
            catch (Exception ex)
            {
                var errorResponse = _sender.SendError(ex, GenericLinks.GetRoutineLinks());

                Response.StatusCode = errorResponse.StatusCode;

                return(errorResponse);
            }
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <HateoasResponse> > GetExerciseToDo()
        {
            try
            {
                GetExerciseToDoQuery query = new ();

                var result = await _mediator.Send(query);

                string message = (result is not null) ? $"You have to do the {result.Name}" : "You are done for today, go and get some rest!";

                return(Ok(_sender.SendResult(result, GenericLinks.GetRoutineLinks(), message)));
            }
            catch (Exception ex)
            {
                var errorResponse = _sender.SendError(ex, GenericLinks.GetRoutineLinks());

                Response.StatusCode = errorResponse.StatusCode;

                return(errorResponse);
            }
        }