예제 #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));
            }
        }
예제 #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());
        }
예제 #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());
        }