Beispiel #1
0
        protected HttpResponseMessage CreateHttpResponse(HttpRequestMessage request, Func <HttpResponseMessage> function)
        {
            HttpResponseMessage response = null;

            try
            {
                response = function.Invoke();
            }
            catch (DbUpdateException ex)
            {
                if (ConfigHelper.LogProviderRequests)
                {
                    ObjHelper.LogProviderRequest(ex, "ApiControllerBase");
                }
                LogError(ex);
                response = request.CreateResponse(HttpStatusCode.BadRequest, ConfigurationReader.ErrorMessage);
            }
            catch (Exception ex)
            {
                if (ConfigHelper.LogProviderRequests)
                {
                    ObjHelper.LogProviderRequest(ex, "ApiControllerBase");
                }
                LogError(ex);
                response = request.CreateResponse(HttpStatusCode.InternalServerError, ConfigurationReader.ErrorMessage);
                //throw;
            }
            return(response);
        }
Beispiel #2
0
        private static IContainer RegisterServices(ContainerBuilder containerBuilder, Assembly executingAssembly)
        {
            try
            {
                containerBuilder.RegisterApiControllers(executingAssembly);

                containerBuilder.RegisterType <HeatChartContext>()
                .As <DbContext>()
                .InstancePerRequest();

                containerBuilder.RegisterType <DBFactory>()
                .As <IDBFactory>()
                .InstancePerRequest();

                containerBuilder.RegisterType <EFUnitOfWork>()
                .As <IEFUnitOfWork>()
                .InstancePerRequest();

                containerBuilder.RegisterType <EFUnitOfWork>()
                .As <IUnitOfWork>()
                .InstancePerRequest();

                containerBuilder.RegisterGeneric(typeof(EFRepository <>))
                .As(typeof(IEFRepository <>))
                .InstancePerRequest();

                containerBuilder.RegisterType <DataRepositoryFactory>()
                .As <IDataRepositoryFactory>()
                .InstancePerRequest();

                containerBuilder.RegisterType <MembershipService>()
                .As <IMembershipService>()
                .InstancePerRequest();

                containerBuilder.RegisterType <EncryptionService>()
                .As <IEncryptionService>()
                .InstancePerRequest();

                container = containerBuilder.Build();


                return(container);
            }
            catch (Exception ex)
            {
                if (ConfigHelper.LogProviderRequests)
                {
                    ObjHelper.LogProviderRequest(ex, "UnityResolver");
                }

                return(null);
            }
        }
        private void LogError(Exception ex)
        {
            try
            {
                if (ConfigHelper.LogProviderRequests)
                {
                    ObjHelper.LogProviderRequest(ex, "ApiControllerBaseExtended");
                }

                Error _error = new Error()
                {
                    Message     = ex.Message,
                    StackTrace  = ex.StackTrace,
                    DateCreated = DateTime.Now
                };

                _errorsRepository.Insert(_error);
                _errorsRepository.Commit();
            }
            catch { }
        }