Beispiel #1
0
        public Task <HttpResponseMessage> Post([FromBody] dynamic body)
        {
            var response = new HttpResponseMessage();

            try
            {
                _usuarioTreinocontroller.Post(body);

                var treinos = _service.GetUsuario((string)body.email);


                try
                {
                    var trei = _service.GetByTreino((string)body.email, (string)body.treino);

                    if (trei.DsTreino.Equals((string)body.treino))
                    {
                        return(CreateResponse(HttpStatusCode.Created, treinos));
                    }
                    else
                    {
                        var command = new CreateTreinoCommand(
                            dsTreino: (string)body.treino,
                            usuarioTreinoId: treinos.UsuarioTreinoId
                            );

                        var treino = _service.Create(command);

                        return(CreateResponse(HttpStatusCode.Created, treino));
                    }
                }
                catch
                {
                    var command = new CreateTreinoCommand(
                        dsTreino: (string)body.treino,
                        usuarioTreinoId: treinos.UsuarioTreinoId
                        );

                    var treino = _service.Create(command);

                    return(CreateResponse(HttpStatusCode.Created, treino));
                }
            }
            catch
            {
                response = Request.CreateResponse(HttpStatusCode.BadRequest, "O treino não foi criado!");
            }
            var tsc = new TaskCompletionSource <HttpResponseMessage>();

            tsc.SetResult(response);
            return(tsc.Task);
        }
Beispiel #2
0
        public Treino Create(CreateTreinoCommand command)
        {
            var treino = new Treino(command.DsTreino, command.UsuarioTreinoId);

            treino.CreateTreino();
            _repository.Create(treino);

            if (Commit())
            {
                return(treino);
            }

            return(null);
        }