Beispiel #1
0
 public ActionResult Create_Post()
 {
     try     // handle exogenous exceptions
     {
         try // log all exceptions
         {
             RegionBusinessModelLayers       regionBusinessModelLayers = new RegionBusinessModelLayers();
             BusinessModelLayer.RegionSingle region = new BusinessModelLayer.RegionSingle();
             TryUpdateModel(region);
             if (ModelState.IsValid)
             {
                 //mm
                 regionBusinessModelLayers.AddRegion(region);
                 return(RedirectToAction("List"));
             }
             else
             {
                 return(View());
             }
         }
         catch (Exception ex)
         {
             BusinessLayer.ExceptionLogging exlog = new BusinessLayer.ExceptionLogging();
             exlog.SendExcepToDB(ex);
             throw;
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #2
0
        //END - create

        //BEGIN - update
        public void UpdateRegion(RegionSingle region)
        {
            try     // handle exogenous exceptions
            {
                try // log all exceptions
                {
                    using (SqlConnection con = new SqlConnection(connectionString))
                    {
                        using (SqlCommand cmd = new SqlCommand("spUpdateRegion", con)
                        {
                            CommandType = CommandType.StoredProcedure
                        })
                        {
                            cmd.Parameters.AddWithValue("@RegionID", region.RegionID);
                            cmd.Parameters.AddWithValue("@RegionDescription", region.RegionDescription);
                            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;
            }
        }
Beispiel #3
0
        //END - delete


        //BEGIN - read
        public List <RegionSingle> GetAllRegions()
        {
            try     // handle exogenous exceptions
            {
                try // log all exceptions
                {
                    List <RegionSingle> regions = new List <RegionSingle>();

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

                        con.Open();

                        SqlDataReader rdr = cmd.ExecuteReader();

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

                                //RegionID = (int)rdr["RegionID"]
                                RegionID = rdr["RegionID"] == DBNull.Value ? default(int) : (int)rdr["RegionID"]
                                           //,RegionDescription = (string)rdr["RegionDescription"]
                                ,
                                RegionDescription = rdr["RegionDescription"] == DBNull.Value ? "" : (string)rdr["RegionDescription"]
                            };
                            regions.Add(region);
                        }
                        con.Close();
                        cmd.Dispose();
                    }
                    return(regions);
                }
                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;
            }
        }
Beispiel #4
0
        //BEGIN - readBy
        public RegionSingle GetRegionData(int RegionID)
        {
            try     // handle exogenous exceptions
            {
                try // log all exceptions
                {
                    RegionSingle region = new RegionSingle();
                    using (SqlConnection con = new SqlConnection(connectionString))
                    {
                        string sqlQuery = "SELECT * FROM [Region] WHERE RegionID= " + RegionID.ToString();

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


                                //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(region);
                }
                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;
            }
        }
Beispiel #5
0
        public ActionResult Details(int RegionID)
        {
            try     // handle exogenous exceptions
            {
                try // log all exceptions
                {
                    RegionBusinessModelLayers regionBusinessModelLayers = new RegionBusinessModelLayers();

                    BusinessModelLayer.RegionSingle region = regionBusinessModelLayers.GetAllRegions().FirstOrDefault(x => x.RegionID == RegionID);

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