public async Task <IHttpActionResult> PutContact(int id, Contact contact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != contact.ContactId)
            {
                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
 public async Task SaveToDB(Note note)
 {
     using (this.context = new NotebookContext())
     {
         context.Notes.Add(note);
         await context.SaveChangesAsync();
     }
 }
示例#3
0
        public async Task SaveEditedToDB(Note note)
        {
            using (this.context = new NotebookContext())
            {
                var editedNote = await context.Notes.FindAsync(note.Id);

                if (editedNote != null)
                {
                    editedNote.Name = note.Name;
                    editedNote.File = note.File;
                    context.Entry(editedNote).State = EntityState.Modified;
                    await context.SaveChangesAsync();
                }
            }
        }