Example #1
0
        public async Task <IActionResult> PostAsync([FromBody] BadgeTrailsForCreationDto badge)
        {
            logger.LogInformation("Adding new trail badge was called");
            try
            {
                if (ModelState.IsValid)
                {
                    var newBadge = mapper.Map <BadgeTrailsForCreationDto, BadgeTrails>(badge);

                    newBadge.BadgeLevel    = 0;
                    newBadge.PointsAquired = 0;
                    newBadge.BadgeStatus   = "Inactive";

                    await repository.AddBadge(newBadge);

                    if (await repository.SaveAll())
                    {
                        return(Created("api/badges", mapper.Map <BadgeTrails, BadgeTrailsForCreationDto>(newBadge)));
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogError($"Failed to add new trails badge: {ex}");
            }

            return(BadRequest("Failed to add new trails badge"));
        }