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));
        }
Example #2
0
 public void Post(Notebook notebook)
 {
     if (ModelState.IsValid)
     {
         db.Entry(notebook).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Example #3
0
 public ActionResult Edit([Bind(Include = "Id,Name,Number")] Contact contact)
 {
     if (ModelState.IsValid)
     {
         db.Entry(contact).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(contact));
 }
 public ActionResult Edit(Notebook notebook)
 {
     if (ModelState.IsValid)
     {
         db.Entry(notebook).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(notebook));
 }
Example #5
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();
                }
            }
        }
 public void Add(TEntity item)
 {
     _context.Entry <TEntity>(item).State = System.Data.Entity.EntityState.Added;
 }
Example #7
0
 public ActionResult Edit(Contact contact)
 {
     db.Entry(contact).State = EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }