예제 #1
0
        public ActionResult Select(int id, int?spellbookId)
        {
            Spell spell = _spellRepo.Get(id);

            // Maybe eventually set up Mapper DI.
            //var mapper = new Mapper(config);
            //SpellViewModel viewModel = mapper.Map<SpellViewModel>(spell);

            var viewModel = new SpellViewModel();

            viewModel.Id          = spell.Id;
            viewModel.Name        = spell.Name;
            viewModel.Level       = spell.Level;
            viewModel.School      = spell.School;
            viewModel.CastingTime = spell.CastingTime;
            viewModel.Range       = spell.Range;
            viewModel.Verbal      = spell.Verbal;
            viewModel.Somatic     = spell.Somatic;
            viewModel.Materials   = spell.Materials;
            viewModel.Ritual      = spell.Ritual;
            viewModel.Description = spell.Description;

            if (spellbookId != null)
            {
                viewModel.SpellbookId = spellbookId;
            }

            return(View(viewModel));
        }
예제 #2
0
 public IActionResult Get(int id)
 {
     try
     {
         if (id > 0)
         {
             var spell = _spellRepository.Get(id);
             if (spell != null)
             {
                 return(Ok(spell));
             }
             else
             {
                 return(NotFound());
             }
         }
         else
         {
             return(BadRequest());
         }
     }
     catch (Exception ex)
     {
         _logger.LogError($"There was an error retrieving element {id}. Ex: {ex}");
         return(BadRequest());
     }
 }
예제 #3
0
 public bool AddSpellToSpellbook(int spellbookId, int spellId)
 {
     try
     {
         var spellbook = Get(spellbookId);
         var spell     = _spellRepo.Get(spellId);
         spellbook.Spells.Add(spell);
         _context.UpdateEntity(spellbook);
         _context.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
예제 #4
0
        public SpellEditModel GetForEdit(int?id)
        {
            if (id == null)
            {
                return(new SpellEditModel());
            }
            var model = _spellRepository.Get(id.Value).ProjectTo <SpellEditModel>(MapperConfig).FirstOrDefault();

            return(model ?? new SpellEditModel());
        }