private static async Task <(ActionExecutionDelegate actionExecutionDelegate, ActionExecutingContext executingContext)> ExecuteFilterForOrderItems(
            EquipmentFilter filter,
            IEnumerable <RequestOrderItem> orderItems
            )
        {
            IDictionary <string, object> actionArguments = new Dictionary <string, object>
            {
                ["someActionParameter"] = new InvoiceRequestModel {
                    OrderItems = orderItems
                }
            };

            var actionContext = new ActionContext(
                new DefaultHttpContext(),
                Substitute.For <RouteData>(),

                Substitute.For <ActionDescriptor>());

            var executingContext = new ActionExecutingContext(
                actionContext,
                Substitute.For <IList <IFilterMetadata> >(),
                actionArguments,
                null);

            ActionExecutionDelegate actionExecutionDelegate = Substitute.For <ActionExecutionDelegate>();

            await filter.OnActionExecutionAsync(executingContext, actionExecutionDelegate);

            return(actionExecutionDelegate, executingContext);
        }
コード例 #2
0
        public EquipmentFilter ParseFilter(string filters)
        {
            if (string.IsNullOrWhiteSpace(filters))
            {
                return(null);
            }
            var filterListString = filters.Split('_');
            var filterReturn     = new EquipmentFilter();

            foreach (var filterString in filterListString)
            {
                var parse = filterString.Split('=');
                var key   = parse[0];
                var value = parse[1];
                switch (key.ToLower())
                {
                case "number":
                {
                    filterReturn.Number = value;
                    break;
                }

                case "auditories":
                {
                    var auditories = value.Replace("[", string.Empty).Replace("]", string.Empty).Split(',');
                    filterReturn.Auditories = auditories.Select(int.Parse).ToList();
                    break;
                }
                }
            }
            return(filterReturn);
        }
        public async Task OnActionExecutionAsync_WhenOrderItems_ShouldReturnOnlyValidItems()
        {
            // Arrange
            var validOrderItems = new List <RequestOrderItem>
            {
                new RequestOrderItem {
                    EquipmentName = "Valid-Name-1", RentalDays = 1
                },
                new RequestOrderItem {
                    EquipmentName = "Valid-Name-2", RentalDays = 1
                }
            };

            var invalidOrderItems = new List <RequestOrderItem>
            {
                new RequestOrderItem {
                    EquipmentName = "Invalid-Name-1", RentalDays = 1
                },
                new RequestOrderItem {
                    EquipmentName = "Invalid-Name-2", RentalDays = 1
                }
            };

            IEnumerable <RequestOrderItem> allOrderItems = validOrderItems.Concat(invalidOrderItems);

            IEquipmentRepository equipmentRepository = Substitute.For <IEquipmentRepository>();

            equipmentRepository
            .DoesEquipmentExist(Arg.Is <string>(value => value.Contains("Valid-Name")))
            .Returns(true);

            equipmentRepository
            .DoesEquipmentExist(Arg.Is <string>(value => value.Contains("Invalid-Name")))
            .Returns(false);

            EquipmentFilter equipmentFilter = new EquipmentFilter(equipmentRepository);

            // Act
            var result = await ExecuteFilterForOrderItems(equipmentFilter, allOrderItems);

            // Assert
            result.executingContext.ActionArguments
            .Values
            .Cast <InvoiceRequestModel>()
            .First().OrderItems
            .Should()
            .BeEquivalentTo(validOrderItems);
        }
コード例 #4
0
        public StaticPagedList <EquipmentDto> GetList(EquipmentFilter filter, SortModel sort, int page, int count)
        {
            var equipments = _repository.TableNoTracking <Equipment>();

            #region Filter

            if (filter != null)
            {
                if (!string.IsNullOrWhiteSpace(filter.Number))
                {
                    equipments = equipments.Where(x => x.Number.Contains(filter.Number));
                }
                if (filter.Auditories != null && filter.Auditories.Count != 0)
                {
                    equipments = equipments.Where(x => filter.Auditories.Contains(x.AuditoryId));
                }
            }

            var countElement = equipments.Count();
            #endregion

            #region Order

            equipments = sort != null
                ? equipments.OrderBy($"{sort.Column} {sort.Order}").Skip(count * (page - 1)).Take(count)
                : equipments.OrderByDescending(x => x.CreatedAt).Skip(count * (page - 1)).Take(count);

            #endregion

            #region Convert to dto

            var equipmentDtos = equipments.Select(x => new EquipmentDto
            {
                Name       = x.Name,
                Id         = x.Id,
                AuditoryId = x.AuditoryId,
                Note       = x.Note,
                Number     = x.Number,
                State      = x.State
            }).ToList();

            #endregion

            equipmentDtos.ForEach(x => x.Auditory = _dicService.GetDictionaryValues("TaskAuditory").Single(dic => dic.Id == x.AuditoryId).Value);

            return(new StaticPagedList <EquipmentDto>(equipmentDtos, page, count, countElement));
        }
