Ejemplo n.º 1
0
        // PUT api/Note/5
        public HttpResponseMessage PutNote(Note note)
        {
            if (ModelState.IsValid)
            {
                //db.Entry(Note).State = EntityState.Modified;

                //note.GroupReference.Attach(db.Groups.Where(gw => gw.ID == note.GroupID).First());
                //note.GroupReference.Load();
                //db.Notes.Attach(note);
                //note.GroupReference.Load();

                //Note existingNote = db.Notes.Find(note.ID);
                //db.Entry(existingNote).CurrentValues.SetValues(note);
                Note existingNote = db.Notes.Single(nw => nw.ID == note.ID);
                db.ApplyCurrentValues("Notes", note);

                //db.ObjectStateManager.ChangeObjectState(note, EntityState.Modified);

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }