예제 #1
0
        public bool UpdateLoot(LootEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Loot
                    .Single(e => e.LootId == model.LootId && e.OwnerId == _userId);

                entity.LootId    = model.LootId;
                entity.LootName  = model.LootName;
                entity.LootDesc  = model.LootDesc;
                entity.MonsterId = model.MonsterId;

                return(ctx.SaveChanges() == 1);
            }
        }
예제 #2
0
        public ActionResult Edit(int id)
        {
            var monsters = _db.Monsters.ToList().Where(t => t.OwnerId == Guid.Parse(User.Identity.GetUserId())); //Getting logged in user's list

            ViewBag.MonsterId = new SelectList(monsters, "MonsterId", "MonsterName");

            var service = CreateLootService();
            var detail  = service.GetLootById(id);
            var model   =
                new LootEdit
            {
                LootId    = detail.LootId,
                LootName  = detail.LootName,
                LootDesc  = detail.LootDesc,
                MonsterId = detail.MonsterId
            };

            return(View(model));
        }
예제 #3
0
        public ActionResult Edit(int id, LootEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.LootId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateLootService();

            if (service.UpdateLoot(model))
            {
                TempData["SaveResult"] = ($"{model.LootName} was updated.");
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", ($"{model.LootName} could not be updated."));
            return(View(model));
        }