Пример #1
0
        public async Task <IHttpActionResult> PutContact(int id, Contact contact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != contact.Id)
            {
                return(BadRequest());
            }

            db.Entry(contact).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #2
0
 /// <summary>
 /// Save Changes Async
 /// </summary>
 /// <returns></returns>
 public Task <int> Save()
 {
     return(_context.SaveChangesAsync());
 }
Пример #3
0
 public async Task AddContact(Contact contact)
 {
     _context.Contacts.Add(contact);
     await _context.SaveChangesAsync();
 }