예제 #1
0
        //END - delete


        //BEGIN - read
        public List <ShippersSingle> GetAllShipperss()
        {
            try     // handle exogenous exceptions
            {
                try // log all exceptions
                {
                    List <ShippersSingle> shipperss = new List <ShippersSingle>();

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

                        con.Open();

                        SqlDataReader rdr = cmd.ExecuteReader();

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

                                //ShipperID = (int)rdr["ShipperID"]
                                ShipperID = rdr["ShipperID"] == DBNull.Value ? default(int) : (int)rdr["ShipperID"]
                                            //,CompanyName = (string)rdr["CompanyName"]
                                ,
                                CompanyName = rdr["CompanyName"] == DBNull.Value ? "" : (string)rdr["CompanyName"]
                                              //,Phone = (string)rdr["Phone"]
                                ,
                                Phone = rdr["Phone"] == DBNull.Value ? "" : (string)rdr["Phone"]
                            };
                            shipperss.Add(shippers);
                        }
                        con.Close();
                        cmd.Dispose();
                    }
                    return(shipperss);
                }
                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;
            }
        }
예제 #2
0
 public ActionResult Create_Post()
 {
     try     // handle exogenous exceptions
     {
         try // log all exceptions
         {
             ShippersBusinessModelLayers       shippersBusinessModelLayers = new ShippersBusinessModelLayers();
             BusinessModelLayer.ShippersSingle shippers = new BusinessModelLayer.ShippersSingle();
             TryUpdateModel(shippers);
             if (ModelState.IsValid)
             {
                 //mm
                 shippersBusinessModelLayers.AddShippers(shippers);
                 return(RedirectToAction("List"));
             }
             else
             {
                 return(View());
             }
         }
         catch (Exception ex)
         {
             BusinessLayer.ExceptionLogging exlog = new BusinessLayer.ExceptionLogging();
             exlog.SendExcepToDB(ex);
             throw;
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
예제 #3
0
        //BEGIN - readBy
        public ShippersSingle GetShippersData(int ShipperID)
        {
            try     // handle exogenous exceptions
            {
                try // log all exceptions
                {
                    ShippersSingle shippers = new ShippersSingle();
                    using (SqlConnection con = new SqlConnection(connectionString))
                    {
                        string sqlQuery = "SELECT * FROM [Shippers] WHERE ShipperID= " + ShipperID.ToString();

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

                                //shippers.Phone = (string)rdr["Phone"];
                                shippers.Phone = rdr["Phone"] == DBNull.Value ? "" : (string)rdr["Phone"];


                                //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(shippers);
                }
                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;
            }
        }
예제 #4
0
        //END - readBy
        //BEGIN - create
        public void AddShippers(ShippersSingle shippers)
        {
            try     // handle exogenous exceptions
            {
                try // log all exceptions
                {
                    using (SqlConnection con = new SqlConnection(connectionString))
                    {
                        SqlCommand cmd = new SqlCommand("spAddShippers", con)
                        {
                            CommandType = CommandType.StoredProcedure
                        };
                        SqlParameter paramShipperID = new SqlParameter
                        {
                            ParameterName = "@ShipperID",
                            Value         = shippers.ShipperID
                        };
                        cmd.Parameters.Add(paramShipperID);

                        SqlParameter paramCompanyName = new SqlParameter
                        {
                            ParameterName = "@CompanyName",
                            Value         = shippers.CompanyName
                        };
                        cmd.Parameters.Add(paramCompanyName);

                        SqlParameter paramPhone = new SqlParameter
                        {
                            ParameterName = "@Phone",
                            Value         = shippers.Phone
                        };
                        cmd.Parameters.Add(paramPhone);

                        con.Open();
                        cmd.ExecuteNonQuery();
                        cmd.Dispose();
                    }
                }
                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;
            }
        }
예제 #5
0
        //END - create

        //BEGIN - update
        public void UpdateShippers(ShippersSingle shippers)
        {
            try     // handle exogenous exceptions
            {
                try // log all exceptions
                {
                    using (SqlConnection con = new SqlConnection(connectionString))
                    {
                        using (SqlCommand cmd = new SqlCommand("spUpdateShippers", con)
                        {
                            CommandType = CommandType.StoredProcedure
                        })
                        {
                            cmd.Parameters.AddWithValue("@ShipperID", shippers.ShipperID);
                            cmd.Parameters.AddWithValue("@CompanyName", shippers.CompanyName);
                            cmd.Parameters.AddWithValue("@Phone", (object)shippers.Phone ?? DBNull.Value);
                            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;
            }
        }
예제 #6
0
        public ActionResult Details(int ShipperID)
        {
            try     // handle exogenous exceptions
            {
                try // log all exceptions
                {
                    ShippersBusinessModelLayers shippersBusinessModelLayers = new ShippersBusinessModelLayers();

                    BusinessModelLayer.ShippersSingle shippers = shippersBusinessModelLayers.GetAllShipperss().FirstOrDefault(x => x.ShipperID == ShipperID);

                    return(View(shippers));
                }
                catch (Exception ex)
                {
                    BusinessLayer.ExceptionLogging exlog = new BusinessLayer.ExceptionLogging();
                    exlog.SendExcepToDB(ex);
                    throw;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }