/// <summary>
        /// Get the datacollection of a collecion
        /// </summary>
        /// <param name="idCollection"></param>
        /// <returns>List of DataCollectionViewModel</returns>
        public List <DataCollectionViewModel> GetDataCollectionByIdCollection(int idCollection)
        {
            var dataCollection = _dndRepository.GetAllWhere(new List <System.Linq.Expressions.Expression <Func <DataCollection, bool> > >()
            {
                a => a.IdCollection == idCollection
            }).ToList();

            if (dataCollection == null)
            {
                throw new Exception(string.Format(Resources.ValidationMessages.EntityM_Error_NotFound, nameof(DataCollection)));
            }
            return(Mapper.Map <List <DataCollection>, List <DataCollectionViewModel> >(dataCollection));
        }
示例#2
0
        public ShoppingListViewModel GetShoppingList(int idSpellbook)
        {
            var spells    = _repository.GetSingle <Spellbook>(a => a.Id == idSpellbook, false, a => a.SpellbookSpells);
            var materials = _repository.GetAllWhere <SpellMaterial>(new List <System.Linq.Expressions.Expression <Func <SpellMaterial, bool> > >()
            {
                a => spells.SpellbookSpells.ToList().Find(b => b.IdSpell == a.IdSpell) != null
            }, null, false, a => a.Material).ToList();

            var materialsSpellbook = new Dictionary <int, ShoppingMaterialViewModel>();

            foreach (var material in materials)
            {
                var id = material.IdMaterial;
                if (materialsSpellbook.ContainsKey(id))
                {
                    materialsSpellbook[id].Quantity     += material.Quantity;
                    materialsSpellbook[id].GoldCost     += material.Material.GoldCost;
                    materialsSpellbook[id].ElectrumCost += material.Material.ElectrumCost;
                    materialsSpellbook[id].SilverCost   += material.Material.SilverCost;
                    materialsSpellbook[id].CupperCost   += material.Material.CupperCost;
                }
                else
                {
                    materialsSpellbook.Add(id, new ShoppingMaterialViewModel()
                    {
                        Id           = id,
                        Description  = material.Material.Description,
                        Quantity     = material.Quantity,
                        GoldCost     = material.Material.GoldCost,
                        SilverCost   = material.Material.SilverCost,
                        ElectrumCost = material.Material.ElectrumCost,
                        CupperCost   = material.Material.CupperCost
                    });
                }
            }
            var shoppingList = new ShoppingListViewModel()
            {
                Materials     = materialsSpellbook.Values.ToList(),
                TotalGold     = materialsSpellbook.Sum(a => a.Value.GoldCost),
                TotalElectrum = materialsSpellbook.Sum(a => a.Value.ElectrumCost),
                TotalSilver   = materialsSpellbook.Sum(a => a.Value.SilverCost),
                TotalCupper   = materialsSpellbook.Sum(a => a.Value.CupperCost),
            };

            return(shoppingList);
        }
示例#3
0
        public List <CharacterSkillViewModel> GetSkillsByCharacter(int idCharacter)
        {
            var character = GetCharacterById(idCharacter);

            if (character == null)
            {
                throw new Exception(string.Format(Resources.ValidationMessages.EntityM_Error_NotFound, nameof(Character)));
            }

            var skills = _dndRepository.GetAllWhere(new List <System.Linq.Expressions.Expression <Func <CharacterSkill, bool> > >()
            {
                a => a.IdCharacter == idCharacter
            }).ToList();

            return(Mapper.Map <List <CharacterSkill>, List <CharacterSkillViewModel> >(skills));
        }