public ActionResult Create([Bind(Include = "Id," + "Name," + "Description," + "Uri," + "Tokens," + "Category," + "")] ShopInventoryModel data) { if (!ModelState.IsValid) { // Send back for edit, with Error Message return(View(data)); } if (data == null) { // Send to Error Page return(RedirectToAction("Error", new { route = "Home", action = "Error" })); } if (string.IsNullOrEmpty(data.Id)) { // Sind back for Edit return(View(data)); } ShopInventoryBackend.Create(data); return(RedirectToAction("Index")); }
public List <ShopInventoryModel> GetAllItem(int shopID) { List <ShopInventoryModel> inventoryItems = new List <ShopInventoryModel>(); using var command = _connection.CreateCommand(); command.CommandText = $"SELECT * FROM shop_inventory JOIN ingredients ON ingredients.ingredient_id = shop_inventory.ingredient_id WHERE shop_id = {shopID}"; using var reader = command.ExecuteReader(); while (reader.Read()) { ShopInventoryModel inventoryItem = new ShopInventoryModel { ItemID = (int)reader["item_id"], ShopID = (int)reader["shop_id"], ItemName = (string)reader["item_name"], Price = (double)reader["price"], Currency = (string)reader["currency"], ItemCategory = (string)reader["ingredient_name"], IngredientID = (int)reader["ingredient_id"] }; inventoryItems.Add(inventoryItem); } return(inventoryItems); }
public IActionResult Create(ShopInventoryModel inventoryItem) { var shopID = Convert.ToInt32(HttpContext.User.FindFirst("Id").Value); inventoryItem.ShopID = shopID; _inventoryService.AddItem(inventoryItem); return(RedirectToAction("Inventory", "ShopInventory")); }
/// <summary> /// Update all attributes to be what is passed in /// </summary> /// <param name="data"></param> /// <returns>Null or updated data</returns> public ShopInventoryModel Update(ShopInventoryModel data) { if (data == null) { return(null); } var myReturn = DataSource.Update(data); return(myReturn); }
/// <summary> /// Update all attributes to be what is passed in /// </summary> /// <param name="data"></param> /// <returns>Null or updated data</returns> public ShopInventoryModel Update(ShopInventoryModel data) { if (data == null) { return(null); } var myReturn = ShopInventoryList.Find(n => n.Id == data.Id); if (myReturn == null) { return(null); } myReturn.Update(data); return(myReturn); }
public void UpdateItem(int inventoryItemID, ShopInventoryModel inventoryItem) { int ingredientID = GetIngredientID(inventoryItem.ItemCategory); using var command = _connection.CreateCommand(); var ingredientIDParam = command.CreateParameter(); ingredientIDParam.ParameterName = "ingredient_id"; ingredientIDParam.Value = ingredientID; var itemNameParam = command.CreateParameter(); itemNameParam.ParameterName = "item_name"; itemNameParam.Value = inventoryItem.ItemName; var itemIDParam = command.CreateParameter(); itemIDParam.ParameterName = "item_id"; itemIDParam.Value = inventoryItemID; var priceParam = command.CreateParameter(); priceParam.ParameterName = "price"; priceParam.Value = inventoryItem.Price; var currencyParam = command.CreateParameter(); currencyParam.ParameterName = "currency"; currencyParam.Value = inventoryItem.Currency; command.CommandText = @"UPDATE shop_inventory SET ingredient_id = @ingredient_id , item_name = @item_name, price = @price, currency = @currency WHERE item_id = @item_id"; command.Parameters.Add(ingredientIDParam); command.Parameters.Add(itemNameParam); command.Parameters.Add(priceParam); command.Parameters.Add(currencyParam); command.Parameters.Add(itemIDParam); command.ExecuteNonQuery(); }
public void AddItem(ShopInventoryModel inventoryItem) { int ingredientID = GetIngredientID(inventoryItem.ItemCategory); using var command = _connection.CreateCommand(); var ingredientIDParam = command.CreateParameter(); ingredientIDParam.ParameterName = "ingredient_id"; ingredientIDParam.Value = ingredientID; var itemNameParam = command.CreateParameter(); itemNameParam.ParameterName = "item_name"; itemNameParam.Value = inventoryItem.ItemName; var shopIDParam = command.CreateParameter(); shopIDParam.ParameterName = "shop_id"; shopIDParam.Value = inventoryItem.ShopID; var priceParam = command.CreateParameter(); priceParam.ParameterName = "price"; priceParam.Value = inventoryItem.Price; var currencyParam = command.CreateParameter(); currencyParam.ParameterName = "currency"; currencyParam.Value = inventoryItem.Currency; command.CommandText = @"INSERT INTO shop_inventory (ingredient_id, item_name, shop_id, price, currency) VALUES (@ingredient_id, @item_name, @shop_id, @price, @currency)"; command.Parameters.Add(ingredientIDParam); command.Parameters.Add(itemNameParam); command.Parameters.Add(shopIDParam); command.Parameters.Add(priceParam); command.Parameters.Add(currencyParam); command.ExecuteNonQuery(); }
public ShopInventoryModel GetItemByID(int inventoryItemID) { using var command = _connection.CreateCommand(); command.CommandText = $"SELECT * FROM shop_inventory JOIN ingredients ON ingredients.ingredient_id = shop_inventory.ingredient_id WHERE item_id = {inventoryItemID}"; using var reader = command.ExecuteReader(); reader.Read(); ShopInventoryModel inventoryItem = new ShopInventoryModel { ItemID = (int)reader["item_id"], ShopID = (int)reader["shop_id"], ItemName = (string)reader["item_name"], Price = (double)reader["price"], Currency = (string)reader["currency"], ItemCategory = (string)reader["ingredient_name"], IngredientID = (int)reader["ingredient_id"] }; return(inventoryItem); }
public IActionResult Edit(int id, ShopInventoryModel inventoryItem) { _inventoryService.UpdateItem(id, inventoryItem); return(RedirectToAction("Inventory", "ShopInventory")); }
/// <summary> /// This opens up the make a new ShopInventory screen /// </summary> /// <returns></returns> // GET: ShopInventory/Create public ActionResult Create() { var myData = new ShopInventoryModel(); return(View(myData)); }
/// <summary> /// Makes a new ShopInventory /// </summary> /// <param name="data"></param> /// <returns>ShopInventory Passed In</returns> public ShopInventoryModel Create(ShopInventoryModel data) { DataSource.Create(data); return(data); }
/// <summary> /// Makes a new ShopInventory /// </summary> /// <param name="data"></param> /// <returns>ShopInventory Passed In</returns> public ShopInventoryModel Create(ShopInventoryModel data) { ShopInventoryList.Add(data); return(data); }