Exemplo n.º 1
0
        public async Task <ActionResult <Person> > Post(Person person)
        {
            using (var ctx = new KDTestContext()){
                ctx.Personnel.Add(person);
                await ctx.SaveChangesAsync();

                return(CreatedAtAction(nameof(Person), new { id = person.PersonID }, person));
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult <Person> > Put(int id, Person person)
        {
            if (id != person.PersonID)
            {
                return(BadRequest());
            }

            using (var ctx = new KDTestContext()){
                ctx.Entry(person).State = EntityState.Modified;
                await ctx.SaveChangesAsync();
            }

            return(NoContent());
        }
Exemplo n.º 3
0
        public async Task <ActionResult <Person> > DeletePerson(int id)
        {
            using (var ctx = new KDTestContext()){
                var person = await ctx.Personnel.FindAsync(id);

                if (person is null)
                {
                    return(NotFound());
                }

                person.Deleted          = DateTime.Now;
                ctx.Entry(person).State = EntityState.Modified;

                await ctx.SaveChangesAsync();
            }

            return(NoContent());
        }
Exemplo n.º 4
0
 public async Task <ActionResult <Person> > Get(int id)
 {
     using (var ctx = new KDTestContext()){
         return(await ctx.Personnel.FindAsync(id));
     }
 }
Exemplo n.º 5
0
 public async Task <ActionResult <IEnumerable <Person> > > Get()
 {
     using (var ctx = new KDTestContext()){
         return(await ctx.Personnel.ToListAsync());
     }
 }