コード例 #5
0
        public async Task <PagedList <EquipmentListDto> > GetEquipments([FromQuery] PageParams pageParams, [FromQuery] int userId, [FromQuery] EquipmentFilter eqFilters, [FromQuery] bool isAdmin)
        {
            var myEquipments = await _repo.ListMyEquipments(pageParams, userId, eqFilters, isAdmin);

            Response.AddPagination(myEquipments.CurrentPage, myEquipments.PageSize, myEquipments.TotalCount, myEquipments.TotalPages);
            return(myEquipments);
        }
コード例 #6
0
 private static List<EquipmentType> FilterByOrderType(List<EquipmentType> equipment, EquipmentFilter filter)
 {
     switch (filter)
     {
         case EquipmentFilter.DropshipOnly:
             return equipment.Where(e => e.MaxDropshipQuantity > 0).ToList();
         case EquipmentFilter.FieldOnly:
             return equipment.Where(e => e.MaxFieldOrderQuantity > 0).ToList();
         default:
             return equipment;
     }
 }
コード例 #7
0
 /// <summary>
 /// Gets equipment that is able to be ordered for the specified order type and which the user has permissions to order
 /// </summary>
 /// <param name="userRoles"></param>
 /// <param name="filter"></param>
 /// <param name="userId"></param>
 /// <returns></returns>
 public static List<EquipmentType> GetCatalog(List<int> userRoles, EquipmentFilter filter, string userId)
 {
     var returnList = FilterByOrderType(FilterCategoryByRoles(Catalog, userRoles, userId), filter).ToList();
     return returnList;
 }
コード例 #8
0
 /// <summary>
 /// Gets equipment that is able to be ordered for the specified order type and which the user has permissions to order
 /// </summary>
 /// <param name="userRoles"></param>
 /// <param name="filter"></param>
 /// <param name="userId"></param>
 /// <param name="catalogId"></param>
 /// <returns></returns>
 public static IEnumerable<EquipmentType> GetCatalog(List<int> userRoles, EquipmentFilter filter, string userId, int catalogId)
 {
     var returnList = FilterByOrderType(FilterCategoryByRoles(Catalog, userRoles, userId,catalogId ), filter);
     return returnList;
 }
コード例 #9
0
 /// <summary>
 /// Gets equipment that is able to be ordered for the type of order specified
 /// </summary>
 /// <param name="filter"></param>
 /// <returns></returns>
 public static List<EquipmentType> GetCatalog(EquipmentFilter filter)
 {
     return FilterByOrderType(Catalog, filter);
 }
