Example #1
0
        public IHttpActionResult GetAll(FilterPrivilegeModule filter)
        {
            if (filter == null)
            {
                filter             = new FilterPrivilegeModule();
                filter.PageSize    = 25;
                filter.CurrentPage = 1;
            }
            var response = repository.GetAllPrivilegeModules(filter);

            return(Ok <DataResponse <EntityList <EntityPrivilegeModules> > >(response));
        }
Example #2
0
        public DataResponse <EntityList <EntityPrivilegeModules> > GetAllPrivilegeModules(FilterPrivilegeModule filter, int take = 10, int skip = 0)
        {
            var response = new DataResponse <EntityList <EntityPrivilegeModules> >();

            try
            {
                base.DBInit();

                if (filter != null)
                {
                    take = filter.Take;
                    skip = filter.Skip;
                }
                var query = DBEntity.ModulesMasters.Where(a => 1 == 1);
                if (!string.IsNullOrEmpty(filter.KeyWords))
                {
                    query = query.Where(ua => ua.Title.ToLower().Contains(filter.KeyWords.ToLower()) || ua.Description.ToLower().Contains(filter.KeyWords.ToLower()));
                }

                var selectQuery = query.Select(a => new EntityPrivilegeModules
                {
                    Id          = a.Id,
                    Title       = a.Title,
                    Description = a.Description,
                    CreatedUser = a.User.FirstName,
                    CreatedOn   = a.CreatedOn,
                    Updateduser = a.User1 == null ? null : a.User1.FirstName,
                    UpdatedOn   = a.UpdatedOn,
                    IsActive    = a.IsActive
                });

                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 <EntityPrivilegeModules>(selectQuery, skip, take);
            }
            catch (Exception ex)
            {
                ex.Log();
            }
            finally
            {
                base.DBClose();
            }
            return(response);
        }