コード例 #1
0
        public IActionResult addContest([FromBody] ContestTypeDTO newContestType)
        {
            var claimsIdentity = this.User.Identity as ClaimsIdentity;

            try
            {
                userService.IsUserAnOrganizator(claimsIdentity);
                if (!appSettingsService.canEnter())
                {
                    throw new AppException("Akcja obecnie niedozwolona");
                }
                List <AllowedBreedsContest> allowedBreeds = new List <AllowedBreedsContest>();
                foreach (int breedId in newContestType.breedIds)
                {
                    allowedBreeds.Add(new AllowedBreedsContest
                    {
                        BreedTypeId = breedId
                    });
                }
                ContestType contestType = new ContestType
                {
                    Enterable            = newContestType.isEnterable,
                    NamePolish           = newContestType.name,
                    AllowedBreedsContest = allowedBreeds
                };
                ContestType savedContestType = contestService.addContest(contestType);
                if (savedContestType == null)
                {
                    throw new AppException("Błąd tworzenia konkursu");
                }
                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(new { message = e.Message }));
            }
        }