I am inserting into my database. My code is working fine, but am stuck trying to throw message if the insertion is successful or not. Please check my code below. For example, if the insertion is successful, a message like "Insertion successful" should be shown.
public class HomeController : Controller
{
public ActionResult Index()
{
SalesLayanEntities3 db = new SalesLayanEntities3();
List<Product_Category> list = db.Product_Category.ToList();
ViewBag.ProductName = new SelectList(list,"cat_id","cat_name");
return View();
}
public ActionResult SaveRecord(ProductForm model)
{
try
{
SalesLayanEntities3 db = new SalesLayanEntities3();
Product prod = new Product();
prod.prod_name = model.Prod_name;
prod.prod_model = model.Prod_model;
prod.prod_quantity = model.Prod_quantity;
prod.prod_description = model.Prod_description;
prod.prod_unit_cost_price = model.Prod_unit_cost_price;
prod.cat_id = model.Cat_id;
db.Products.Add(prod);
db.SaveChanges();
int latestProdId = prod.prod_id;
}
catch (Exception ex)
{
throw ex;
}
return RedirectToAction("Index");
}
}