Beispiel #1
0
        public async Task <IActionResult> DeleteAsync(string key)
        {
            try
            {
                using (var reader = new EntityReader <TEntity>(Config.ConnectionString))
                {
                    var     entity = reader.GetByIdOrKey(key);
                    TEntity returnEntity;
                    using (var writer = new EntityWriter <TEntity>(Config))
                    {
                        returnEntity = await writer.DeleteAsync();

                        if (!returnEntity.IsNew)
                        {
                            return(BadRequest());
                        }
                    }
                    return(Ok(returnEntity));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new { message = $"{ex.Message}. Inner Exception: {ex.InnerException}" }));
            }
        }
Beispiel #2
0
        public IActionResult Get(string key)
        {
            var reader   = new EntityReader <CustomerInfo>();
            var customer = reader.GetByIdOrKey(key);

            return(Ok(customer.CastOrFill <CustomerModel>()));
        }
Beispiel #3
0
        public async Task <IActionResult> Delete(string key)
        {
            var reader   = new EntityReader <CustomerInfo>();
            var customer = reader.GetByIdOrKey(key);

            using (var writer = new StoredProcedureWriter <CustomerInfo>(customer, new CustomerSPConfig(customer)))
            {
                customer = await writer.DeleteAsync();
            }

            return(Ok(customer.CastOrFill <CustomerModel>()));
        }
Beispiel #4
0
        public IActionResult Get(string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                return(UnprocessableEntity());
            }

            try
            {
                using (var reader = new EntityReader <TEntity>(Config.ConnectionString))
                {
                    var entity = reader.GetByIdOrKey(key);
                    if (entity.IsNew)
                    {
                        return(NotFound());
                    }
                    return(Ok(entity));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new { message = $"{ex.Message}. Inner Exception: {ex.InnerException}" }));
            }
        }