Example #1
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);
        }
Example #2
0
        public SpellViewModel GetSpellById(int id)
        {
            var entity = _repository.GetSingle <Spell>(a => a.Id == id, false, a => a.SpellsClass, a => a.SpellMaterials);

            return(Mapper.Map <Spell, SpellViewModel>(entity));
        }
        public EquipmentViewModel GetEquipmentById(int id)
        {
            var entity = _dndRepository.GetSingle <Equipment>(a => a.IdEquipment == id, false, a => a.TypeEquipment);

            if (entity == null)
            {
                throw new Exception(string.Format(Resources.ValidationMessages.EntityM_Error_NotFound, nameof(Equipment)));
            }
            return(Mapper.Map <Equipment, EquipmentViewModel>(entity));
        }
Example #4
0
        public CharacterViewModel GetCharacterById(int id)
        {
            var entity    = _dndRepository.GetSingle <Character>(a => a.Id == id, false, a => a.Aligment, a => a.CharacterSpells, a => a.CharacterEquipments);
            var viewModel = Mapper.Map <Character, CharacterViewModel>(entity);

            viewModel.SpellsKnown = GetCharacterSpell(entity);
            return(viewModel);
        }