Ejemplo n.º 1
0
        public IActionResult CreateActivity([FromBody] ActivityForCreationAndUpdate activity)
        {
            if (activity == null)
            {
                return(NotFound());
            }

            var finalActivity = Mapper.Map <Entities.Activity>(activity);

            var trainerId = User.Claims.FirstOrDefault(c => c.Type == "sub").Value;

            finalActivity.TrainerId = trainerId;

            _sportRepository.AddActivity(finalActivity);

            if (!_sportRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            var createdActivityToReturn = Mapper.Map <Model.Activity>(finalActivity);

            return(CreatedAtRoute("GetActivity",
                                  new { activityId = createdActivityToReturn.Id },
                                  createdActivityToReturn));
        }