//BEGIN - readBy
        public Order_DetailsSingle GetOrder_DetailsData(int OrderID)
        {
            try     // handle exogenous exceptions
            {
                try // log all exceptions
                {
                    Order_DetailsSingle order_details = new Order_DetailsSingle();
                    using (SqlConnection con = new SqlConnection(connectionString))
                    {
                        string sqlQuery = "SELECT * FROM [Order Details] WHERE OrderID= " + OrderID.ToString();

                        using (SqlCommand cmd = new SqlCommand(sqlQuery, con))
                        {
                            con.Open();
                            SqlDataReader rdr = cmd.ExecuteReader();
                            while (rdr.Read())
                            {
                                //order_details.OrderID = (int)rdr["OrderID"];
                                order_details.OrderID = rdr["OrderID"] == DBNull.Value ? default(int) : (int)rdr["OrderID"];

                                //order_details.ProductID = (int)rdr["ProductID"];
                                order_details.ProductID = rdr["ProductID"] == DBNull.Value ? default(int) : (int)rdr["ProductID"];

                                //order_details.UnitPrice = (decimal)rdr["UnitPrice"];
                                order_details.UnitPrice = rdr["UnitPrice"] == DBNull.Value ? default(decimal) : (decimal)rdr["UnitPrice"];

                                //order_details.Quantity = (short)rdr["Quantity"];
                                order_details.Quantity = rdr["Quantity"] == DBNull.Value ? default(short) : (short)rdr["Quantity"];

                                //order_details.Discount = (float)rdr["Discount"];
                                order_details.Discount = rdr["Discount"] == DBNull.Value ? default(float) : (float)rdr["Discount"];

                                //EXAMPLES:
                                //employee.EmployeeId = Convert.ToInt32(rdr["EmployeeID"]);
                                //employee.Name = rdr["Name"].ToString();
                                //employee.Gender = rdr["Gender"].ToString();
                                //employee.Salary = (decimal)rdr["Salary"];
                                //employee.City = rdr["City"].ToString();
                                //employee.IsPermanent = (bool)rdr["IsPermanent"];
                                //employee.DateOfBirth = Convert.ToDateTime(rdr["DateOfBirth"]);
                            }
                        }
                    }
                    return(order_details);
                }
                catch (Exception ex)
                {
                    BusinessLayer.ExceptionLogging exlog = new BusinessLayer.ExceptionLogging();
                    exlog.SendExcepToDB(ex);
                    //errResult = "A Technical Error occurred, Please visit after some time.";
                    throw;
                }
            }
            catch (Exception fx)
            {
                errResult = fx.Message.ToString();
                throw;
            }
        }
        //END - create

        //BEGIN - update
        public void UpdateOrder_Details(Order_DetailsSingle order_details)
        {
            try     // handle exogenous exceptions
            {
                try // log all exceptions
                {
                    using (SqlConnection con = new SqlConnection(connectionString))
                    {
                        using (SqlCommand cmd = new SqlCommand("spUpdateOrder_Details", con)
                        {
                            CommandType = CommandType.StoredProcedure
                        })
                        {
                            cmd.Parameters.AddWithValue("@OrderID", order_details.OrderID);
                            cmd.Parameters.AddWithValue("@ProductID", order_details.ProductID);
                            cmd.Parameters.AddWithValue("@UnitPrice", order_details.UnitPrice);
                            cmd.Parameters.AddWithValue("@Quantity", order_details.Quantity);
                            cmd.Parameters.AddWithValue("@Discount", order_details.Discount);
                            con.Open();
                            cmd.ExecuteNonQuery();
                        }
                        con.Close();
                    }
                }
                catch (Exception ex)
                {
                    BusinessLayer.ExceptionLogging exlog = new BusinessLayer.ExceptionLogging();
                    exlog.SendExcepToDB(ex);
                    //errResult = "A Technical Error occurred, Please visit after some time.";
                    throw;
                }
            }
            catch (Exception fx)
            {
                errResult = fx.Message.ToString();
                throw;
            }
        }
