Lädt...

🔧 Controller not bee able to pass data to Quantity table


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

` public ActionResult SaveItem(ItemViewModel itemModel)
{
bool result = false;

try
{
    // Step 1: Save Category
    tblCategory objCategory = objRestaurantDBEntities.tblCategories
        .SingleOrDefault(x => x.CategoryId == itemModel.CategoryId) ?? new tblCategory();

    if (itemModel.CategoryId <= 0)
    {
        objCategory.CategoryName = itemModel.CategoryName;
        objRestaurantDBEntities.tblCategories.Add(objCategory);
        objRestaurantDBEntities.SaveChanges(); // Save to generate CategoryId
    }

    // Ensure objCategory has an ID
    if (objCategory.CategoryId <= 0)
    {
        return Json(new { success = false, message = "Failed to save category." });
    }

    // Step 2: Save Item
    tblItem objItem = objRestaurantDBEntities.tblItems
        .SingleOrDefault(x => x.ItemId == itemModel.ItemId) ?? new tblItem();

    objItem.PCode = itemModel.PCode;
    objItem.ItemName = itemModel.ItemName;
    objItem.CostPrice = itemModel.CostPrice;
    objItem.ItemPrice = itemModel.ItemPrice;
    objItem.Vat = itemModel.Vat;
    objItem.ExpiringDate = itemModel.ExpiringDate;
    objItem.Active = itemModel.Active;
    objItem.CategoryId = objCategory.CategoryId; // Assign correct category ID

    if (itemModel.ItemId <= 0) // New Item
    {
        objRestaurantDBEntities.tblItems.Add(objItem);
    }

    objRestaurantDBEntities.SaveChanges(); // Save Item


    if (objItem.ItemId <= 0)
    {
        return Json(new { success = false, message = "Failed to save item. ItemId not generated." });
    }

    // Step 3: Save Quantity (Ensure itemModel.tblQuantities is not null)
    if (itemModel.tblQuantities != null)
    {
        tblQuantity objQnty = objRestaurantDBEntities.tblQuantities
            .SingleOrDefault(x => x.QuantityId == itemModel.QuantityId) ?? new tblQuantity();

        objQnty.InitialQty = itemModel.tblQuantities.InitialQty;
        objQnty.Quantity = itemModel.tblQuantities.Quantity;
        objQnty.ItemId = objItem.ItemId;

        if (itemModel.tblQuantities.QuantityId <= 0) // New Quantity Entry
        {
            objRestaurantDBEntities.tblQuantities.Add(objQnty);
        }

        objRestaurantDBEntities.SaveChanges(); // Save Quantity Data
    }

    result = true;
}
catch (Exception ex)
{
    // Log the error properly (Assuming you have a logging mechanism)
    Console.WriteLine(ex.ToString());

    return Json(new { success = false, message = "An error occurred: {ex.Message}" });
}

return Json(new { success = result, message = "Item saved successfully." });

}
`

...

🔧 Controller not bee able to pass data to Quantity table


📈 81.67 Punkte
🔧 Programmierung

📰 Neat King Bee II &amp; Worker Bee II im Test: Mikrofone mit gutem Klang zum fairen Preis


📈 38.05 Punkte
📰 IT Nachrichten

📰 Report: Quality, not quantity, is the hallmark of the latest waves of phishing attacks


📈 25.61 Punkte
📰 IT Security Nachrichten

🔧 Building and Comparing Table Data Made Easy with @libs-jd/table-data-kit


📈 24.94 Punkte
🔧 Programmierung

🔧 Building and Comparing Table Data Made Easy with @libs-jd/table-data-kit


📈 24.94 Punkte
🔧 Programmierung

🔧 🤔 Why Not Always Put "Relationships" in the Table? The Secret of the Join Table!


📈 24.2 Punkte
🔧 Programmierung

🔧 SQLSTATE[42S02]: Base table or view not found: 1146 Table 'planner_v2_be.role_user' doesn't exist


📈 24.2 Punkte
🔧 Programmierung

📰 Quantity vs Quality in Coffee Data


📈 23.72 Punkte
🔧 AI Nachrichten

🔧 Let's create Data Table with React, TanStack Table and Tailwind CSS. Part 1: Intro and HTML layout


📈 22.31 Punkte
🔧 Programmierung

🔧 Deleted a table in production and lost four more table data with ON DELETE CASCADE


📈 22.31 Punkte
🔧 Programmierung

🔧 A data-first approach to evaluate dev team effectiveness ft. Chris Bee, CTO @Superhuman


📈 21.66 Punkte
🔧 Programmierung

🕵️ HackerOne: Being able to disclose IBB bounty table of any public program


📈 21.35 Punkte
🕵️ Sicherheitslücken

📰 “ML-Everything”? Balancing Quantity and Quality in Machine Learning Methods for Science


📈 21.09 Punkte
🔧 AI Nachrichten

📰 Lessons From the Cold War: How Quality Trumps Quantity in Cybersecurity


📈 21.09 Punkte
📰 IT Security Nachrichten

🕵️ CVE-2024-8887 | CIRCUTOR Q-SMT 1.0.4 improper validation of specified quantity in input


📈 21.09 Punkte
🕵️ Sicherheitslücken

🕵️ CVE-2006-4214 | Zen Cart add_cart quantity sql injection (XFDB-28393 / Nessus ID 22233)


📈 21.09 Punkte
🕵️ Sicherheitslücken

⚠️ #0daytoday #CSE Bookstore 1.0 - (quantity) Persistent Cross-site Scripting Vulnerability [#0day #Exploit]


📈 21.09 Punkte
⚠️ PoC

⚠️ [webapps] CSE Bookstore 1.0 - 'quantity' Persistent Cross-site Scripting


📈 21.09 Punkte
⚠️ PoC

🔧 How to create a Dart lint rule – plural quantity check example


📈 21.09 Punkte
🔧 Programmierung

🕵️ OpenCA up to 1.5.6.4 system/library/cart.php Cart::getProducts quantity XML External Entity


📈 21.09 Punkte
🕵️ Sicherheitslücken

📰 Quality Over Quantity: the Counter-Intuitive GenAI Key


📈 21.09 Punkte
📰 IT Security Nachrichten

🔧 A Social Media App that Encourages Quality Over Quantity


📈 21.09 Punkte
🔧 Programmierung

🕵️ OpenCA bis 1.5.6.4 system/library/cart.php Cart::getProducts quantity erweiterte Rechte


📈 21.09 Punkte
🕵️ Sicherheitslücken