public bool InsertBookingIntoDatabase(MakeBookingDetails obj) { bool isInserted = false; try { ConnectionStr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; conn = new SqlConnection(ConnectionStr); conn.Open(); } catch (Exception e) { Debug.WriteLine("SQL Server connection failed:" + e.Message); isInserted = false; } try { cmd = new SqlCommand("INSERT INTO FoodBookingDB VALUES (@empId, @menuId, @noOfPlates, @bookingDate, @amount)", conn); cmd.Parameters.AddWithValue("empId", Convert.ToInt32(obj.EmployeeId)); cmd.Parameters.AddWithValue("menuId", Convert.ToInt32(obj.MenuId)); cmd.Parameters.AddWithValue("noOfPlates", Convert.ToInt32(obj.NumberOfPlates)); cmd.Parameters.AddWithValue("bookingDate", Convert.ToDateTime(obj.DateOfBooking)); cmd.Parameters.AddWithValue("amount", Convert.ToDecimal(obj.TotalAmount)); int count1 = cmd.ExecuteNonQuery(); if (count1 >= 0) { isInserted = true; } else { isInserted = false; } } catch (Exception err) { Debug.WriteLine("SQL operation failed:" + err.Message); isInserted = false; } conn.Close(); return isInserted; }
public string BookMealIntoDatabase(string EmpId, string MenuId, string NoOfPlates, string Cost) { FoodDAL agent = new FoodDAL(); MakeBookingDetails obj = new MakeBookingDetails(); obj.EmployeeId = Convert.ToInt32(EmpId); obj.MenuId = Convert.ToInt32(MenuId); obj.NumberOfPlates = Convert.ToInt32(NoOfPlates); obj.DateOfBooking = DateTime.Today.ToShortDateString(); obj.TotalAmount = Convert.ToDouble(Cost); bool res = agent.InsertBookingIntoDatabase(obj); if (res) { return ("DONE"); } else { return ("ERROR"); } }
public void MakeMealBooking(string menuId, string dishName, string pricePerPlate) { MakeBookingDetails obj = new MakeBookingDetails(); obj.EmployeeId = Convert.ToInt32(Session["UserID"]); obj.MenuId = Convert.ToInt32(menuId); obj.PricePerPlate = Convert.ToDouble(pricePerPlate); obj.DishName = dishName; TempData["model"] = obj; //return RedirectToAction("BookMeal"); }