Example #1
0
        public async Task <IActionResult> List(int?PageIndex, int?Name)
        {
            List <Employee> empl = new List <Employee>();


            AppUser user = await userManager.FindByNameAsync(User.Identity.Name);

            int companyId = await context.WorkPlaces.Where(x => x.EmployeeId == user.EmployeeId && x.ExitDate == null).Select(x => x.Branch.CompanyId).FirstOrDefaultAsync();

            var employeeId = context.WorkPlaces.Where(x => x.Branch.CompanyId == companyId && x.ExitDate == null).Select(x => x.EmployeeId);

            foreach (var item in employeeId)
            {
                var employees = context.Employees.Where(x => x.Id == item).Select(x => x);
                empl.AddRange(employees);
            }
            int Page = 8;

            EmployeeModel emp = new EmployeeModel
            {
                Employees  = Pagination <Employee> .Create(empl, PageIndex ?? 1, Page),
                Pagination = Pagination <Employee> .Create(empl, PageIndex ?? 1, Page)
            };

            return(View(emp));
        }
        public async Task <IActionResult> List(int?PageIndex)
        {
            List <EmployeeWorkplacePositionFullModel> empl = new List <EmployeeWorkplacePositionFullModel>();

            AppUser user = await userManager.FindByNameAsync(User.Identity.Name);

            var DepartmentId_CompanyId = await context.WorkPlaces.Where(x => x.EmployeeId == user.EmployeeId && x.ExitDate == null)
                                         .Select(x => new { x.Branch.CompanyId, x.Position.DepartmentId })
                                         .FirstOrDefaultAsync();

            var employeeId = context.WorkPlaces
                             .Where(x =>
                                    x.Branch.CompanyId == DepartmentId_CompanyId.CompanyId &&
                                    x.Position.DepartmentId == DepartmentId_CompanyId.DepartmentId &&
                                    x.ExitDate == null)
                             .Select(x => x.EmployeeId);

            foreach (var item in employeeId)
            {
                var employees = await context.Employees.Where(x => x.Id == item)
                                .Join(context.WorkPlaces.Where(w => w.ExitDate == null), e => e.Id, w => w.EmployeeId, (employee, workplace) => new { employee, workplace })
                                .Join(context.Branches, x => x.workplace.BranchId, b => b.Id, (x, b) => new { x, b })
                                .Join(context.Companies, v => v.b.CompanyId, c => c.Id, (v, c) => new { v, c })
                                .Join(context.Positions, t => t.v.x.workplace.PositionId, p => p.Id, (model, position) => new { model, position })
                                .Join(context.Departments, z => z.position.DepartmentId, d => d.Id, (z, department) =>
                                      new EmployeeWorkplacePositionFullModel
                {
                    E_id           = z.model.v.x.employee.Id,
                    Ename          = z.model.v.x.employee.Name,
                    Surname        = z.model.v.x.employee.Surname,
                    FatherName     = z.model.v.x.employee.FatherName,
                    workplaceId    = z.model.v.x.workplace.Id,
                    Bonuses        = z.model.v.x.employee.Bonuses.Where(x => x.EmployeeId == z.model.v.x.employee.Id).ToList(),
                    Penalties      = z.model.v.x.employee.Penalties.Where(x => x.EmployeeId == z.model.v.x.employee.Id).ToList(),
                    EntryDate      = z.model.v.x.workplace.EntryDate,
                    BranchName     = z.model.v.b.Name,
                    IsHead         = z.model.v.b.IsHead,
                    CompanyName    = z.model.c.Name,
                    PositionName   = z.position.Namme,
                    DepartmentName = department.Name
                }).ToListAsync();

                empl.AddRange(employees);
            }

            int Page = 2;

            Employee_Incentive_Model Employee_Incentive_Model = new Employee_Incentive_Model
            {
                EmployeeWorkplacePositionFullModel = Pagination <EmployeeWorkplacePositionFullModel> .Create(empl, PageIndex ?? 1, Page),
                Pagination = Pagination <EmployeeWorkplacePositionFullModel> .Create(empl, PageIndex ?? 1, Page),
                Month      = DateTime.Now.Month,
                Year       = DateTime.Now.Year,
                Days       = Enumerable.Range(1, DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)).ToList()
            };

            return(View(Employee_Incentive_Model));
        }
            public async Task <Pagination <BookViewModel> > Handle(Query request, CancellationToken cancellationToken)
            {
                using var streamReader = new StreamReader($"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}/Books/Data/books.json");
                string json = await streamReader.ReadToEndAsync();

                var books = JsonConvert.DeserializeObject <List <BookViewModel> >(json);

                return(Pagination <BookViewModel> .Create(books, request.PageIndex, request.PageSize, request.FilterColumn, request.SearchTerm));
            }