Exemple #3
0
        public ActionResult Create_Post()
        {
            try     // handle exogenous exceptions
            {
                try // log all exceptions
                {
                    OrdersBusinessModelLayers ordersLUBusinessModelLayers = new OrdersBusinessModelLayers();
                    ViewBag.Orderss = new SelectList(ordersLUBusinessModelLayers.OrdersSelect, "OrderID", "CustomerID");
                    ProductsBusinessModelLayers productsLUBusinessModelLayers = new ProductsBusinessModelLayers();
                    ViewBag.Productss = new SelectList(productsLUBusinessModelLayers.ProductsSelect, "ProductID", "ProductName");

                    Order_DetailsBusinessModelLayers       order_detailsBusinessModelLayers = new Order_DetailsBusinessModelLayers();
                    BusinessModelLayer.Order_DetailsSingle order_details = new BusinessModelLayer.Order_DetailsSingle();
                    TryUpdateModel(order_details);
                    if (ModelState.IsValid)
                    {
                        //mm
                        order_detailsBusinessModelLayers.AddOrder_Details(order_details);
                        return(RedirectToAction("List"));
                    }
                    else
                    {
                        return(View());
                    }
                }
                catch (Exception ex)
                {
                    BusinessLayer.ExceptionLogging exlog = new BusinessLayer.ExceptionLogging();
                    exlog.SendExcepToDB(ex);
                    throw;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        //END - delete


        //BEGIN - read
        public List <Order_DetailsSingle> GetAllOrder_Detailss()
        {
            try     // handle exogenous exceptions
            {
                try // log all exceptions
                {
                    List <Order_DetailsSingle> order_detailss = new List <Order_DetailsSingle>();

                    using (SqlConnection con = new SqlConnection(connectionString))
                    {
                        SqlCommand cmd = new SqlCommand("spGetAllOrder_Details", con)
                        {
                            CommandType = CommandType.StoredProcedure
                        };

                        con.Open();

                        SqlDataReader rdr = cmd.ExecuteReader();

                        while (rdr.Read())
                        {
                            Order_DetailsSingle order_details = new Order_DetailsSingle
                            {
                                // EXAMPLES:
                                //EmployeeId = Convert.ToInt32(rdr["EmployeeId"]),
                                //Name = rdr["Name"].ToString(),
                                //IsPermanent = (bool)rdr["IsPermanent"],
                                //Salary = Convert.ToDecimal(rdr["Salary"]),
                                //DateOfBirth = Convert.ToDateTime(rdr["DateOfBirth"])

                                //OrderID = (int)rdr["OrderID"]
                                OrderID = rdr["OrderID"] == DBNull.Value ? default(int) : (int)rdr["OrderID"]
                                          //,ProductID = (int)rdr["ProductID"]
                                ,
                                ProductID = rdr["ProductID"] == DBNull.Value ? default(int) : (int)rdr["ProductID"]
                                            //,UnitPrice = (decimal)rdr["UnitPrice"]
                                ,
                                UnitPrice = rdr["UnitPrice"] == DBNull.Value ? default(decimal) : (decimal)rdr["UnitPrice"]
                                            //,Quantity = (short)rdr["Quantity"]
                                ,
                                Quantity = rdr["Quantity"] == DBNull.Value ? default(short) : (short)rdr["Quantity"]
                                           //,Discount = (float)rdr["Discount"]
                                ,
                                Discount = rdr["Discount"] == DBNull.Value ? default(float) : (float)rdr["Discount"]
                            };
                            order_detailss.Add(order_details);
                        }
                        con.Close();
                        cmd.Dispose();
                    }
                    return(order_detailss);
                }
                catch (Exception ex)
                {
                    BusinessLayer.ExceptionLogging exlog = new BusinessLayer.ExceptionLogging();
                    exlog.SendExcepToDB(ex);
                    //errResult = "A Technical Error occurred, Please visit after some time.";
                    throw;
                }
            }
            catch (Exception fx)
            {
                errResult = fx.Message.ToString();
                throw;
            }
        }