//END - create //BEGIN - update public void UpdateCustomerdemographics(CustomerdemographicsSingle customerdemographics) { try // handle exogenous exceptions { try // log all exceptions { using (SqlConnection con = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand("spUpdateCustomerdemographics", con) { CommandType = CommandType.StoredProcedure }) { cmd.Parameters.AddWithValue("@CustomerTypeID", customerdemographics.CustomerTypeID); cmd.Parameters.AddWithValue("@CustomerDesc", (object)customerdemographics.CustomerDesc ?? 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; } }
public ActionResult Create_Post() { try // handle exogenous exceptions { try // log all exceptions { CustomerdemographicsBusinessModelLayers customerdemographicsBusinessModelLayers = new CustomerdemographicsBusinessModelLayers(); BusinessModelLayer.CustomerdemographicsSingle customerdemographics = new BusinessModelLayer.CustomerdemographicsSingle(); TryUpdateModel(customerdemographics); if (ModelState.IsValid) { //mm customerdemographicsBusinessModelLayers.AddCustomerdemographics(customerdemographics); 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 <CustomerdemographicsSingle> GetAllCustomerdemographicss() { try // handle exogenous exceptions { try // log all exceptions { List <CustomerdemographicsSingle> customerdemographicss = new List <CustomerdemographicsSingle>(); using (SqlConnection con = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand("spGetAllCustomerdemographics", con) { CommandType = CommandType.StoredProcedure }; con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { CustomerdemographicsSingle customerdemographics = new CustomerdemographicsSingle { // EXAMPLES: //EmployeeId = Convert.ToInt32(rdr["EmployeeId"]), //Name = rdr["Name"].ToString(), //IsPermanent = (bool)rdr["IsPermanent"], //Salary = Convert.ToDecimal(rdr["Salary"]), //DateOfBirth = Convert.ToDateTime(rdr["DateOfBirth"]) //CustomerTypeID = (string)rdr["CustomerTypeID"] CustomerTypeID = rdr["CustomerTypeID"] == DBNull.Value ? "" : (string)rdr["CustomerTypeID"] //,CustomerDesc = (string)rdr["CustomerDesc"] , CustomerDesc = rdr["CustomerDesc"] == DBNull.Value ? "" : (string)rdr["CustomerDesc"] }; customerdemographicss.Add(customerdemographics); } con.Close(); cmd.Dispose(); } return(customerdemographicss); } 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; } }
//BEGIN - readBy public CustomerdemographicsSingle GetCustomerdemographicsData(string CustomerTypeID) { try // handle exogenous exceptions { try // log all exceptions { CustomerdemographicsSingle customerdemographics = new CustomerdemographicsSingle(); using (SqlConnection con = new SqlConnection(connectionString)) { string sqlQuery = "SELECT * FROM [CustomerDemographics] WHERE CustomerTypeID= '" + CustomerTypeID.ToString() + "'"; using (SqlCommand cmd = new SqlCommand(sqlQuery, con)) { con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { //customerdemographics.CustomerTypeID = (string)rdr["CustomerTypeID"]; customerdemographics.CustomerTypeID = rdr["CustomerTypeID"] == DBNull.Value ? "" : (string)rdr["CustomerTypeID"]; //customerdemographics.CustomerDesc = (string)rdr["CustomerDesc"]; customerdemographics.CustomerDesc = rdr["CustomerDesc"] == DBNull.Value ? "" : (string)rdr["CustomerDesc"]; //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(customerdemographics); } 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 - readBy //BEGIN - create public void AddCustomerdemographics(CustomerdemographicsSingle customerdemographics) { try // handle exogenous exceptions { try // log all exceptions { using (SqlConnection con = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand("spAddCustomerdemographics", con) { CommandType = CommandType.StoredProcedure }; SqlParameter paramCustomerTypeID = new SqlParameter { ParameterName = "@CustomerTypeID", Value = customerdemographics.CustomerTypeID }; cmd.Parameters.Add(paramCustomerTypeID); SqlParameter paramCustomerDesc = new SqlParameter { ParameterName = "@CustomerDesc", Value = customerdemographics.CustomerDesc }; cmd.Parameters.Add(paramCustomerDesc); 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; } }
public ActionResult Details(string CustomerTypeID) { try // handle exogenous exceptions { try // log all exceptions { CustomerdemographicsBusinessModelLayers customerdemographicsBusinessModelLayers = new CustomerdemographicsBusinessModelLayers(); BusinessModelLayer.CustomerdemographicsSingle customerdemographics = customerdemographicsBusinessModelLayers.GetAllCustomerdemographicss().FirstOrDefault(x => x.CustomerTypeID == CustomerTypeID); return(View(customerdemographics)); } catch (Exception ex) { BusinessLayer.ExceptionLogging exlog = new BusinessLayer.ExceptionLogging(); exlog.SendExcepToDB(ex); throw; } } catch (Exception) { throw; } }