Exemplo n.º 1
0
        public async Task Create__Admin_Or_Moderator_Can_Create_Exercise()
        {
            await LogInAs("*****@*****.**");

            CreateExerciseRequest exerciseRequest = Factory.Exercise.CreateExerciseRequest();

            var response = await Client.PostAsJsonAsync(ApiRoutes.Exercise.Create, exerciseRequest);

            response.StatusCode.Should().Be(HttpStatusCode.Created);

            var responseData = await response.Content.ReadAsAsync <ExerciseResponse>();

            responseData.Id.Should().Be(1);
            responseData.Name.Should().Be(exerciseRequest.Name);
            responseData.Description.Should().Be(exerciseRequest.Description);
            responseData.Powtorzenia.Should().Be(exerciseRequest.Powtorzenia);
            responseData.Serie.Should().Be(exerciseRequest.Serie);
            responseData.Obciazenie.Should().Be(exerciseRequest.Obciazenie);
            responseData.Czas.Should().Be(exerciseRequest.Czas);
            responseData.Dystans.Should().Be(exerciseRequest.Dystans);

            int count = await Context.Exercise.AsNoTracking().CountAsync();

            count.Should().Be(1);

            await LogInAs("*****@*****.**");

            response = await Client.PostAsJsonAsync(ApiRoutes.Exercise.Create, exerciseRequest);

            response.StatusCode.Should().Be(HttpStatusCode.Created);
        }
Exemplo n.º 2
0
        public async Task Create__Normal_User_Can_Not_Create_Exercise()
        {
            await LogInAs("*****@*****.**");

            CreateExerciseRequest exerciseRequest = Factory.Exercise.CreateExerciseRequest();

            var response = await Client.PostAsJsonAsync(ApiRoutes.Exercise.Create, exerciseRequest);

            response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
        }
        public async Task <IActionResult> Create([FromBody] CreateExerciseRequest request)
        {
            var newExercise     = _mapper.Map <Exercise>(request);
            var createdExercise = await _exerciseService.CreateExerciseAsync(newExercise);

            if (createdExercise.Id == 0)
            {
                return(BadRequest(new ErrorResponse("Wystąpił błąd podczas dodawania")));
            }

            return(CreatedAtAction(nameof(GetById),
                                   new { exerciseId = createdExercise.Id },
                                   _mapper.Map <ExerciseResponse>(createdExercise)));
        }
Exemplo n.º 4
0
 public Exercise MapRequestToEntity(CreateExerciseRequest request)
 {
     try
     {
         return(new Exercise
         {
             ExerciseName = request.Name,
             CategoryId = request.CategoryId,
             IsInTheRoutine = false,
         });
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 5
0
        public async Task <IActionResult> CreateExercise([FromBody] CreateExerciseRequest request)
        {
            var newExercise = new Exercise
            {
                ExerciseId   = Guid.NewGuid(),
                Name         = request.Name,
                Abbreviation = request.Abbrev
            };

            await _context.Exercises.AddAsync(newExercise);

            await _context.SaveChangesAsync();

            return(new JsonResult(new Response <ExerciseCreatedResponse>(new ExerciseCreatedResponse {
                ExerciseId = newExercise.ExerciseId
            })));
        }
Exemplo n.º 6
0
        public async Task <ActionResult <HateoasResponse> > CreateExercise([FromForm] CreateExerciseRequest model)
        {
            try
            {
                CreateExerciseCommand command = new(model);

                var exercise = await _mediator.Send(command);

                return(Ok(_sender.SendResult(exercise, GenericLinks.GetExerciseLinks(), $"The exercise whose name is {exercise.ExerciseName} has been created!")));
            }
            catch (Exception ex)
            {
                var errorResponse = _sender.SendError(ex, GenericLinks.GetExerciseLinks());

                Response.StatusCode = errorResponse.StatusCode;

                return(errorResponse);
            }
        }
Exemplo n.º 7
0
 public async Task <IActionResult> Create([FromBody] CreateExerciseRequest request, CancellationToken cancellationToken = default)
 {
     RemoveCacheKeys($"Report/TrainingMetrics{request.TrainingId}");
     return(Ok(await Mediator.Send(request, cancellationToken)));
 }