public IHttpActionResult Get([FromUri] Guid paragraphId) { try { Utils.IsAValidToken(Request, AuthorizationBusinessLogic); var paragraph = ParagraphBusinessLogic.GetParagraph(paragraphId); return(Ok(ParagraphModel.ToModel(paragraph))); } catch (Exception e) { return(BadRequest(e.Message)); } }
// DELETE: api/Paragraph/5 public IHttpActionResult Delete([FromUri] Guid id) { try { Utils.IsAValidToken(Request, AuthorizationBusinessLogic); Guid documentId = ParagraphBusinessLogic.GetParagraph(id).DocumentId.Value; ParagraphBusinessLogic.DeleteParagraph(id); AuditLogBussinesLogic.CreateLog("Document", documentId, Utils.GetUsername(Request), ActionPerformed.MODIFY); return(Ok("Paragraph deleted")); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IHttpActionResult Put([FromUri] Guid paragraphId, [FromBody] Guid textId, [FromUri] int newPosition) { try { Utils.IsAValidToken(Request, AuthorizationBusinessLogic); Guid documentId = ParagraphBusinessLogic.GetParagraph(paragraphId).DocumentId.Value; ParagraphBusinessLogic.MoveTextTo(paragraphId, textId, newPosition); AuditLogBussinesLogic.CreateLog("Document", documentId, Utils.GetUsername(Request), ActionPerformed.MODIFY); return(Ok("Text moved to " + newPosition)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IHttpActionResult Post([FromUri] Guid paragraphId, [FromBody] TextModel textModel, [FromUri] int position) { try { Utils.IsAValidToken(Request, AuthorizationBusinessLogic); var text = TextModel.ToEntity(textModel); Guid documentId = ParagraphBusinessLogic.GetParagraph(paragraphId).DocumentId.Value; ParagraphBusinessLogic.PutTextAt(paragraphId, text, position); AuditLogBussinesLogic.CreateLog("Document", documentId, Utils.GetUsername(Request), ActionPerformed.MODIFY); return(Ok("Text deleted")); } catch (Exception e) { return(BadRequest(e.Message)); } }
public void IntegrationTest_ExpectedParameters_Ok() { ParagraphDataAccess paragraphDA = new ParagraphDataAccess(); ParagraphBusinessLogic paragraphBL = new ParagraphBusinessLogic(paragraphDA); Paragraph paragraph1 = Utils.CreateParagraphForTest(); Paragraph paragraph2 = Utils.CreateParagraphForTest(); paragraphBL.AddParagraph(paragraph1); paragraphBL.AddParagraph(paragraph2); paragraph2.PutTextAtLast(text); paragraphBL.ModifyParagraph(paragraph2); paragraphBL.DeleteParagraph(paragraph1.Id); Paragraph paragraph2Obtained = paragraphBL.GetParagraph(paragraph2.Id); IList <Paragraph> paragraphsObtained = paragraphBL.GetParagraphs(); Assert.IsTrue(!paragraphsObtained.Contains(paragraph1) && paragraphsObtained.Contains(paragraph2Obtained)); }