public DataResponse <EntityList <EntityRoles> > GetRoles(FilterRoles filter, int currentBusineId, int take = 10, int skip = 0)
        {
            var response = new DataResponse <EntityList <EntityRoles> >();

            try
            {
                if (filter != null)
                {
                    take = filter.Take;
                    skip = filter.Skip;
                }
                base.DBInit();
                var query = DBEntity.Roles.Where(a => a.BusinessId == currentBusineId);
                if (filter != null)
                {
                    if (!String.IsNullOrEmpty(filter.KeyWords))
                    {
                        query = query.Where(a => a.Name.ToLower().Contains(filter.KeyWords));
                    }
                }

                var selectQuery = query.Select(a => new EntityRoles
                {
                    Id          = a.Id,
                    Name        = a.Name,
                    Description = a.Description,
                    Status      = a.Status,
                    CreatedBy   = a.CreatedBy,
                    CreatedOn   = a.CreatedOn,
                    BusinessId  = a.BusinessId,
                    IsActive    = a.IsActive,
                    OldId       = a.OldId,
                });

                if (string.IsNullOrEmpty(filter.SortKey) || string.IsNullOrEmpty(filter.SortOrder))
                {
                    selectQuery = selectQuery.OrderByDescending(o => o.CreatedOn);
                }
                else
                {
                    string orderBy = string.Format("{0} {1}", filter.SortKey, filter.SortOrder);
                    selectQuery = selectQuery.OrderBy(orderBy);
                }
                response = GetList <EntityRoles>(selectQuery, skip, take);
            }
            catch (Exception ex)
            {
                ex.Log();
            }
            finally
            {
                base.DBClose();
            }

            return(response);
        }
        public IHttpActionResult GetAllRoles(FilterRoles filter)
        {
            if (filter == null)
            {
                filter             = new FilterRoles();
                filter.PageSize    = 25;
                filter.CurrentPage = 1;
            }
            var response = repository.GetRoles(filter, CurrentBusinessId.Value);

            return(Ok <DataResponse <EntityList <EntityRoles> > >(response));
        }
Example #3
0
        public IHttpActionResult GetByFilter(FilterRoles filter)
        {
            var repository = new RepositoryRoles();

            if (filter == null)
            {
                filter = new FilterRoles {
                    PageSize = 25, CurrentPage = 1
                }
            }
            ;
            var response = repository.GetRoles(filter, CurrentBusinessId.Value);

            return(Ok <DataResponse <EntityList <EntityRoles> > >(response));
        }