/// <summary> /// Purpose: Add a new Product to the database /// Accepts: Hashtable /// Returns: String (Product Code) /// </summary> public string AddProduct(Hashtable hsh) { //The product code that was added to database string retProdcd = ""; Product prod = new Product(); QuickStart_DBEntities dbContext; try { dbContext = new QuickStart_DBEntities(); prod.ProductCode = Convert.ToString(hsh["productcode"]); prod.Name = Convert.ToString(hsh["name"]); prod.Brand = Convert.ToString(hsh["brand"]); prod.Description = Convert.ToString(hsh["description"]); prod.CategoryID = Convert.ToInt32(hsh["categoryid"]); prod.MSRP = Convert.ToDouble(hsh["msrp"]); prod.isFreeShipping = Convert.ToBoolean(hsh["isfreeshipping"]); prod.isTaxFree = Convert.ToBoolean(hsh["istaxfree"]); prod.QuantityInStock = Convert.ToInt32(hsh["quantityinstock"]); prod.IsQuantityUnlimited = Convert.ToBoolean(hsh["isquantityunlimited"]); prod.Created = DateTime.Now; prod.Modified = null; prod.isActive = true; //set to active dbContext.AddToProducts(prod); dbContext.SaveChanges(); retProdcd = prod.ProductCode; dbContext.Detach(prod); } catch (Exception e) { ErrorRoutine(e, "ProductData", "AddProduct"); } return retProdcd; }
/// <summary> /// Purpose: Add new user's information to the DB /// Accepts: Hashtable /// Returns: int /// </summary> public int AddUser(Hashtable hsh) { int newId = -1; User usr = new User(); QuickStart_DBEntities dbContext; try { dbContext = new QuickStart_DBEntities(); usr.Username = Convert.ToString(hsh["username"]); usr.Password = Convert.ToString(hsh["password"]); usr.Salutation = Convert.ToString(hsh["salutation"]); usr.FirstName = Convert.ToString(hsh["firstName"]); usr.LastName = Convert.ToString(hsh["lastName"]); usr.Address1 = Convert.ToString(hsh["address1"]); usr.Address2 = Convert.ToString(hsh["address2"]); usr.City = Convert.ToString(hsh["city"]); usr.StateProvinceID = Convert.ToInt32(hsh["stateProv"]); usr.ZipPostalCode = Convert.ToString(hsh["zipPC"]); usr.Email = Convert.ToString(hsh["email"]); usr.IsReceiveNewsletters = Convert.ToBoolean(hsh["newsletters"]); usr.Created = DateTime.Now; dbContext.AddToUsers(usr); dbContext.SaveChanges(); newId = usr.UserID; dbContext.Detach(usr); } catch (Exception e) { ErrorLoggerData.ErrorRoutine(e, "UserData", "AddUser"); } return newId; }
/// <summary> /// Purpose: Update an existing Product in the database /// Accepts: Hashtable /// Returns: Boolean /// </summary> public bool UpdateProduct(Hashtable hsh) { bool isSuccess = false; Product prod = new Product(); QuickStart_DBEntities dbContext; try { dbContext = new QuickStart_DBEntities(); string prodcd = hsh["productcode"].ToString(); prod = dbContext.Products.FirstOrDefault(p => p.ProductCode == prodcd); prod.Name = Convert.ToString(hsh["name"]); prod.Brand = Convert.ToString(hsh["brand"]); prod.Description = Convert.ToString(hsh["description"]); prod.CategoryID = Convert.ToInt32(hsh["categoryid"]); prod.MSRP = Convert.ToDouble(hsh["msrp"]); prod.isFreeShipping = Convert.ToBoolean(hsh["isfreeshipping"]); prod.isTaxFree = Convert.ToBoolean(hsh["istaxfree"]); prod.QuantityInStock = Convert.ToInt32(hsh["quantityinstock"]); prod.IsQuantityUnlimited = Convert.ToBoolean(hsh["isquantityunlimited"]); //need 'modified' but not 'created' during an update prod.Modified = DateTime.Now; prod.isActive = Convert.ToBoolean(hsh["isactive"]); dbContext.SaveChanges(); isSuccess = true; } catch (Exception e) { ErrorRoutine(e, "ProductData", "UpdateProduct"); } return isSuccess; }
/// <summary> /// Purpose: Update an existing User in the database /// Accepts: Hashtable /// Returns: Boolean /// </summary> public bool UpdateUser(Hashtable hsh) { bool isSuccess = false; User usr = new User(); QuickStart_DBEntities dbContext; try { dbContext = new QuickStart_DBEntities(); //Get the user to update based on its id int userid = Convert.ToInt32(hsh["userid"]); usr = dbContext.Users.FirstOrDefault(u => u.UserID == userid); usr.Username = Convert.ToString(hsh["username"]); usr.Password = Convert.ToString(hsh["password"]); usr.Salutation = Convert.ToString(hsh["salutation"]); usr.FirstName = Convert.ToString(hsh["firstName"]); usr.LastName = Convert.ToString(hsh["lastName"]); usr.Address1 = Convert.ToString(hsh["address1"]); usr.Address2 = Convert.ToString(hsh["address2"]); usr.City = Convert.ToString(hsh["city"]); usr.StateProvinceID = Convert.ToInt32(hsh["stateProv"]); usr.ZipPostalCode = Convert.ToString(hsh["zipPC"]); usr.Email = Convert.ToString(hsh["email"]); usr.IsReceiveNewsletters = Convert.ToBoolean(hsh["newsletters"]); //need 'modified' but not 'created' during an update usr.Modified = DateTime.Now; dbContext.SaveChanges(); isSuccess = true; } catch (Exception e) { ErrorRoutine(e, "UserData", "UpdateUser"); } return isSuccess; }
/// <summary> /// Purpose: Update an existing Order in the database /// Accepts: Hashtable /// Returns: Boolean /// </summary> public bool UpdateOrder(Hashtable hsh) { bool isSuccess = false; Order order = new Order(); QuickStart_DBEntities dbContext; try { dbContext = new QuickStart_DBEntities(); int orderid = Convert.ToInt32(hsh["orderid"]); order = dbContext.Orders.FirstOrDefault(o => o.OrderID == orderid); order.UserID = Convert.ToInt32(hsh["userid"]); order.Subtotal = Convert.ToDouble(hsh["subtotal"]); order.Taxes = Convert.ToDouble(hsh["taxes"]); order.DeliveryCost = Convert.ToDouble(hsh["deliverycost"]); order.DeliveryTypeID= Convert.ToInt32(hsh["deliverytypeid"]); order.GrandTotal = Convert.ToDouble(hsh["grandtotal"]); //need 'modified' but not 'created' during an update order.Modified = DateTime.Now; dbContext.SaveChanges(); isSuccess = true; } catch (Exception e) { ErrorRoutine(e, "OrderData", "UpdateOrder"); } return isSuccess; }