示例#1
0
        public async Task <IActionResult> PutAdult(int id, Adult adult)
        {
            if (id != adult.Id)
            {
                return(BadRequest());
            }

            _context.Entry(adult).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AdultExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#2
0
        public async Task addNewAdultAsync(Adult adult)
        {
            EntityEntry <Adult> newlyAdded = await ctx.Adults.AddAsync(adult);

            await ctx.SaveChangesAsync();

            //return newlyAdded.Entity;
        }
        public async Task <Adult> AddAdult(Adult todo)
        {
            EntityEntry <Adult> newlyAdded = await ctx.Adults.AddAsync(todo);

            await ctx.SaveChangesAsync();

            return(newlyAdded.Entity);
        }
示例#4
0
        public async Task <User> AddUserAsync(User user)
        {
            EntityEntry <User> newUser = await ctx.users.AddAsync(user);

            await ctx.SaveChangesAsync();

            return(newUser.Entity);
        }
示例#5
0
        public async Task <Adult> AddAdultAsync(Adult adult)
        {
            EntityEntry <Adult> newAdult = await cxt.Adults.AddAsync(adult);

            await cxt.SaveChangesAsync();

            return(newAdult.Entity);
        }
示例#6
0
        public async Task <Adult> AddAdultsAsync(Adult person)
        {
            int max = adults.Max(person => person.Id);

            person.Id = (++max);
            adults.Add(person);
            await ctx.Adult.AddAsync(person);

            await ctx.SaveChangesAsync();

            return(person);
        }
示例#7
0
        public async Task UpdateAdultsAsync(Adult person)
        {
            AdultContext dbContext = new AdultContext();

            dbContext.Update(person);
            await dbContext.SaveChangesAsync();
        }
示例#8
0
        public async Task <IActionResult> PostAdult(int id, Adult adult)
        {
            Adult adultToModify = await _context.Adults.FindAsync(id);

            if (adultToModify == null)
            {
                return(NotFound());
            }
            else
            {
                adultToModify.Update(adult);
            }
            await _context.SaveChangesAsync();

            //return CreatedAtAction("GetAdult", new { id = adult.Id }, adult);
            return(CreatedAtAction(nameof(GetAdult), new { id = adult.Id }, adult));
        }
 private static void AddUsers(IList <User> users)
 {
     foreach (User user in users)
     {
         using (AdultContext fctxt = new AdultContext())
         {
             Console.WriteLine(user.ToString());
             fctxt.Users.AddAsync(user);
             fctxt.Entry(user).State = EntityState.Added;
             //fctxt.Entry(user).State = EntityState.Detached;
             fctxt.SaveChangesAsync();
         }
     }
 }
 private static void AddAdults(IList <Adult> adults)
 {
     foreach (Adult adult in adults)
     {
         using (AdultContext fctxt = new AdultContext())
         {
             Console.WriteLine(adult.ToString());
             fctxt.Adults.AddAsync(adult);
             fctxt.Entry(adult).State = EntityState.Added;
             //fctxt.Entry(adult).State = EntityState.Detached;
             fctxt.SaveChangesAsync();
         }
     }
 }