Ejemplo n.º 1
0
 public ActionResult Create_Post()
 {
     try     // handle exogenous exceptions
     {
         try // log all exceptions
         {
             CategoriesBusinessModelLayers       categoriesBusinessModelLayers = new CategoriesBusinessModelLayers();
             BusinessModelLayer.CategoriesSingle categories = new BusinessModelLayer.CategoriesSingle();
             TryUpdateModel(categories);
             if (ModelState.IsValid)
             {
                 //mm
                 categoriesBusinessModelLayers.AddCategories(categories);
                 return(RedirectToAction("List"));
             }
             else
             {
                 return(View());
             }
         }
         catch (Exception ex)
         {
             BusinessLayer.ExceptionLogging exlog = new BusinessLayer.ExceptionLogging();
             exlog.SendExcepToDB(ex);
             throw;
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 2
0
        //END - readBy
        //BEGIN - create
        public void AddCategories(CategoriesSingle categories)
        {
            try     // handle exogenous exceptions
            {
                try // log all exceptions
                {
                    using (SqlConnection con = new SqlConnection(connectionString))
                    {
                        SqlCommand cmd = new SqlCommand("spAddCategories", con)
                        {
                            CommandType = CommandType.StoredProcedure
                        };
                        SqlParameter paramCategoryID = new SqlParameter
                        {
                            ParameterName = "@CategoryID",
                            Value         = categories.CategoryID
                        };
                        cmd.Parameters.Add(paramCategoryID);

                        SqlParameter paramCategoryName = new SqlParameter
                        {
                            ParameterName = "@CategoryName",
                            Value         = categories.CategoryName
                        };
                        cmd.Parameters.Add(paramCategoryName);

                        SqlParameter paramDescription = new SqlParameter
                        {
                            ParameterName = "@Description",
                            Value         = categories.Description
                        };
                        cmd.Parameters.Add(paramDescription);

                        SqlParameter paramPicture = new SqlParameter
                        {
                            ParameterName = "@Picture",
                            Value         = categories.Picture
                        };
                        cmd.Parameters.Add(paramPicture);

                        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;
            }
        }
Ejemplo n.º 3
0
        //BEGIN - readBy
        public CategoriesSingle GetCategoriesData(int CategoryID)
        {
            try     // handle exogenous exceptions
            {
                try // log all exceptions
                {
                    CategoriesSingle categories = new CategoriesSingle();
                    using (SqlConnection con = new SqlConnection(connectionString))
                    {
                        string sqlQuery = "SELECT * FROM [Categories] WHERE CategoryID= " + CategoryID.ToString();

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

                                //categories.Description = (string)rdr["Description"];
                                categories.Description = rdr["Description"] == DBNull.Value ? "" : (string)rdr["Description"];


                                //categories.Picture = (byte[])rdr["Picture"];
                                categories.Picture = rdr["Picture"] == DBNull.Value ? default(byte[]) : (byte[])rdr["Picture"];

                                //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(categories);
                }
                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;
            }
        }
Ejemplo n.º 4
0
        //END - create

        //BEGIN - update
        public void UpdateCategories(CategoriesSingle categories)
        {
            try     // handle exogenous exceptions
            {
                try // log all exceptions
                {
                    using (SqlConnection con = new SqlConnection(connectionString))
                    {
                        using (SqlCommand cmd = new SqlCommand("spUpdateCategories", con)
                        {
                            CommandType = CommandType.StoredProcedure
                        })
                        {
                            cmd.Parameters.AddWithValue("@CategoryID", categories.CategoryID);
                            cmd.Parameters.AddWithValue("@CategoryName", categories.CategoryName);
                            cmd.Parameters.AddWithValue("@Description", (object)categories.Description ?? DBNull.Value);
                            cmd.Parameters.AddWithValue("@Picture", (object)categories.Picture ?? 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;
            }
        }
Ejemplo n.º 5
0
        public ActionResult Details(int CategoryID)
        {
            try     // handle exogenous exceptions
            {
                try // log all exceptions
                {
                    CategoriesBusinessModelLayers categoriesBusinessModelLayers = new CategoriesBusinessModelLayers();

                    BusinessModelLayer.CategoriesSingle categories = categoriesBusinessModelLayers.GetAllCategoriess().FirstOrDefault(x => x.CategoryID == CategoryID);

                    return(View(categories));
                }
                catch (Exception ex)
                {
                    BusinessLayer.ExceptionLogging exlog = new BusinessLayer.ExceptionLogging();
                    exlog.SendExcepToDB(ex);
                    throw;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 6
0
        //END - delete


        //BEGIN - read
        public List <CategoriesSingle> GetAllCategoriess()
        {
            try     // handle exogenous exceptions
            {
                try // log all exceptions
                {
                    List <CategoriesSingle> categoriess = new List <CategoriesSingle>();

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

                        con.Open();

                        SqlDataReader rdr = cmd.ExecuteReader();

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

                                //CategoryID = (int)rdr["CategoryID"]
                                CategoryID = rdr["CategoryID"] == DBNull.Value ? default(int) : (int)rdr["CategoryID"]
                                             //,CategoryName = (string)rdr["CategoryName"]
                                ,
                                CategoryName = rdr["CategoryName"] == DBNull.Value ? "" : (string)rdr["CategoryName"]
                                               //,Description = (string)rdr["Description"]
                                ,
                                Description = rdr["Description"] == DBNull.Value ? "" : (string)rdr["Description"]
                                              //,Picture = (byte[])rdr["Picture"]
                                ,
                                Picture = rdr["Picture"] == DBNull.Value ? default(byte[]) : (byte[])rdr["Picture"]
                            };
                            categoriess.Add(categories);
                        }
                        con.Close();
                        cmd.Dispose();
                    }
                    return(categoriess);
                }
                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;
            }
        }