public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Description,InStock,Picture1,Picture2,Picture3")] JewelryItem item) { if (id != item.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(item); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ItemExists(item.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(item)); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } JewelryItem = await _context.JewelryItem.FirstOrDefaultAsync(m => m.ID == id); if (JewelryItem == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> Create([Bind("ID,Name,Description,InStock,Picture1,Picture2,Picture3")] JewelryItem item) { try { if (ModelState.IsValid) { _context.Add(item); await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(Index))); } catch { return(View(item)); } }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } JewelryItem = await _context.JewelryItem.FindAsync(id); if (JewelryItem != null) { _context.JewelryItem.Remove(JewelryItem); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public JewelryItem GetJewelryItem(string id) { try { if (string.IsNullOrEmpty(id)) { return(null); } string ID = "'" + id + "'"; SimpleSQL.SimpleDataTable dt = dbManager.QueryGeneric( "SELECT " + "*" + "FROM " + "JewelryItem " + "WHERE " + "ID LIKE " + ID ); PowerUps ups = new PowerUps(dt.rows[0]["PowerUps"].ToString()); SuitEffectInfo setEffectInfo; if (dt.rows[0]["Suit"] != null) { setEffectInfo = GetSuitEffectInfo(dt.rows[0]["Suit"].ToString()); } else { setEffectInfo = null; } JewelryItem jewelry = new JewelryItem(dt.rows[0]["ID"].ToString(), dt.rows[0]["Name"].ToString(), dt.rows[0]["Description"].ToString(), dt.rows[0]["Icon"].ToString(), (int)dt.rows[0]["MaxCount"], float.Parse(dt.rows[0]["Weight"].ToString()), (int)dt.rows[0]["BuyPrice"], (int)dt.rows[0]["SellPrice"], (int)dt.rows[0]["SellAble"] == 1, (int)dt.rows[0]["Usable"] == 1, (MyEnums.JewelryType)dt.rows[0]["JewelryType"], ups, setEffectInfo); if (dt.rows[0]["Materials"] != null) { jewelry.MaterialsListInput = dt.rows[0]["Materials"].ToString(); } jewelry.SetMaterials(this); return(jewelry); } catch (System.Exception ex) { Debug.Log("\"" + id + "\"" + ex.Message); return(null); } }
public override async void Execute(object parameter) { using (var unitOfWork = _unitOfWorkFactory.CreateUnitOfWork()) { JewelryItem newItem = new JewelryItem() { JewelryName = _jewelryItemViewmodel.Name, Image = _jewelryItemViewmodel.Image, Price = _jewelryItemViewmodel.Price, Description = _jewelryItemViewmodel.Description, JewelryOrders = new List <JewelryOrder>() }; unitOfWork.JewelryItemRepository.Create(newItem); await unitOfWork.SaveAsync(); } _jewelryItemViewmodel.Name = string.Empty; _jewelryItemViewmodel.Image = @"E:\2 курс\2 семестр\OOP 2\курсач\CourseProject\OOPCourseProject\CourseProj\Images\placeholder.png"; _jewelryItemViewmodel.Price = 0; _jewelryItemViewmodel.Description = string.Empty; }
public async Task UpdateItem(int id, [Bind("ID,Name,Price")] JewelryItem item) { _context.Update(item); await _context.SaveChangesAsync(); }
public async Task <JewelryItem> DeleteItem(int id) { JewelryItem item = await _context.JewelryItem.FirstOrDefaultAsync(m => m.ID == id); return(item); }
public async Task CreateItem(JewelryItem item) { _context.Add(item); await _context.SaveChangesAsync(); }
public void LoseItem(ItemBase item, int lose_num) { if (item == null || lose_num <= 0) { return; } if (Current_Size <= 0) { throw new System.Exception("背包为空"); } ItemInfo tempitem = itemList.Find(i => i.Item == item); if (tempitem == null) { throw new System.Exception("该物品未在行囊中"); } bool isequip = false; switch (tempitem.Item.ItemType) { case ItemType.Weapon: WeaponItem weapon = tempitem.Item as WeaponItem; if (weapon == null) { break; } isequip = weapon.IsEqu; break; case ItemType.Armor: ArmorItem armor = tempitem.Item as ArmorItem; if (armor == null) { break; } isequip = armor.IsEqu; break; case ItemType.Jewelry: JewelryItem jewelry = tempitem.Item as JewelryItem; if (jewelry == null) { break; } isequip = jewelry.IsEqu; break; case ItemType.Mount: MountItem mount = tempitem.Item as MountItem; if (mount == null) { break; } isequip = mount.IsEqu; break; } if (isequip) { throw new System.Exception("该物品已装备"); } if (tempitem.Quantity <= 0) { throw new System.Exception("该物品为空"); } int finallyDiscard = tempitem.StackAble ? tempitem.Quantity - lose_num > 0 ? lose_num : tempitem.Quantity : 1; tempitem.Quantity -= finallyDiscard; Current_Weight -= tempitem.Item.Weight * finallyDiscard; if (tempitem.Quantity <= 0) { Current_Size -= 1; itemList.Remove(tempitem); } CheckSizeAndWeight(); }
public void OnDiscard(int discard_num, BagInfo bag) { if (discard_num <= 0) { return; } bool isequip = false; switch (Item.ItemType) { case ItemType.Weapon: WeaponItem weapon = Item as WeaponItem; if (weapon == null) { break; } isequip = weapon.IsEqu; break; case ItemType.Armor: ArmorItem armor = Item as ArmorItem; if (armor == null) { break; } isequip = armor.IsEqu; break; case ItemType.Jewelry: JewelryItem jewelry = Item as JewelryItem; if (jewelry == null) { break; } isequip = jewelry.IsEqu; break; } if (isequip) { throw new System.Exception("装备中的物品不能丢弃"); } if (Quantity <= 0) { throw new System.Exception("该物品为空"); } if (!bag.itemList.Exists(i => i.Item == Item)) { throw new System.Exception("该物品未在行囊里"); } int finallyDiscard = StackAble ? Quantity - discard_num > 0 ? discard_num : Quantity : 1; //Debug.Log("最终丢弃数为" + finallyDiscard); Quantity -= finallyDiscard; bag.Current_Weight -= Item.Weight * finallyDiscard; if (Quantity <= 0) { bag.Current_Size -= 1; bag.itemList.Remove(this); } bag.CheckSizeAndWeight(); }