public IsoJsonResult CreateNotes(JsonNote [] notes) { bool fromCache = notes != null && notes.Length > 0; var newNotesNumber = fromCache ? notes.Length : 1; List <Note> newNotes = new List<Note>(); for(ushort i = 0; i < newNotesNumber; i++) { Note newNote = new Note { ID = Guid.NewGuid().ToString(), UserId = User.Identity.GetUserId(), CreationDate = fromCache ? notes[i].CreationDate : DateTime.Now, Content = fromCache ? notes[i].Content : "" }; newNotes.Add(newNote); db.Notes.Add(newNote); } db.SaveChanges(); var generatedJsonEntities = EntityToJsonModelConverter.Convert(newNotes.Cast<BaseDbEntity>().ToList()); return new IsoJsonResult() { Data = generatedJsonEntities, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; }
public IsoJsonResult UpdateNotes(JsonNote note) { var noteEntry = db.Notes.Find(note.ID); noteEntry.Content = note.Content; db.Entry(noteEntry).State = EntityState.Modified; db.SaveChanges(); return new IsoJsonResult() { Data = EntityToJsonModelConverter.Convert(noteEntry), JsonRequestBehavior = JsonRequestBehavior.AllowGet }; }