コード例 #1
0
ファイル: ItemsController.cs プロジェクト: oppahansi/WoWAPI
        public async Task <IActionResult> GetItems([FromQuery] ItemFilterParams filterParams)
        {
            try
            {
                var itemList = await _repository.ItemTemplateRepo.GetAllItemTemplatesAsync(filterParams);

                var paginatedItemList = await PaginatedList <CItemTemplate> .CreateAsync(itemList, filterParams.Page, filterParams.PageSize > 100? 100 : filterParams.PageSize);

                var returnObject = new
                {
                    category   = "items",
                    page       = paginatedItemList.PageIndex,
                    totalPages = paginatedItemList.TotalPages,
                    pageSize   = paginatedItemList.PageSize,
                    items      = paginatedItemList.CreateResultObject(filterParams.Class)
                };

                _logger.LogInfo($"Returned items.");

                return(Ok(returnObject));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Some error in the GetItems method: {ex}");
                return(StatusCode(500, "Internal server error"));
            }
        }
コード例 #2
0
ファイル: CommonExtensions.cs プロジェクト: oppahansi/WoWAPI
 public static bool IsEmpty(this ItemFilterParams itemFilterParams)
 {
     return
         (string.IsNullOrEmpty(itemFilterParams.Name) &&
          string.IsNullOrEmpty(itemFilterParams.Description) &&
          itemFilterParams.Class == 100 &&
          itemFilterParams.Subclass == 100 &&
          itemFilterParams.Quality == 100 &&
          itemFilterParams.Flags == 0 &&
          itemFilterParams.InventoryType == 100 &&
          itemFilterParams.AllowableClass == -2 &&
          itemFilterParams.AllowableRace == -2 &&
          itemFilterParams.RequiredLevel == 0 &&
          itemFilterParams.RequiredSkill == 0 &&
          itemFilterParams.RequiredSkillRank == 0 &&
          itemFilterParams.RequiredSpell == 0 &&
          itemFilterParams.RequiredHonorRank == 0 &&
          itemFilterParams.RequiredCityRank == 0 &&
          itemFilterParams.RequiredReputationFaction == 0 &&
          itemFilterParams.RequiredReputationRank == 0 &&
          itemFilterParams.ContainerSlots == 0 &&
          itemFilterParams.StatType == 100 &&
          itemFilterParams.StatValue == 0 &&
          itemFilterParams.Dps == 0 &&
          itemFilterParams.DmgMin == 0 &&
          itemFilterParams.DmgMax == 0 &&
          itemFilterParams.DmgType == 100 &&
          itemFilterParams.Armor == 0 &&
          itemFilterParams.Resistance == 0 &&
          itemFilterParams.HolyRes == 0 &&
          itemFilterParams.FireRes == 0 &&
          itemFilterParams.NatureRes == 0 &&
          itemFilterParams.FrostRes == 0 &&
          itemFilterParams.ShadowRes == 0 &&
          itemFilterParams.ArcaneRes == 0 &&
          itemFilterParams.Speed == 0 &&
          itemFilterParams.AmmoType == 0 &&
          itemFilterParams.SpellTrigger == 100 &&
          itemFilterParams.Bonding == 0 &&
          itemFilterParams.StartQuest == 0 &&
          itemFilterParams.LockId == 0 &&
          itemFilterParams.Material == 0 &&
          itemFilterParams.Sheath == 0 &&
          itemFilterParams.Block == 0 &&
          itemFilterParams.ItemSet == 0 &&
          itemFilterParams.Durability == 0 &&
          itemFilterParams.Area == 100 &&
          itemFilterParams.Map == 100 &&
          itemFilterParams.BagFamily == 0 &&
          itemFilterParams.DisenchantId == 0 &&
          itemFilterParams.FoodType == 0 &&
          itemFilterParams.MoneyLoot == 0 &&
          itemFilterParams.Duration == 0 &&
          itemFilterParams.Entries.Count() == 0);
 }
