public NoteModel PostAddNote(int itemId, NoteModel noteModel, [ValueProvider(typeof(HeaderValueProviderFactory<string>))] string sessionKey) { var responseMsg = this.PerformOperationAndHandleExceptions(() => { var user = GetAndValidateUser(sessionKey); var itemModel = this.Data.Items.All().Where(item => item.UserId == user.Id).SingleOrDefault(it => it.Id == itemId); if (itemModel == null) { throw new ArgumentException("Item Not Found!"); } Note note = new Note(); note.Text = noteModel.Text; note.ItemId = itemModel.Id; this.Data.Notes.Add(note); this.Data.SaveChanges(); noteModel.Id = note.Id; return noteModel; }); return responseMsg; }
public NoteModel PutUpdateNote(NoteModel noteModel, [ValueProvider(typeof(HeaderValueProviderFactory<string>))] string sessionKey) { var responseMsg = this.PerformOperationAndHandleExceptions(() => { var user = GetAndValidateUser(sessionKey); var noteEntity = this.Data.Notes.All().Where(n => n.Item.User.Id == user.Id).SingleOrDefault(n => n.Id == noteModel.Id); if (noteModel == null) { throw new ArgumentException("Note Not Found!"); } if (noteEntity.Text != noteModel.Text) { noteEntity.Text = noteModel.Text; } this.Data.SaveChanges(); return noteModel; }); return responseMsg; }