Example #4
0
        /// <summary>
        /// Default action, retrives list of all clothes with possible filtering/sorting and pagination
        /// </summary>
        /// <param name="search">Helper phrase for handling filering with pagination</param>
        /// <param name="pageNum">current page number</param>
        /// <param name="filter">phrase for filtering list for desired items</param>
        /// <param name="sortingOrder">Order in wchich items are presented. Can contain sorting for every parameter in ascending or descending order</param>
        /// <returns>List of clothes</returns>
        public IActionResult Index(string search, int?pageNum, string filter, string sortingOrder)
        {
            var clothes = _clothingRepository.GetAll();

            #region pagination
            if (search != null)
            {
                pageNum = 1;
            }
            else
            {
                search = filter;
            }
            #endregion

            #region filtering
            ViewData["filter"] = filter;
            if (!String.IsNullOrEmpty(filter))
            {
                clothes = clothes.Where(c => c.Name.Contains(filter) || c.Color.Contains(filter) || c.Material.Contains(filter));
            }
            #endregion

            #region sorting
            //Field for holding way of sorting for pagination
            ViewData["CurrentSortingMethod"] = sortingOrder;

            ViewData["NameSortParm"]     = sortingOrder == "name" ? "name_desc" : "name";
            ViewData["ColorSortParm"]    = sortingOrder == "color" ? "color_desc" : "color";
            ViewData["MaterialSortParm"] = sortingOrder == "material" ? "material_desc" : "material";
            ViewData["DateSortParm"]     = sortingOrder == "date" ? "date_desc" : "date";
            switch (sortingOrder)
            {
            case "name": clothes = clothes.OrderBy(c => c.Name); break;

            case "name_desc": clothes = clothes.OrderByDescending(c => c.Name); break;

            case "color": clothes = clothes.OrderBy(c => c.Color); break;

            case "color_desc": clothes = clothes.OrderByDescending(c => c.Color); break;

            case "material": clothes = clothes.OrderBy(c => c.Material); break;

            case "material_desc": clothes = clothes.OrderByDescending(c => c.Material); break;

            case "date": clothes = clothes.OrderBy(c => c.DateAdded); break;

            case "date_desc": clothes = clothes.OrderByDescending(c => c.DateAdded); break;

            default: break;
            }
            #endregion

            //returns new paginated list with source, currently viewed index and size of page(how many entries are displayed)
            return(View(Pagination <Clothing> .Create(clothes, pageIndex: pageNum ?? 1, pageSize: 9)));
        }
