public ActionResult <Step> Post()
        {
            var newStep = new Step {
            };

            _codeTestContext.Steps.Add(newStep);
            _codeTestContext.SaveChanges();

            return(Ok(newStep));
        }
        public ActionResult <Item> Post(Item item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _codeTestContext.Items.Add(item);
            _codeTestContext.SaveChanges();

            return(Ok(item));
        }
Exemplo n.º 3
0
        public IActionResult CreateCharacter([FromBody] CharacterCreateInputDTO input)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Result <Name> nameResult = Name.Create(input.PlayerName, input.CharacterName);

            if (nameResult.IsFailure)
            {
                return(BadRequest(nameResult.Error));
            }

            if (_context.Characters.Any(x => (x.Name.CharacterName == nameResult.Value.CharacterName && x.Name.PlayerName == nameResult.Value.PlayerName)))
            {
                return(BadRequest("The Player already has a Character with that name."));
            }

            var character = new Character(nameResult.Value, input.Strength, input.Dexterity, input.Constitution, input.Wisdom, input.Intelligence, input.Charisma);

            _repository.Save(character);

            _context.SaveChanges();

            return(Ok(character));
        }
Exemplo n.º 4
0
        public IActionResult Index()
        {
            if (testContext.Country.Count() == 0)
            {
                var item1 = new Country();
                var item2 = new Country();
                var item3 = new Country();

                item1.Name      = "Palestine";
                item1.CreatedAt = DateTime.Now;

                item2.Name      = "USA";
                item2.CreatedAt = DateTime.Now;

                item3.Name      = "Egypt";
                item3.CreatedAt = DateTime.Now;

                testContext.Country.Add(item1);
                testContext.Country.Add(item2);
                testContext.Country.Add(item3);
                testContext.SaveChanges();
            }
            if (testContext.City.Count() == 0)
            {
                var city1 = new City();
                var city2 = new City();
                var city3 = new City();
                var city4 = new City();
                var city5 = new City();
                var city6 = new City();
                var city7 = new City();

                city1.Name      = "Gaza";
                city1.CountryId = 1;
                city1.CreatedAt = DateTime.Now;

                city2.Name      = "Ramallah";
                city2.CountryId = 1;
                city2.CreatedAt = DateTime.Now;

                city3.Name      = "Nablus";
                city3.CountryId = 1;
                city3.CreatedAt = DateTime.Now;

                city4.Name      = "New York";
                city4.CountryId = 2;
                city4.CreatedAt = DateTime.Now;

                city5.Name      = "Washington";
                city5.CountryId = 2;
                city5.CreatedAt = DateTime.Now;

                city6.Name      = "Cairo";
                city6.CountryId = 3;
                city6.CreatedAt = DateTime.Now;

                city7.Name      = "Alexandria";
                city7.CountryId = 3;
                city7.CreatedAt = DateTime.Now;

                testContext.City.Add(city1);
                testContext.City.Add(city2);
                testContext.City.Add(city3);
                testContext.City.Add(city4);
                testContext.City.Add(city5);
                testContext.City.Add(city6);
                testContext.City.Add(city7);
                testContext.SaveChanges();
            }


            return(View());
        }