// Add a new shopping cart item public static bool AddReview(string customerId, string productId, string review) { // get a configured DbCommand object DbCommand comm = GenericDataAccess.CreateCommand(); // set the stored procedure name comm.CommandText = "CatalogAddProductReview "; // create a new parameter DbParameter param = comm.CreateParameter(); param.ParameterName = "@CustomerID"; param.Value = customerId; param.DbType = DbType.String; comm.Parameters.Add(param); // create a new parameter param = comm.CreateParameter(); param.ParameterName = "@ProductID"; param.Value = productId; param.DbType = DbType.Int32; comm.Parameters.Add(param); // create a new parameter param = comm.CreateParameter(); param.ParameterName = "@Review"; param.Value = review; param.DbType = DbType.String; comm.Parameters.Add(param); // returns true in case of success or false in case of an error try { // execute the stored procedure and return true if it executes // successfully, or false otherwise return(GenericDataAccess.ExecuteNonQuery(comm) != -1); } catch { // prevent the exception from propagating, but return false to // signal the error return(false); } }
// Add a new department public static bool AddDepartment(string name, string description) { // get a configured DbCommand object DbCommand comm = GenericDataAccess.CreateCommand(); // set the stored procedure name comm.CommandText = "CatalogAddDepartment"; // create a new parameter DbParameter param = comm.CreateParameter(); param.ParameterName = "@DepartmentName"; param.Value = name; param.DbType = DbType.String; param.Size = 50; comm.Parameters.Add(param); // create a new parameter param = comm.CreateParameter(); param.ParameterName = "@DepartmentDescription"; param.Value = description; param.DbType = DbType.String; param.Size = 1000; comm.Parameters.Add(param); // result will represent the number of changed rows int result = -1; try { // execute the stored procedure result = GenericDataAccess.ExecuteNonQuery(comm); } catch { // any errors are logged in GenericDataAccess, we ignore them here } // result will be 1 in case of success return(result != -1); }
public static void Update(OrderInfo orderInfo) { // get a configured DbCommand object DbCommand comm = GenericDataAccess.CreateCommand(); // set the stored procedure name comm.CommandText = "OrderUpdate"; // create a new parameter DbParameter param = comm.CreateParameter(); param.ParameterName = "@OrderID"; param.Value = orderInfo.OrderID; param.DbType = DbType.Int32; comm.Parameters.Add(param); // create a new parameter param = comm.CreateParameter(); param.ParameterName = "@DateCreated"; param.Value = orderInfo.DateCreated; param.DbType = DbType.DateTime; comm.Parameters.Add(param); // The DateShipped parameter is sent only if data is available if (orderInfo.DateShipped.Trim() != "") { param = comm.CreateParameter(); param.ParameterName = "@DateShipped"; param.Value = orderInfo.DateShipped; param.DbType = DbType.DateTime; comm.Parameters.Add(param); } // create a new parameter param = comm.CreateParameter(); param.ParameterName = "@Verified"; param.Value = orderInfo.Verified; param.DbType = DbType.Byte; comm.Parameters.Add(param); // create a new parameter param = comm.CreateParameter(); param.ParameterName = "@Completed"; param.Value = orderInfo.Completed; param.DbType = DbType.Byte; comm.Parameters.Add(param); // create a new parameter param = comm.CreateParameter(); param.ParameterName = "@Canceled"; param.Value = orderInfo.Canceled; param.DbType = DbType.Byte; comm.Parameters.Add(param); // create a new parameter param = comm.CreateParameter(); param.ParameterName = "@Comments"; param.Value = orderInfo.Comments; param.DbType = DbType.String; comm.Parameters.Add(param); // create a new parameter param = comm.CreateParameter(); param.ParameterName = "@CustomerName"; param.Value = orderInfo.CustomerName; param.DbType = DbType.String; comm.Parameters.Add(param); // create a new parameter param = comm.CreateParameter(); param.ParameterName = "@ShippingAddress"; param.Value = orderInfo.ShippingAddress; param.DbType = DbType.String; comm.Parameters.Add(param); // create a new parameter param = comm.CreateParameter(); param.ParameterName = "@CustomerEmail"; param.Value = orderInfo.CustomerEmail; param.DbType = DbType.String; comm.Parameters.Add(param); // return the results GenericDataAccess.ExecuteNonQuery(comm); }
// Update an existing product public static bool UpdateProduct(string productId, string name, string description, string price, string Thumbnail, string Image, string PromoDept, string PromoFront) { // get a configured DbCommand object DbCommand comm = GenericDataAccess.CreateCommand(); // set the stored procedure name comm.CommandText = "CatalogUpdateProduct"; // create a new parameter DbParameter param = comm.CreateParameter(); param.ParameterName = "@ProductID"; param.Value = productId; param.DbType = DbType.Int32; comm.Parameters.Add(param); // create a new parameter param = comm.CreateParameter(); param.ParameterName = "@ProductName"; param.Value = name; param.DbType = DbType.String; param.Size = 50; comm.Parameters.Add(param); // create a new parameter param = comm.CreateParameter(); param.ParameterName = "@ProductDescription"; param.Value = description; param.DbType = DbType.String; comm.Parameters.Add(param); // create a new parameter param = comm.CreateParameter(); param.ParameterName = "@Price"; param.Value = price; param.DbType = DbType.Decimal; comm.Parameters.Add(param); // create a new parameter param = comm.CreateParameter(); param.ParameterName = "@Thumbnail"; param.Value = Thumbnail; param.DbType = DbType.String; param.Size = 50; comm.Parameters.Add(param); // create a new parameter param = comm.CreateParameter(); param.ParameterName = "@Image"; param.Value = Image; param.DbType = DbType.String; param.Size = 50; comm.Parameters.Add(param); // create a new parameter param = comm.CreateParameter(); param.ParameterName = "@PromoDept"; param.Value = PromoDept; param.DbType = DbType.Boolean; comm.Parameters.Add(param); // create a new parameter param = comm.CreateParameter(); param.ParameterName = "@PromoFront"; param.Value = PromoFront; param.DbType = DbType.Boolean; comm.Parameters.Add(param); // result will represent the number of changed rows int result = -1; try { // execute the stored procedure result = GenericDataAccess.ExecuteNonQuery(comm); } catch { // any errors are logged in GenericDataAccess, we ignore them here } // result will be 1 in case of success return(result != -1); }