Example #5
0
 public Pagination <Warehouse> GetAll(int?page, Expression <Func <Warehouse, bool> > predicate, int pageSize)
 {
     try
     {
         var query = _facturacionDbContext.Warehouse.AsExpandable().Where(predicate).AsQueryable();
         return(Pagination <Warehouse> .Create(query, page ?? 1, pageSize));
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Example #6
0
        public Pagination <Person> GetAll(int?page, Expression <Func <Person, bool> > predicate)
        {
            try
            {
                var query = _facturacionDbContext.Person.AsExpandable().Where(predicate).AsQueryable();

                return(Pagination <Person> .Create(query, page ?? 1, 5));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #7
0
        public Pagination <Product> GetAll(int?page, Expression <Func <Product, bool> > predicate)
        {
            try
            {
                var query = _facturacionDbContext.Product.Include(x => x.Warehouse)
                            .AsExpandable().Where(predicate).AsQueryable();

                return(Pagination <Product> .Create(query, page ?? 1, 5));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #8
0
        public Pagination <Order> GetAll(int?page, Expression <Func <Order, bool> > expression)
        {
            try
            {
                var query = _facturacionDbContext.Order.Include(x => x.OrderDetails)
                            .Include(x => x.Person)
                            .AsExpandable().Where(expression).AsQueryable();

                return(Pagination <Order> .Create(query, page ?? 1, 5));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #9
0
 public ISelect <T> Limit(int take, long offset = 0)
 {
     _sb = new StringBuilder(_provider.FormatQueryPagination(_sb.ToString(), Pagination.Create(offset, take), _writer.Parameters));
     return(this);
 }
Example #10
0
        public async Task <ActionResult <Pagination <RecipeReturn> > > GetRecipes(string orderBy, string ingredientsType, string search, int?page, int?pageSize, int recipeTypeId)
        {
            var recipes = await _unitOfWork.Recipe.GetAll(includeProperties : "RecipeType");

            var ingredients = await _unitOfWork.Ingredient.GetAll();

            var prepartionSteps = await _unitOfWork.PreparationStep.GetAll();

            switch (orderBy)
            {
            case "fast":
                recipes = recipes.OrderBy(x => x.PreparationTime);
                break;

            case "new":
                break;

            default:
                recipes = recipes.OrderBy(x => x.Name);
                break;
            }
            switch (ingredientsType)
            {
            case "vege":
                recipes = recipes.Where(x => x.IngredientsType.ToString() == "Wegetariańskie");
                break;

            case "vegan":
                recipes = recipes.Where(x => x.IngredientsType.ToString() == "Wegańskie");
                break;

            case "meat":
                recipes = recipes.Where(x => x.IngredientsType.ToString() == "Mięsne");
                break;
            }
            if (search != null)
            {
                recipes = recipes.Where(x => EF.Functions.Like(x.Name, $"%{search}%"));
            }

            if (recipeTypeId > 0)
            {
                recipes = recipes.Where(x => x.RecipeTypeId == recipeTypeId);
            }

            var data = recipes.Select(recipe => new RecipeReturn
            {
                Id              = recipe.Id,
                Name            = recipe.Name,
                PreparationTime = recipe.PreparationTime,
                Description     = recipe.Description,
                ImageUrl        = _config["ApiUrl"] + recipe.ImageUrl,
                IngredientsType = Enum.GetName(typeof(IngredientsType), recipe.IngredientsType),
                Difficulty      = Enum.GetName(typeof(Difficulty), recipe.Difficulty),
                RecipeType      = recipe.RecipeType.Name,
                Ingredients     = ingredients.Where(x => x.RecipeId == recipe.Id).Select(ingredient => new IngredientReturn
                {
                    Id   = ingredient.Id,
                    Name = ingredient.Name
                }).ToList(),
                PreparationSteps = prepartionSteps.Where(x => x.RecipeId == recipe.Id).Select(step => new PreparationStepReturn
                {
                    Id   = step.Id,
                    Name = step.Name
                }).ToList()
            }).ToList();

            return(Ok(Pagination <RecipeReturn> .Create(data, page ?? 1, pageSize ?? 10)));
        }
Example #11
0
        public void pagination()
        {
            var p = _db.QueryPaged(q => q.From <User>().OrderBy(d => d.Id).SelectAll(), Pagination.Create(1, 1));

            p.Count.Should().Be(3);
            p.Items.First().Should().BeEquivalentTo(_inserted[1], d => d.Excluding(s => s.Id).Excluding(s => s.CreatedOn));
        }
Example #12
0
        public void page_from_skips()
        {
            var p = Pagination.Create(12, 5);

            Assert.Equal(3, p.Page);
        }