public async Task <ActionResult <ConceptSqlSet> > Create([FromBody] ConceptSqlSet conceptSqlSet) { try { if (conceptSqlSet == null) { return(BadRequest(CRUDError.From("ConceptSqlSet is missing."))); } if (string.IsNullOrWhiteSpace(conceptSqlSet.SqlSetFrom)) { return(BadRequest(CRUDError.From("ConceptSqlSet.SqlSetFrom is required."))); } var created = await setService.Create(conceptSqlSet); return(Ok(created)); } catch (LeafDbException le) { return(StatusCode(le.StatusCode, CRUDError.From(le.Message))); } catch (Exception e) { logger.LogError("Could not create ConceptSqlSet:{@ConceptSqlSet}. Error:{Error}", conceptSqlSet, e.ToString()); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <ActionResult> Update(int id, [FromBody] ConceptSqlSet conceptSqlSet) { try { if (conceptSqlSet != null) { conceptSqlSet.Id = id; } var updated = await manager.UpdateAsync(conceptSqlSet); if (updated == null) { return(NotFound()); } return(Ok(updated)); } catch (ArgumentException ae) { logger.LogError("Invalid update ConceptSqlSet model. Model:{@Model} Error:{Error}", conceptSqlSet, ae.Message); return(BadRequest(CRUDError.From($"{nameof(ConceptSqlSet)} is missing or incomplete."))); } catch (LeafRPCException le) { return(StatusCode(le.StatusCode, CRUDError.From(le.Message))); } catch (Exception e) { logger.LogError("Failed to update ConceptSqlSet:{@ConceptSqlSet}. Error:{Error}", conceptSqlSet, e.ToString()); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <ConceptSqlSet> Update(ConceptSqlSet set) { logger.LogInformation("Updating ConceptSqlSet:{@ConceptSqlSet}", set); using (var cn = new SqlConnection(opts.ConnectionString)) { await cn.OpenAsync(); try { return(await cn.QueryFirstOrDefaultAsync <ConceptSqlSet>( Sql.Update, new { id = set.Id, isEncounterBased = set.IsEncounterBased, isEventBased = set.IsEventBased, sqlSetFrom = set.SqlSetFrom, sqlFieldDate = set.SqlFieldDate, sqlFieldEvent = set.SqlFieldEvent, eventId = set.EventId, user = user.UUID }, commandType : CommandType.StoredProcedure, commandTimeout : opts.DefaultTimeout )); } catch (SqlException se) { logger.LogError("Could not update ConceptSqlSet:{@ConceptSqlSet}. Code:{Code} Error:{Error}", set, se.ErrorCode, se.Message); se.MapThrow(); throw; } } }
public async Task <ConceptSqlSet> CreateAsync(ConceptSqlSet set) { using (var cn = new SqlConnection(opts.ConnectionString)) { await cn.OpenAsync(); var created = await cn.QueryFirstOrDefaultAsync <ConceptSqlSet>( Sql.Create, new { isEncounterBased = set.IsEncounterBased, isEventBased = set.IsEventBased, sqlSetFrom = set.SqlSetFrom, sqlFieldDate = set.SqlFieldDate, sqlFieldEvent = set.SqlFieldEvent, eventId = set.EventId, user = user.UUID }, commandType : CommandType.StoredProcedure, commandTimeout : opts.DefaultTimeout ); return(created); } }
public async Task <ActionResult> Update(int id, [FromBody] ConceptSqlSet conceptSqlSet) { try { if (conceptSqlSet == null) { return(BadRequest(CRUDError.From("ConceptSqlSet is missing."))); } if (string.IsNullOrWhiteSpace(conceptSqlSet.SqlSetFrom)) { return(BadRequest(CRUDError.From("ConceptSqlSet.SqlSetFrom is required."))); } conceptSqlSet.Id = id; var updated = await setService.Update(conceptSqlSet); if (updated == null) { return(NotFound()); } return(Ok(updated)); } catch (LeafRPCException le) { return(StatusCode(le.StatusCode, CRUDError.From(le.Message))); } catch (Exception e) { logger.LogError("Could not update ConceptSqlSet:{@ConceptSqlSet}. Error:{Error}", conceptSqlSet, e.ToString()); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <ActionResult <ConceptSqlSet> > Create([FromBody] ConceptSqlSet conceptSqlSet) { try { var created = await manager.CreateAsync(conceptSqlSet); return(Ok(created)); } catch (ArgumentException ae) { logger.LogError("Invalid create ConceptSqlSet model. Model:{@Model} Error:{Error}", conceptSqlSet, ae.Message); return(BadRequest(CRUDError.From($"{nameof(ConceptSqlSet)} is missing or incomplete."))); } catch (LeafRPCException le) { return(StatusCode(le.StatusCode, CRUDError.From(le.Message))); } catch (Exception e) { logger.LogError("Failed to create ConceptSqlSet:{@ConceptSqlSet}. Error:{Error}", conceptSqlSet, e.ToString()); return(StatusCode(StatusCodes.Status500InternalServerError)); } }