コード例 #10
0
        public async Task <PagedList <EquipmentListDto> > ListMyEquipments(PageParams pageParams, int userId, EquipmentFilter eqFilters, bool isAdmin)
        {
            List <EquipmentListDto> lstEquipments = new List <EquipmentListDto>();


            if (isAdmin)
            {
                foreach (Equipments eq in await _context.Equipments.Where(x => x.UserId == userId || isAdmin).ToListAsync())
                {
                    if (!lstEquipments.Any(x => x.EqName == eq.EqName))
                    {
                        // pobranie nazwy bohatera dla ekwipunku
                        var hero = await _context.Heroes.FirstOrDefaultAsync(x => x.Id == eq.HeroId);

                        // pobranie poziomu bohatera dla ekwipunku
                        var heroLvl = await _context.UserHeroesLvl.FirstOrDefaultAsync(x => x.EquipmentId == eq.Id);

                        // pobranie ilości lajków dla ekwipunku
                        var counterOfLikes = await _context.Likes.CountAsync(x => x.EquipmentId == eq.Id);

                        // pobranie nazwy użytkownika
                        var userName = await _context.Users.FirstOrDefaultAsync(x => x.Id == eq.UserId);

                        var gameName = await _context.Games.FirstOrDefaultAsync(x => x.Id == eq.GameId);

                        var eqWithoutShared = new EquipmentListDto()
                        {
                            EquipmentId    = eq.Id,
                            EqName         = eq.EqName,
                            HeroName       = hero.HeroName,
                            HeroLvl        = heroLvl != null ? 1 : (int)heroLvl.Lvl,
                            CounterOfLikes = counterOfLikes,
                            UserName       = userName.UserName,
                            GameName       = gameName.GameName,
                            GameId         = gameName.Id
                        };

                        lstEquipments.Add(eqWithoutShared);
                    }
                }
            }
            else
            {
                //pobranie grup uzytkownika
                var userGroups = await _context.UserToGroups.Where(x => x.UserId == userId).ToListAsync();

                if (userGroups.Count > 0)
                {
                    //pobranie ekwipunkow udostępnionych dla grup użytkowników
                    foreach (UserToGroups groupId in await _context.UserToGroups.Where(x => x.UserId == userId).ToListAsync())
                    {
                        foreach (EquipmentsToGroup eqToGroup in await _context.EquipmentsToGroup.Where(x => x.GroupId == groupId.GroupId).ToListAsync())
                        {
                            if (await _context.Equipments.AnyAsync(x => x.Id == eqToGroup.EquipmentId))
                            {
                                Equipments sharedEquipment = await _context.Equipments.FirstOrDefaultAsync(x => x.Id == eqToGroup.EquipmentId);

                                // pobranie nazwy bohatera dla ekwipunku
                                var hero = await _context.Heroes.FirstOrDefaultAsync(x => x.Id == sharedEquipment.HeroId);

                                // pobranie poziomu bohatera dla ekwipunku
                                var heroLvl = await _context.UserHeroesLvl.FirstOrDefaultAsync(x => x.EquipmentId == sharedEquipment.Id);

                                // pobranie ilości lajków dla ekwipunku
                                var counterOfLikes = await _context.Likes.CountAsync(x => x.EquipmentId == sharedEquipment.Id);

                                // pobranie nazwy użytkownika
                                var userName = await _context.Users.FirstOrDefaultAsync(x => x.Id == sharedEquipment.UserId);

                                var gameName = await _context.Games.FirstOrDefaultAsync(x => x.Id == sharedEquipment.GameId);

                                var eqWithoutShared = new EquipmentListDto()
                                {
                                    EquipmentId    = sharedEquipment.Id,
                                    EqName         = sharedEquipment.EqName,
                                    HeroName       = hero.HeroName,
                                    HeroLvl        = (int)heroLvl.Lvl,
                                    CounterOfLikes = counterOfLikes,
                                    UserName       = userName.UserName,
                                    GameName       = gameName.GameName,
                                    GameId         = gameName.Id
                                };

                                lstEquipments.Add(eqWithoutShared);
                            }
                        }
                    }
                }


                foreach (Equipments eq in await _context.Equipments.Where(x => x.UserId == userId).ToListAsync())
                {
                    if (!lstEquipments.Any(x => x.EqName == eq.EqName))
                    {
                        // pobranie nazwy bohatera dla ekwipunku
                        var hero = await _context.Heroes.FirstOrDefaultAsync(x => x.Id == eq.HeroId);

                        // pobranie poziomu bohatera dla ekwipunku
                        var heroLvl = await _context.UserHeroesLvl.FirstOrDefaultAsync(x => x.EquipmentId == eq.Id);

                        // pobranie ilości lajków dla ekwipunku
                        var counterOfLikes = await _context.Likes.CountAsync(x => x.EquipmentId == eq.Id);

                        // pobranie nazwy użytkownika
                        var userName = await _context.Users.FirstOrDefaultAsync(x => x.Id == eq.UserId);

                        var gameName = await _context.Games.FirstOrDefaultAsync(x => x.Id == eq.GameId);

                        var eqWithoutShared = new EquipmentListDto()
                        {
                            EquipmentId    = eq.Id,
                            EqName         = eq.EqName,
                            HeroName       = hero.HeroName,
                            HeroLvl        = (int)heroLvl.Lvl,
                            CounterOfLikes = counterOfLikes,
                            UserName       = userName.UserName,
                            GameName       = gameName.GameName,
                            GameId         = gameName.Id
                        };

                        lstEquipments.Add(eqWithoutShared);
                    }
                }
            }

            if (eqFilters != null)
            {
                lstEquipments = lstEquipments.Where(x => x.HeroLvl >= eqFilters.HeroLvlFrom && x.HeroLvl <= eqFilters.HeroLvlTo).ToList();

                if (eqFilters.EquipmentNameLike != null)
                {
                    lstEquipments = lstEquipments.Where(x => x.EqName.ToLower().Contains(eqFilters.EquipmentNameLike.ToLower())).ToList();
                }

                if (eqFilters.UserNameLike != null)
                {
                    lstEquipments = lstEquipments.Where(x => x.UserName.ToLower().Contains(eqFilters.UserNameLike.ToLower())).ToList();
                }

                if (eqFilters.HeroNameLike != null)
                {
                    lstEquipments = lstEquipments.Where(x => x.HeroName.ToLower().Contains(eqFilters.HeroNameLike.ToLower())).ToList();
                }

                if (eqFilters.GameId != 0)
                {
                    lstEquipments = lstEquipments.Where(x => x.GameId == eqFilters.GameId).ToList();
                }
            }

            return(await PagedList <EquipmentListDto> .Create(lstEquipments, pageParams.PageNumber, pageParams.PageSize));

            // return querableEq;
        }
コード例 #11
0
 public ActionResult Filter(EquipmentFilter equipmentFilter)
 {
     return(ActionResponse(Data: _EquipmentBO.Filter(equipmentFilter), BusinessObject: _EquipmentBO));
 }