public async Task <ConceptEvent> Create(ConceptEvent ev)
        {
            logger.LogInformation("Creating ConceptEvent:{@ConceptEvent}", ev);
            using (var cn = new SqlConnection(opts.ConnectionString))
            {
                await cn.OpenAsync();

                try
                {
                    var created = await cn.QueryFirstOrDefaultAsync <ConceptEvent>(
                        Sql.Create,
                        new
                    {
                        uiDisplayEventName = ev.UiDisplayEventName,
                        user = user.UUID
                    },
                        commandType : CommandType.StoredProcedure,
                        commandTimeout : opts.DefaultTimeout
                        );

                    logger.LogInformation("Created ConceptEvent:{@ConceptEvent}", ev);
                    return(created);
                }
                catch (SqlException se)
                {
                    logger.LogError("Could not create ConceptEvent:{@ConceptEvent}. Code:{Code} Error:{Error}", ev, se.ErrorCode, se.Message);
                    se.MapThrow();
                    throw;
                }
            }
        }
        public async Task <ActionResult <ConceptEvent> > Create([FromBody] ConceptEvent conceptEvent)
        {
            try
            {
                if (conceptEvent == null)
                {
                    return(BadRequest(CRUDError.From("ConceptEvent is missing.")));
                }
                if (string.IsNullOrWhiteSpace(conceptEvent.UiDisplayEventName))
                {
                    return(BadRequest(CRUDError.From("ConceptEvent.UiDisplayEventName is required.")));
                }

                var created = await evService.Create(conceptEvent);

                return(Ok(created));
            }
            catch (LeafRPCException le)
            {
                return(StatusCode(le.StatusCode, CRUDError.From(le.Message)));
            }
            catch (Exception e)
            {
                logger.LogError("Could not create ConceptEvent:{@ConceptEvent}. Error:{Error}", conceptEvent, e.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Exemple #3
0
        public async Task <ActionResult> Update(int id, [FromBody] ConceptEvent conceptEvent)
        {
            try
            {
                if (conceptEvent != null)
                {
                    conceptEvent.Id = id;
                }

                var updated = await manager.UpdateAsync(conceptEvent);

                if (updated == null)
                {
                    return(NotFound());
                }
                return(Ok(updated));
            }
            catch (ArgumentException ae)
            {
                logger.LogError("Invalid update ConceptEvent model. Model:{@Model} Error:{Error}", conceptEvent, ae.Message);
                return(BadRequest(CRUDError.From($"{nameof(ConceptEvent)} is missing or incomplete.")));
            }
            catch (LeafRPCException le)
            {
                return(StatusCode(le.StatusCode, CRUDError.From(le.Message)));
            }
            catch (Exception e)
            {
                logger.LogError("Failed to update ConceptEvent:{@ConceptEvent}. Error:{Error}", conceptEvent, e.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Exemple #4
0
        public async Task <ConceptEvent> UpdateAsync(ConceptEvent ev)
        {
            using (var cn = new SqlConnection(opts.ConnectionString))
            {
                await cn.OpenAsync();

                return(await cn.QueryFirstOrDefaultAsync <ConceptEvent>(
                           Sql.Update,
                           new
                {
                    id = ev.Id,
                    uiDisplayEventName = ev.UiDisplayEventName,
                    user = user.UUID
                },
                           commandType : CommandType.StoredProcedure,
                           commandTimeout : opts.DefaultTimeout
                           ));
            }
        }
Exemple #5
0
        public async Task <ActionResult <ConceptEvent> > Create([FromBody] ConceptEvent conceptEvent)
        {
            try
            {
                var created = await manager.CreateAsync(conceptEvent);

                return(Ok(created));
            }
            catch (ArgumentException ae)
            {
                logger.LogError("Invalid create ConceptEvent model. Model:{@Model} Error:{Error}", conceptEvent, ae.Message);
                return(BadRequest(CRUDError.From($"{nameof(ConceptEvent)} is missing or incomplete.")));
            }
            catch (LeafRPCException le)
            {
                return(StatusCode(le.StatusCode, CRUDError.From(le.Message)));
            }
            catch (Exception e)
            {
                logger.LogError("Failed to create ConceptEvent:{@ConceptEvent}. Error:{Error}", conceptEvent, e.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }