public IEnumerable <CharacterItemListItem> GetItemsByCharacterID(int characterID) { List <CharacterItemListItem> itemList = new List <CharacterItemListItem>(); using (var ctx = new ApplicationDbContext()) { var query = ctx.CharacterItems.Where(e => e.CharacterID == characterID).ToList(); foreach (var item in query) { var listItem = new CharacterItemListItem { CharacterItemID = item.CharacterItemsID, ItemID = item.ItemID, ItemName = item.Equipment.ItemName, UsableBy = item.Equipment.UsableBy, ItemType = item.Equipment.ItemType, IsEquipped = item.IsEquipped, Damage = item.Equipment.Damage, DamageType = item.Equipment.DamageType, WeaponType = item.Equipment.WeaponType, Size = item.Equipment.Size, ArmorClassBonus = item.Equipment.ArmorClassBonus, ItemNotes = item.Equipment.ItemNotes }; itemList.Add(listItem); } } return(itemList); }
public ActionResult Update(CharacterItemListItem model, int characterID) { var service = CharacterSheetServices(); service.UpdateCharacterItem(model, characterID); TempData["SaveResult"] = "Items Updated."; return(RedirectToAction("Details", new { id = characterID })); }
public bool UpdateCharacterItem(CharacterItemListItem model, int characterID) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.CharacterItems.Single(e => e.CharacterItemsID == model.CharacterItemID); entity.CharacterItemsID = model.CharacterItemID; entity.CharacterID = characterID; entity.ItemID = model.ItemID; entity.IsEquipped = model.IsEquipped; return(ctx.SaveChanges() == 1); } }