Esempio n. 1
0
        public ActionResult <Word> CreateWord(CreateWordDto dto)
        {
            var addMe = new Word
            {
                Name = dto.WordToAdd
            };

            _context.Set <Word>().Add(addMe);
            _context.SaveChanges();

            return(Created($"/api/Words/{addMe.Id}", addMe));
        }
Esempio n. 2
0
        public ActionResult <Person> GetAllPeople(CreatePersonDto dto)
        {
            var addPerson = new Person
            {
                FirstName = dto.FirstName,
                LastName  = dto.LastName,
                Age       = dto.Age
            };

            _context.Set <Person>().Add(addPerson);
            _context.SaveChanges();

            return(Created($"/api/Person/the-id", addPerson));
        }
Esempio n. 3
0
        public GetWordDto Post(string word)
        {
            // Create a new Word Entity
            var entity = new Word();

            // Assign WordName to the string word from user
            entity.WordName = word;

            // Using Dependency Injection
            // Add entity to database
            _context.Add(entity);
            // Save changes to database
            _context.SaveChanges();

            // Return ojbect including Id made by database
            return(new GetWordDto {
                Id = entity.Id, WordName = entity.WordName
            });
        }