コード例 #1
0
 public bool AdventurerCreate(AdventurerCreate model)
 {
     using (var ctx = new ApplicationDbContext())
     {
         var newAdventurer = new Adventurer()
         {
             Name     = model.Name,
             Class    = model.Class,
             Level    = 1,
             PlanetId = 1,
             Weapon   = model.WeaponChoice(),
             Xp       = 0,
             OwnerId  = _userId
         };
         ctx.Adventurers.Add(newAdventurer);
         return(ctx.SaveChanges() == 1);
     }
 }
コード例 #2
0
        public ActionResult Create(AdventurerCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateAdventurerService();

            if (service.AdventurerCreate(model))
            {
                TempData["SaveResult"] = "Your Adventurer was Succesfully Created";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Your Adventurer could not be " +
                                     "Created");

            return(View(model));
        }
コード例 #3
0
        public ActionResult Create(AdventurerCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateAdventurerService();

            if (service.CreateAdventurer(model))
            {
                TempData["SaveResult"] = "Your Adventurer was created.";
                return(RedirectToAction($"Index"));
            }
            ;

            ModelState.AddModelError("", "Note could not be created.");

            return(View(model));
        }
コード例 #4
0
        public bool CreateAdventurer(AdventurerCreate model)
        {
            var entity =
                new Adventurer()
            {
                //AdventurerId = _adventurerId,
                Name     = model.Name,
                Class    = (Species)model.Class,
                Level    = 1,
                PlanetId = 1,
                Weapon   = model.WeaponChoice(),
                OwnerId  = _userId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Adventurers.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }