public void InsertUpdateDelete() { OtherAssociationController otherAssociationController = new OtherAssociationController(); //create new entity OtherAssociation otherAssociation = new OtherAssociation(); otherAssociation.otherAssociationId = Guid.NewGuid(); otherAssociation.name = "Test Name"; otherAssociation.entryDate = DateTime.Now; otherAssociation.appUserId = Guid.NewGuid(); otherAssociation.modifiedDate = DateTime.Now; otherAssociation.remark = "Test Remark"; //insert var result1 = otherAssociationController.Post(otherAssociation); //update var result2 = otherAssociationController.Post(otherAssociation); //delete var result3 = otherAssociationController.Delete(otherAssociation.otherAssociationId); //assert Assert.IsNotNull(result1); Assert.IsNotNull(result2); Assert.IsNotNull(result3); Assert.IsTrue(result1 is OkResult); Assert.IsTrue(result2 is OkResult); Assert.IsTrue(result3 is OkResult); }
public IActionResult Post([FromBody] OtherAssociation value) { try { using (var db = My.ConnectionFactory()) { int result = db.Execute($@"IF EXISTS({My.Table_OtherAssociation.SelectSingle}) {My.Table_OtherAssociation.Update} ELSE {My.Table_OtherAssociation.Insert}", value); } return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }