Exemplo n.º 1
0
        public async static Task <PaginatedMongoModel <TList> > GetAll <TList>(this IEntityService <Empresa> service, IComponentContext container, PaginatedRequestCommand model)
            where TList : class, IMongoModel, IDto, new()
        {
            var result = await service.MongoService.GetMongoListAsync <EmpresaClienteMongoModel, TList>(container, model);

            var paged = result.ToPaginatedModel <TList>();

            paged.ColumnDefinitions = ColumnFactory.GenerateColumnDefinitions <TList>(ActionEnum.List).ToArray();
            paged.Condition         = new Condition();

            return(paged);
        }
Exemplo n.º 2
0
        public virtual IHttpActionResult Get(PaginatedRequestCommand cmd)
        {
            cmd.FilterInternalDictionary = new Dictionary <string, object>();

            this.ListSelecting(cmd);

            var attr = typeof(TModel).GetCustomAttributes(true).OfType <DataEntityAttribute>().FirstOrDefault();

            if (cmd.Type.Equals(AInBox.Astove.Core.Enums.EnumUtility.GetEnumText(GetTypes.PagedGrid), StringComparison.CurrentCultureIgnoreCase))
            {
                try
                {
                    var list = this.Service.GetEntities(this.Container, cmd, typeof(TModel), cmd.OrdersBy, cmd.Directions, (attr != null) ? attr.Include : null);

                    var paginatedModel = list.ToPaginatedModel <TModel>(null, null);
                    SetViews(paginatedModel.Items);

                    paginatedModel.ColumnDefinitions = ColumnFactory.GenerateColumnDefinitions <TModel>(ActionEnum.List).ToArray();
                    paginatedModel.Condition         = new Condition();

                    this.ListSelected(paginatedModel);

                    return(Ok(paginatedModel));
                }
                catch (Exception ex)
                {
                    return(InternalServerError(ex));
                }
            }

            try
            {
                var entities = this.Service.GetEntities(this.Container, cmd, typeof(TModel), cmd.OrdersBy, cmd.Directions, (attr != null) ? attr.Include : null);
                var paged    = entities.ToPaginatedModel <TModel>(null, null);
                SetViews(paged.Items);

                paged.ColumnDefinitions = ColumnFactory.GenerateColumnDefinitions <TModel>(ActionEnum.List).ToArray();
                paged.Condition         = new Condition();

                this.ListSelected(paged);

                return(Ok(paged));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemplo n.º 3
0
        public virtual IHttpActionResult Get(PaginatedRequestCommand cmd)
        {
            cmd.FilterInternalDictionary = new Dictionary <string, object>();

            this.ListSelecting(cmd);

            if (this.ControllerContext.ControllerDescriptor != null)
            {
                this._tracer.Info(this.Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, string.Format("Começando Get {0}", cmd.Type));
            }

            var attr = typeof(TModel).GetCustomAttributes(true).OfType <DataEntityAttribute>().FirstOrDefault();

            if (cmd.Type.Equals(AInBox.Astove.Core.Enums.EnumUtility.GetEnumText(GetTypes.InsertModel), StringComparison.CurrentCultureIgnoreCase))
            {
                try
                {
                    TRequestModel requestModel = new TRequestModel();
                    BaseEntity.SetDropDownOptions <TRequestModel, IBindingModel>(requestModel, this.Container);

                    this.ListSelected(requestModel);

                    return(Ok(requestModel));
                }
                catch (Exception ex)
                {
                    if (this.ControllerContext.ControllerDescriptor != null)
                    {
                        this._tracer.Info(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, "Tipo da exceção {0} {1}", ex.GetType(), ex.InnerException.GetType());
                    }

                    if (ex is ReflectionTypeLoadException || (ex.InnerException != null && ex.InnerException is ReflectionTypeLoadException))
                    {
                        ReflectionTypeLoadException typeLoadException = null;
                        if (ex.InnerException != null && ex.InnerException is ReflectionTypeLoadException)
                        {
                            typeLoadException = ex.InnerException as ReflectionTypeLoadException;
                        }
                        else
                        {
                            typeLoadException = ex as ReflectionTypeLoadException;
                        }

                        var loaderExceptins = typeLoadException.LoaderExceptions;
                        foreach (var tlex in loaderExceptins)
                        {
                            this._tracer.Error(Request, string.Format("{0} {1}", this.ControllerContext.ControllerDescriptor.ControllerType.FullName, tlex.GetType().FullName), "Erro: {0} {1}", new[] { tlex.Message, tlex.Source });
                        }
                    }
                    else
                    {
                        this._tracer.Debug(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, ex.InnerException);
                    }

                    //return InternalServerError(base.ErrorMessage(ex));
                    return(InternalServerError(ex));
                }
            }
            else if (cmd.Type.Equals(AInBox.Astove.Core.Enums.EnumUtility.GetEnumText(GetTypes.UpdateModel), StringComparison.CurrentCultureIgnoreCase))
            {
                try
                {
                    string[] includeProperties = null;
                    if (attr != null)
                    {
                        includeProperties = attr.Include;
                    }

                    TEntity entity = this.Service.GetSingle(cmd.EntityId, includeProperties);
                    if (entity == null)
                    {
                        NotFound();
                    }
                    //return Request.CreateErrorResponse(HttpStatusCode.NotFound, string.Format("{0} não encontrado(a)", typeof(TEntity).Name));

                    TUpdateRequestModel model = entity.ToModel <TUpdateRequestModel, IModel>(this.Container, false, 0);

                    this.ListSelected(model);

                    return(Ok(model));
                }
                catch (Exception ex)
                {
                    return(InternalServerError(ex));
                }
            }
            else if (cmd.Type.Equals(AInBox.Astove.Core.Enums.EnumUtility.GetEnumText(GetTypes.PagedGrid), StringComparison.CurrentCultureIgnoreCase))
            {
                if (this.ControllerContext.ControllerDescriptor != null)
                {
                    this._tracer.Info(this.Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, string.Format("Começando Get ", cmd.Type));
                }

                try
                {
                    var list = this.Service.GetEntities(this.Container, cmd, typeof(TModel), cmd.OrdersBy, cmd.Directions, (attr != null) ? attr.Include : null);

                    var paginatedModel = list.ToPaginatedModel <TModel>(null, null);
                    SetViews(paginatedModel.Items);

                    paginatedModel.Condition         = new Condition();
                    paginatedModel.ColumnDefinitions = ColumnFactory.GenerateColumnDefinitions <TModel>(ActionEnum.List).ToArray();

                    this.ListSelected(paginatedModel);

                    return(Ok(paginatedModel));
                }
                catch (Exception ex)
                {
                    if (this.ControllerContext.ControllerDescriptor != null)
                    {
                        this._tracer.Info(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, "Tipo da exceção {0} {1}", ex.GetType(), (ex.InnerException == null) ? null : ex.InnerException.GetType());
                    }

                    if (ex is ReflectionTypeLoadException || (ex.InnerException != null && ex.InnerException is ReflectionTypeLoadException))
                    {
                        ReflectionTypeLoadException typeLoadException = null;
                        if (ex.InnerException != null && ex.InnerException is ReflectionTypeLoadException)
                        {
                            typeLoadException = ex.InnerException as ReflectionTypeLoadException;
                        }
                        else
                        {
                            typeLoadException = ex as ReflectionTypeLoadException;
                        }

                        var loaderExceptins = typeLoadException.LoaderExceptions;
                        foreach (var tlex in loaderExceptins)
                        {
                            this._tracer.Error(Request, string.Format("{0} {1}", this.ControllerContext.ControllerDescriptor.ControllerType.FullName, tlex.GetType().FullName), "Erro: {0} {1}", new[] { tlex.Message, tlex.Source });
                        }
                    }
                    else if (this.ControllerContext.ControllerDescriptor != null)
                    {
                        this._tracer.Debug(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, ex);
                    }

                    return(InternalServerError(ex));
                }
            }

            try
            {
                var entities = this.Service.GetEntities(this.Container, cmd, typeof(TModel), cmd.OrdersBy, cmd.Directions, (attr != null) ? attr.Include : null);
                var paged    = entities.ToPaginatedModel <TModel>(null, null);
                SetViews(paged.Items);

                paged.ColumnDefinitions = ColumnFactory.GenerateColumnDefinitions <TModel>(ActionEnum.List).ToArray();
                paged.Condition         = new Condition();

                this.ListSelected(paged);

                return(Ok(paged));
            }
            catch (Exception ex)
            {
                if (this.ControllerContext.ControllerDescriptor != null)
                {
                    this._tracer.Info(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, "Tipo da exceção {0} {1}", ex.GetType(), ex.InnerException.GetType());
                }

                if (ex is ReflectionTypeLoadException || (ex.InnerException != null && ex.InnerException is ReflectionTypeLoadException))
                {
                    ReflectionTypeLoadException typeLoadException = null;
                    if (ex.InnerException != null && ex.InnerException is ReflectionTypeLoadException)
                    {
                        typeLoadException = ex.InnerException as ReflectionTypeLoadException;
                    }
                    else
                    {
                        typeLoadException = ex as ReflectionTypeLoadException;
                    }

                    var loaderExceptins = typeLoadException.LoaderExceptions;
                    foreach (var tlex in loaderExceptins)
                    {
                        this._tracer.Error(Request, string.Format("{0} {1}", this.ControllerContext.ControllerDescriptor.ControllerType.FullName, tlex.GetType().FullName), "Erro: {0} {1}", new[] { tlex.Message, tlex.Source });
                    }
                }
                else if (this.ControllerContext.ControllerDescriptor != null)
                {
                    this._tracer.Debug(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, ex.InnerException);
                }

                return(InternalServerError(ex));
            }
        }