public async Task <IHttpActionResult> PostNoteBody(NoteBody noteBody) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.NoteBodies.Add(noteBody); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (NoteBodyExists(noteBody.id)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = noteBody.id }, noteBody)); }
protected override void Execute(CodeActivityContext executionContext) { //Create the tracing service ITracingService tracingService = executionContext.GetExtension <ITracingService>(); //Create the context IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); tracingService.Trace("Resolving Account from Context"); Account entity = new Account(); entity.Id = ((EntityReference)AccountReference.Get <EntityReference>(executionContext)).Id; tracingService.Trace("Account resolved with Id {0}", entity.Id.ToString()); tracingService.Trace("Create a note for the account"); Annotation newNote = new Annotation(); newNote.Subject = NoteSubject.Get <string>(executionContext); newNote.NoteText = NoteBody.Get <string>(executionContext); newNote.ObjectId = entity.ToEntityReference(); Guid noteId = service.Create(newNote); tracingService.Trace("Note has been created"); NoteReference.Set(executionContext, new EntityReference(Annotation.EntityLogicalName, noteId)); }
public async Task <IHttpActionResult> PutNoteBody(int id, NoteBody noteBody) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != noteBody.id) { return(BadRequest()); } db.Entry(noteBody).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NoteBodyExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> GetNoteBody(string data) { NoteBody noteBody = await db.NoteBodies.FindAsync(data); System.Diagnostics.Debug.WriteLine("Found: " + noteBody); if (noteBody == null) { return(NotFound()); } return(Ok(noteBody)); }
private void ProcessMatch(string match) { if (String.IsNullOrEmpty(match)) { _main.PositionInContents = 0; NoteBody.Select(0, 0); MessageBox.Show("No match found"); return; } NoteBody.Focus(); NoteBody.Select(NoteBody.Text.IndexOf(match, _main.PositionInContents), match.Length); _main.PositionInContents++; }
public async Task <IHttpActionResult> DeleteNoteBody(int id) { NoteBody noteBody = await db.NoteBodies.FindAsync(id); if (noteBody == null) { return(NotFound()); } db.NoteBodies.Remove(noteBody); await db.SaveChangesAsync(); return(Ok(noteBody)); }
// DELETE: odata/NoteBodies(5) public async Task <IHttpActionResult> Delete([FromODataUri] int key) { NoteBody noteBody = await db.NoteBodies.FindAsync(key); if (noteBody == null) { return(NotFound()); } db.NoteBodies.Remove(noteBody); await db.SaveChangesAsync(); return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <ActionResult> Put(int id, [FromBody] NoteBody body) { string user = User.FindFirstValue(ClaimTypes.NameIdentifier); int found = await db.Value <int>("SELECT COUNT(*) FROM Notes WHERE ID=@id AND userID=@user;UPDATE Notes SET text=@text WHERE ID=@id AND userId=@user", new { body.Text, id, user }); if (found > 0) { return(Ok("UPDATED: " + id)); } else { return(Unauthorized()); } }
// PUT: odata/NoteBodies(5) public async Task <IHttpActionResult> Put([FromODataUri] int key, Delta <NoteBody> patch) { Validate(patch.GetEntity()); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } NoteBody noteBody = await db.NoteBodies.FindAsync(key); if (noteBody == null) { return(NotFound()); } patch.Put(noteBody); try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NoteBodyExists(key)) { return(NotFound()); } else { throw; } } return(Updated(noteBody)); }
public async Task <ActionResult> Post([FromBody] NoteBody body) { string user = User.FindFirstValue(ClaimTypes.NameIdentifier); return(Ok(await db.Value <int>("INSERT INTO Notes (text, date, userId) VALUES (@text, GETDATE(), @user); SELECT SCOPE_IDENTITY()", new { body.Text, user }))); }