コード例 #3
0
        public async Task <IEnumerable <CItemTemplate> > GetAllItemTemplatesAsync(ItemFilterParams filterParams)
        {
            IEnumerable <CItemTemplate> itemTemplates;

            if (filterParams.IsEmpty())
            {
                itemTemplates = await FindAllAsync();
            }
            else
            {
                itemTemplates = await FindAllByConditionsAsync(filterParams.AsFilters(), filterParams.FilterType, filterParams.ToCacheString());
            }

            return(itemTemplates.OrderItemTemplates(filterParams.SortOrder));
        }
コード例 #4
0
ファイル: CommonExtensions.cs プロジェクト: oppahansi/WoWAPI
        public static List <Func <CItemTemplate, bool> > AsFilters(this ItemFilterParams filterParams)
        {
            var filters = new List <Func <CItemTemplate, bool> >();

            if (!string.IsNullOrEmpty(filterParams.Name))
            {
                filters.Add(x => x.Name.ToLower().CompareTo(filterParams.Name.ToLower()) == 0 ||  x.Name.ToLower().Contains(filterParams.Name.ToLower()));
            }

            if (!string.IsNullOrEmpty(filterParams.Description))
            {
                filters.Add(x =>
                {
                    if (!string.IsNullOrEmpty(x.Description))
                    {
                        return(x.Description.ToLower().CompareTo(filterParams.Description.ToLower()) == 0 ||  x.Description.ToLower().Contains(filterParams.Description.ToLower()));
                    }
                    else
                    {
                        return(false);
                    }
                });
            }

            if (filterParams.Class != 100)
            {
                filters.Add(x => x.Class == filterParams.Class);
            }

            if (filterParams.Subclass != 100)
            {
                filters.Add(x => x.Subclass == filterParams.Subclass);
            }

            if (filterParams.Quality != 100)
            {
                filters.Add(x => x.Quality == filterParams.Quality);
            }

            if (filterParams.Flags != 0)
            {
                filters.Add(x => x.Flags == filterParams.Flags);
            }

            if (filterParams.InventoryType != 100)
            {
                filters.Add(x => x.InventoryType == filterParams.InventoryType);
            }

            if (filterParams.AllowableClass != -2)
            {
                filters.Add(x => x.AllowableClass == filterParams.AllowableClass);
            }

            if (filterParams.AllowableRace != -2)
            {
                filters.Add(x => x.AllowableRace == filterParams.AllowableRace);
            }

            if (filterParams.RequiredLevel != 0)
            {
                filters.Add(x => x.RequiredLevel == filterParams.RequiredLevel);
            }

            if (filterParams.RequiredSkill != 0)
            {
                filters.Add(x => x.RequiredSkill == filterParams.RequiredSkill);
            }

            if (filterParams.RequiredSkillRank != 0)
            {
                filters.Add(x => x.RequiredSkillRank == filterParams.RequiredSkillRank);
            }

            if (filterParams.RequiredSpell != 0)
            {
                filters.Add(x => x.Requiredspell == filterParams.RequiredSpell);
            }

            if (filterParams.RequiredHonorRank != 0)
            {
                filters.Add(x => x.Requiredhonorrank == filterParams.RequiredHonorRank);
            }

            if (filterParams.RequiredCityRank != 0)
            {
                filters.Add(x => x.RequiredCityRank == filterParams.RequiredCityRank);
            }

            if (filterParams.RequiredReputationFaction != 0)
            {
                filters.Add(x => x.RequiredReputationFaction == filterParams.RequiredReputationFaction);
            }

            if (filterParams.RequiredReputationRank != 0)
            {
                filters.Add(x => x.RequiredReputationRank == filterParams.RequiredReputationRank);
            }

            if (filterParams.ContainerSlots != 0)
            {
                filters.Add(x => x.ContainerSlots == filterParams.ContainerSlots);
            }

            if (filterParams.StatType != 100)
            {
                filters.Add(x =>
                {
                    if (x.StatType1 == filterParams.StatType)
                    {
                        if (filterParams.StatValue != 0)
                        {
                            return(x.StatValue1 == filterParams.StatValue);
                        }
                        else
                        {
                            return(true);
                        }
                    }
                    else if (x.StatType2 == filterParams.StatType)
                    {
                        if (filterParams.StatValue != 0)
                        {
                            return(x.StatValue2 == filterParams.StatValue);
                        }
                        else
                        {
                            return(true);
                        }
                    }
                    else if (x.StatType3 == filterParams.StatType)
                    {
                        if (filterParams.StatValue != 0)
                        {
                            return(x.StatValue3 == filterParams.StatValue);
                        }
                        else
                        {
                            return(true);
                        }
                    }
                    else if (x.StatType4 == filterParams.StatType)
                    {
                        if (filterParams.StatValue != 0)
                        {
                            return(x.StatValue4 == filterParams.StatValue);
                        }
                        else
                        {
                            return(true);
                        }
                    }
                    else if (x.StatType5 == filterParams.StatType)
                    {
                        if (filterParams.StatValue != 0)
                        {
                            return(x.StatValue5 == filterParams.StatValue);
                        }
                        else
                        {
                            return(true);
                        }
                    }
                    else if (x.StatType6 == filterParams.StatType)
                    {
                        if (filterParams.StatValue != 0)
                        {
                            return(x.StatValue6 == filterParams.StatValue);
                        }
                        else
                        {
                            return(true);
                        }
                    }
                    else if (x.StatType7 == filterParams.StatType)
                    {
                        if (filterParams.StatValue != 0)
                        {
                            return(x.StatValue7 == filterParams.StatValue);
                        }
                        else
                        {
                            return(true);
                        }
                    }
                    else if (x.StatType8 == filterParams.StatType)
                    {
                        if (filterParams.StatValue != 0)
                        {
                            return(x.StatValue8 == filterParams.StatValue);
                        }
                        else
                        {
                            return(true);
                        }
                    }
                    else if (x.StatType9 == filterParams.StatType)
                    {
                        if (filterParams.StatValue != 0)
                        {
                            return(x.StatValue9 == filterParams.StatValue);
                        }
                        else
                        {
                            return(true);
                        }
                    }
                    else if (x.StatType10 == filterParams.StatType)
                    {
                        if (filterParams.StatValue != 0)
                        {
                            return(x.StatValue10 == filterParams.StatValue);
                        }
                        else
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                });
            }

            if (filterParams.Dps != 0)
            {
                filters.Add(x => x.CalculateItemDps() == filterParams.Dps);
            }

            if (filterParams.DmgMin != 0)
            {
                filters.Add(x => x.DmgMin1 == filterParams.DmgMin || x.DmgMin2 == filterParams.DmgMin);
            }

            if (filterParams.DmgMax != 0)
            {
                filters.Add(x => x.DmgMax1 == filterParams.DmgMax ||  x.DmgMax2 == filterParams.DmgMax);
            }

            if (filterParams.DmgType != 100)
            {
                filters.Add(x => x.DmgType1 == filterParams.DmgType ||  x.DmgType2 == filterParams.DmgType);
            }

            if (filterParams.Armor != 0)
            {
                filters.Add(x => x.Armor == filterParams.Armor);
            }

            if (filterParams.Resistance != 0)
            {
                filters.Add(x =>
                            x.HolyRes == filterParams.Resistance ||
                            x.FireRes == filterParams.Resistance ||
                            x.NatureRes == filterParams.Resistance ||
                            x.FrostRes == filterParams.Resistance ||
                            x.ShadowRes == filterParams.Resistance ||
                            x.ArcaneRes == filterParams.Resistance);
            }

            if (filterParams.HolyRes != 0)
            {
                filters.Add(x => x.HolyRes == filterParams.HolyRes);
            }

            if (filterParams.FireRes != 0)
            {
                filters.Add(x => x.FireRes == filterParams.FireRes);
            }

            if (filterParams.NatureRes != 0)
            {
                filters.Add(x => x.NatureRes == filterParams.NatureRes);
            }

            if (filterParams.FrostRes != 0)
            {
                filters.Add(x => x.FrostRes == filterParams.FrostRes);
            }

            if (filterParams.ShadowRes != 0)
            {
                filters.Add(x => x.ShadowRes == filterParams.ShadowRes);
            }

            if (filterParams.ArcaneRes != 0)
            {
                filters.Add(x => x.ArcaneRes == filterParams.ArcaneRes);
            }

            if (filterParams.Speed != 0)
            {
                filters.Add(x => x.Delay == filterParams.Speed);
            }

            if (filterParams.AmmoType != 0)
            {
                filters.Add(x => x.AmmoType == filterParams.AmmoType);
            }

            if (filterParams.SpellTrigger != 100)
            {
                filters.Add(x =>
                            x.Spelltrigger1 == filterParams.SpellTrigger ||
                            x.Spelltrigger2 == filterParams.SpellTrigger ||
                            x.Spelltrigger3 == filterParams.SpellTrigger ||
                            x.Spelltrigger4 == filterParams.SpellTrigger);
            }

            if (filterParams.Bonding != 0)
            {
                filters.Add(x => x.Bonding == filterParams.Bonding);
            }

            if (filterParams.StartQuest != 0)
            {
                filters.Add(x => x.Startquest == filterParams.StartQuest);
            }

            if (filterParams.LockId != 0)
            {
                filters.Add(x => x.Lockid == filterParams.LockId);
            }

            if (filterParams.Material != 0)
            {
                filters.Add(x => x.Material == filterParams.Material);
            }

            if (filterParams.Sheath != 0)
            {
                filters.Add(x => x.Sheath == filterParams.Sheath);
            }

            if (filterParams.Block != 0)
            {
                filters.Add(x => x.Block == filterParams.Block);
            }

            if (filterParams.ItemSet != 0)
            {
                filters.Add(x => x.Itemset == filterParams.ItemSet);
            }

            if (filterParams.Durability != 0)
            {
                filters.Add(x => x.MaxDurability == filterParams.Durability);
            }

            if (filterParams.Area != 100)
            {
                filters.Add(x => x.Area == filterParams.Area);
            }

            if (filterParams.Map != 100)
            {
                filters.Add(x => x.Map == filterParams.Map);
            }

            if (filterParams.BagFamily != 0)
            {
                filters.Add(x => x.BagFamily == filterParams.BagFamily);
            }

            if (filterParams.DisenchantId != 0)
            {
                filters.Add(x => x.DisenchantId == filterParams.DisenchantId);
            }

            if (filterParams.FoodType != 0)
            {
                filters.Add(x => x.FoodType == filterParams.FoodType);
            }

            if (filterParams.MoneyLoot != 0)
            {
                filters.Add(x => filterParams.MoneyLoot >= x.MinMoneyLoot && filterParams.MoneyLoot <= x.MaxMoneyLoot);
            }

            if (filterParams.Duration != 0)
            {
                filters.Add(x => x.Duration == filterParams.Duration);
            }

            if (filterParams.Entries.Count() != 0)
            {
                filters.Add(x => filterParams.Entries.Contains(x.Entry));
            }

            return(filters);
        }
コード例 #5
0
        public async Task <CItemTemplate> GetItemByFiltersAsync(ItemFilterParams filterParams)
        {
            var itemTemplates = await FindAllByConditionsAsync(filterParams.AsFilters(), filterParams.FilterType, filterParams.ToCacheString());

            return(itemTemplates.DefaultIfEmpty(new CItemTemplate()).FirstOrDefault());
        }