コード例 #1
0
        public async Task <IActionResult> AddArmor(AdminAddArmorViewModel model)
        {
            if (ModelState.IsValid)
            {
                var armor = new CraftableArmor
                {
                    Id               = Guid.NewGuid().ToString(),
                    Name             = model.Name,
                    Type             = model.Type,
                    MaterialRequired = model.MaterialRequired,
                    MaterialCount    = model.MaterialCount,
                    Defence          = model.Defence,
                    CraftCost        = model.Cost
                };

                await _db.CraftableArmors.AddAsync(armor);

                await _db.SaveChangesAsync();

                return(this.RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Invalid armor entry.");
            return(this.View(model));
        }
コード例 #2
0
        public async Task SeedCraftableArmors(ApplicationDbContext context)
        {
            var armor1 = new CraftableArmor()
            {
                Id               = "Id1",
                Name             = "Test armor 1",
                Type             = ArmorTypes.Chest,
                MaterialRequired = Materials.Copper,
                MaterialCount    = 5,
                Defence          = 10,
                CraftCost        = 50,
            };

            var armor2 = new CraftableArmor()
            {
                Id               = "Id2",
                Name             = "Test armor 2",
                Type             = ArmorTypes.Boots,
                MaterialRequired = Materials.Mithril,
                MaterialCount    = 10,
                Defence          = 20,
                CraftCost        = 100,
            };

            await context.CraftableArmors.AddAsync(armor1);

            await context.CraftableArmors.AddAsync(armor2);

            await context.SaveChangesAsync();
        }