/// <summary> /// Purpose: Grabs administrator information based on ID /// Accepts: Int /// Returns: Hashtable /// </summary> public Hashtable GetAdministratorByID(int id) { Administrator obj = new Administrator(); QuickStart_DBEntities dbContext; Hashtable hsh = new Hashtable(); try { dbContext = new QuickStart_DBEntities(); obj = dbContext.Administrators.FirstOrDefault(a => a.AdministratorID == id); if (obj != null) { hsh["adminid"] = obj.AdministratorID; hsh["username"] = obj.Username; hsh["password"] = obj.Password; hsh["firstname"] = obj.FirstName; hsh["lastname"] = obj.LastName; hsh["isactive"] = obj.IsActive; } } catch (Exception ex) { ErrorLoggerData.ErrorRoutine(ex, "AdministratorData", "GetAdministratorByID"); } return hsh; }
/// <summary> /// Purpose: Grabs delivery type information based on ID /// Accepts: Int /// Returns: Hashtable /// </summary> public Hashtable GetDeliveryTypeByID(int id) { DeliveryType obj = new DeliveryType(); QuickStart_DBEntities dbContext; Hashtable hsh = new Hashtable(); try { dbContext = new QuickStart_DBEntities(); obj = dbContext.DeliveryTypes.FirstOrDefault(d => d.DeliveryTypeID == id); if (obj != null) { hsh["deliverytypeid"] = obj.DeliveryTypeID; hsh["name"] = obj.Name; hsh["description"] = obj.Description; hsh["cost"] = obj.Cost; hsh["created"] = obj.Created; hsh["modified"] = obj.Modified; } } catch (Exception ex) { ErrorLoggerData.ErrorRoutine(ex, "DeliveryTypeData", "GetDeliveryTypeByID"); } return hsh; }
/// <summary> /// Purpose: Grabs audit information based on ID /// Accepts: Int /// Returns: Hashtable /// </summary> public Hashtable GetAuditByID(int id) { Audit obj = new Audit(); QuickStart_DBEntities dbContext; Hashtable hsh = new Hashtable(); try { dbContext = new QuickStart_DBEntities(); obj = dbContext.Audits.FirstOrDefault(a => a.AuditID == id); if (obj != null) { hsh["auditid"] = obj.AuditID; hsh["audittypeid"] = obj.AuditTypeID; hsh["userid"] = obj.UserID; hsh["adminid"] = obj.AdminID; hsh["notes"] = obj.Notes; hsh["created"] = obj.Created; } } catch (Exception ex) { ErrorLoggerData.ErrorRoutine(ex, "AuditData", "GetAuditByID"); } return hsh; }
/// <summary> /// Purpose: Grabs product delivery type information based on ID /// Accepts: Int /// Returns: Hashtable /// </summary> public Hashtable GetProductDeliveryTypeByID(int id) { ProductDeliveryType obj = new ProductDeliveryType(); QuickStart_DBEntities dbContext; Hashtable hsh = new Hashtable(); try { dbContext = new QuickStart_DBEntities(); obj = dbContext.ProductDeliveryTypes.FirstOrDefault(d => d.ProductDeliveryTypeID == id); if (obj != null) { hsh["productdeliverytypeid"] = obj.ProductDeliveryTypeID; hsh["deliverytypeid"] = obj.DeliveryTypeID; hsh["productcode"] = obj.ProductCode; hsh["created"] = obj.Created; hsh["modified"] = obj.Modified; } } catch (Exception ex) { ErrorLoggerData.ErrorRoutine(ex, "ProductDeliveryTypeData", "GetProductDeliveryTypeByID"); } return hsh; }
/// <summary> /// Purpose: Grabs state/province information based on ID /// Accepts: Int /// Returns: Hashtable /// </summary> public Hashtable GetStateProvinceByID(int id) { StatesProvince obj = new StatesProvince(); QuickStart_DBEntities dbContext; Hashtable hsh = new Hashtable(); try { dbContext = new QuickStart_DBEntities(); obj = dbContext.StatesProvinces.FirstOrDefault(s => s.StateProvinceID == id); if (obj != null) { hsh["stateprovinceid"] = obj.StateProvinceID; hsh["name"] = obj.Name; hsh["country"] = obj.Country; hsh["currencycode"] = obj.CurrencyCode; hsh["taxratepercentage"] = obj.TaxRatePercentage; hsh["modified"] = obj.Modified; } } catch (Exception ex) { ErrorLoggerData.ErrorRoutine(ex, "StateProvinceData", "GetStateProvinceByID"); } return hsh; }
/// <summary> /// Purpose: Grabs order information based on ID /// Accepts: Int /// Returns: Hashtable /// </summary> public Hashtable GetOrderByID(int id) { Order obj = new Order(); QuickStart_DBEntities dbContext; Hashtable hsh = new Hashtable(); try { dbContext = new QuickStart_DBEntities(); obj = dbContext.Orders.FirstOrDefault(o => o.OrderID == id); if (obj != null) { hsh["orderid"] = obj.OrderID; hsh["userid"] = obj.UserID; hsh["subtotal"] = obj.Subtotal; hsh["taxes"] = obj.Taxes; hsh["deliverytypeid"] = obj.DeliveryTypeID; hsh["deliverycost"] = obj.DeliveryCost; hsh["grandtotal"] = obj.GrandTotal; hsh["created"] = obj.Created; hsh["modified"] = obj.Modified; } } catch (Exception ex) { ErrorLoggerData.ErrorRoutine(ex, "OrderData", "GetOrderByID"); } return hsh; }
/// <summary> /// Purpose: Grabs configuration information based on configuration code /// Accepts: String /// Returns: Hashtable /// </summary> public Hashtable GetConfigurationByCode(string code) { Configuration obj = new Configuration(); QuickStart_DBEntities dbContext; Hashtable hsh = new Hashtable(); try { dbContext = new QuickStart_DBEntities(); obj = dbContext.Configurations.FirstOrDefault(c => c.ConfigurationCode == code); if (obj != null) { hsh["configurationcode"] = obj.ConfigurationCode; hsh["description"] = obj.Description; hsh["value"] = obj.Value; hsh["isyesnovalue"] = obj.IsYesNoValue; hsh["yesnovalue"] = obj.YesNoValue; hsh["modified"] = obj.Modified; } } catch (Exception ex) { ErrorLoggerData.ErrorRoutine(ex, "ConfigurationData", "GetConfigurationByCode"); } return hsh; }
/// <summary> /// Purpose: Grabs category information based on ID /// Accepts: Int /// Returns: Hashtable /// </summary> public Hashtable GetCategoryByID(int id) { Category obj = new Category(); QuickStart_DBEntities dbContext; Hashtable hsh = new Hashtable(); try { dbContext = new QuickStart_DBEntities(); obj = dbContext.Categories.FirstOrDefault(c => c.CategoryID == id); if (obj != null) { hsh["categoryid"] = obj.CategoryID; hsh["name"] = obj.Name; hsh["description"] = obj.Description; hsh["parentcategoryid"] = obj.ParentCategoryID; hsh["created"] = obj.Created; hsh["modified"] = obj.Modified; hsh["isactive"] = obj.IsActive; } } catch (Exception ex) { ErrorLoggerData.ErrorRoutine(ex, "CategoryData", "GetCategoryByID"); } return hsh; }
/// <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: Grabs orderitem information based on ID /// Accepts: Int /// Returns: Hashtable /// </summary> public Hashtable GetOrderItemByID(int id) { OrderItem obj = new OrderItem(); QuickStart_DBEntities dbContext; Hashtable hsh = new Hashtable(); try { dbContext = new QuickStart_DBEntities(); obj = dbContext.OrderItems.FirstOrDefault(o => o.OrderItemID == id); if (obj != null) { hsh["orderitemid"] = obj.OrderItemID; hsh["orderid"] = obj.OrderID; hsh["productcode"] = obj.ProductCode; hsh["quantity"] = obj.Quantity; hsh["created"] = obj.Created; hsh["modified"] = obj.Modified; } } catch (Exception ex) { ErrorLoggerData.ErrorRoutine(ex, "OrderItemData", "GetOrderItemByID"); } return hsh; }
/// <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: Grabs all InvoiceItems via stored procedure /// Accepts: Nothing /// Returns: List<InvoiceItem> /// </summary> public List<InvoiceItem> GetAllInvoiceItemsByOrderID(int orderid) { QuickStart_DBEntities dbContext; List<InvoiceItem> retList = null; try { dbContext = new QuickStart_DBEntities(); //all Invoice Items are returned for this order id retList = dbContext.spGetInvoiceItemsByOrderID(orderid).ToList(); } catch (Exception ex) { ErrorRoutine(ex, "InvoiceItemData", "GetAllInvoiceItemsByOrderID"); } return retList; }
/// <summary> /// Purpose: Grabs all StatesProvinces /// Accepts: Nothing /// Returns: List<StatesProvince> /// </summary> public List<StatesProvince> GetAllStatesProvinces() { QuickStart_DBEntities dbContext; List<StatesProvince> allstatesprovinces = null; try { dbContext = new QuickStart_DBEntities(); //all states/provinces are returned allstatesprovinces = dbContext.StatesProvinces.ToList(); } catch (Exception ex) { ErrorRoutine(ex, "StatesProvinceData", "GetAllStatesProvinces"); } return allstatesprovinces; }
/// <summary> /// Purpose: Grabs all audits /// Accepts: Nothing /// Returns: List<Audit> /// </summary> public List<Audit> GetAllAudits() { QuickStart_DBEntities dbContext; List<Audit> allaudits = null; try { dbContext = new QuickStart_DBEntities(); //all audits are returned allaudits = dbContext.Audits.ToList(); } catch (Exception ex) { ErrorRoutine(ex, "AuditData", "GetAllAudits"); } return allaudits; }
/// <summary> /// Purpose: Grabs all configuration settings /// Accepts: Nothing /// Returns: List<Configuration> /// </summary> public List<Configuration> GetAllConfigurations() { QuickStart_DBEntities dbContext; List<Configuration> allconfigs = null; try { dbContext = new QuickStart_DBEntities(); //all configurations are returned allconfigs = dbContext.Configurations.ToList(); } catch (Exception ex) { ErrorRoutine(ex, "ConfigurationData", "GetAllConfigurations"); } return allconfigs; }
/// <summary> /// Purpose: Grabs all product delivery types by product code /// Accepts: String (Product Code) /// Returns: List<ProductDeliveryType> /// </summary> public List<ProductDeliveryType> GetAllProductDeliveryTypesByProdCode(string prodcd) { QuickStart_DBEntities dbContext; List<ProductDeliveryType> proddeliverytypes = null; try { dbContext = new QuickStart_DBEntities(); //all product delivery types for this product are returned proddeliverytypes = dbContext.ProductDeliveryTypes.Where(pdt => pdt.ProductCode == prodcd).ToList(); } catch (Exception ex) { ErrorRoutine(ex, "ProductDeliveryTypeData", "GetAllDeliveryTypesByProdCode"); } return proddeliverytypes; }
/// <summary> /// Purpose: Grabs all users /// Accepts: Nothing /// Returns: List<User> /// </summary> public List<User> GetAllUsers() { QuickStart_DBEntities dbContext; List<User> allusers = null; try { dbContext = new QuickStart_DBEntities(); //all users are returned allusers = dbContext.Users.ToList(); } catch (Exception ex) { ErrorRoutine(ex, "UserData", "GetAllUsers"); } return allusers; }
/// <summary> /// Purpose: Grabs all order items /// Accepts: Nothing /// Returns: List<OrderItem> /// </summary> public List<OrderItem> GetAllOrderItems() { QuickStart_DBEntities dbContext; List<OrderItem> allorderitems = null; try { dbContext = new QuickStart_DBEntities(); //all order items are returned allorderitems = dbContext.OrderItems.ToList(); } catch (Exception ex) { ErrorRoutine(ex, "OrderItemData", "GetAllOrderItems"); } return allorderitems; }
/// <summary> /// Purpose: Grabs all language labels /// Accepts: Nothing /// Returns: List<LanguageLabel> /// </summary> public List<LangLabel> GetAllLangLabels() { QuickStart_DBEntities dbContext; List<LangLabel> alllanglabels = null; try { dbContext = new QuickStart_DBEntities(); //all language labels are returned alllanglabels = dbContext.LangLabels.ToList(); } catch (Exception ex) { ErrorRoutine(ex, "LangLabelData", "GetAllLangLabels"); } return alllanglabels; }
/// <summary> /// Purpose: Grabs all orders /// Accepts: Int representing the userID /// Returns: List<Order> /// </summary> public List<Order> GetAllOrdersByUserID(int uId) { QuickStart_DBEntities dbContext; List<Order> allorders = null; try { dbContext = new QuickStart_DBEntities(); //all orders are returned allorders = dbContext.Orders.Where(o => o.UserID == uId).ToList(); } catch (Exception ex) { ErrorRoutine(ex, "OrderData", "GetAllOrders"); } return allorders; }
/// <summary> /// Purpose: Grabs all delivery types /// Accepts: Nothing /// Returns: List<DeliveryType> /// </summary> public List<DeliveryType> GetAllDeliveryTypes() { QuickStart_DBEntities dbContext; List<DeliveryType> alldeliverytypes = null; try { dbContext = new QuickStart_DBEntities(); //all delivery types are returned alldeliverytypes = dbContext.DeliveryTypes.ToList(); } catch (Exception ex) { ErrorRoutine(ex, "DeliveryTypeData", "GetAllDeliveryTypes"); } return alldeliverytypes; }
/// <summary> /// Purpose: Grabs audit type information based on ID /// Accepts: Int /// Returns: Hashtable /// </summary> public Hashtable GetAuditTypeByID(int id) { AuditType obj = new AuditType(); QuickStart_DBEntities dbContext; Hashtable hsh = new Hashtable(); try { dbContext = new QuickStart_DBEntities(); obj = dbContext.AuditTypes.FirstOrDefault(a => a.AuditTypeID == id); if (obj != null) { hsh["audittypeid"] = obj.AuditTypeID; hsh["description"] = obj.Description; hsh["isadmin"] = obj.IsAdmin; } } catch (Exception ex) { ErrorLoggerData.ErrorRoutine(ex, "AuditTypeData", "GetAuditTypeByID"); } return hsh; }
/// <summary> /// Purpose: Grabs language label information based on language label code /// Accepts: String /// Returns: Hashtable /// </summary> public Hashtable GetLangLabelByCode(string code) { LangLabel obj = new LangLabel(); QuickStart_DBEntities dbContext; Hashtable hsh = new Hashtable(); try { dbContext = new QuickStart_DBEntities(); obj = dbContext.LangLabels.FirstOrDefault(l => l.LangLabelCode == code); if (obj != null) { hsh["langlabelcode"] = obj.LangLabelCode; hsh["value"] = obj.Value; hsh["modified"] = obj.Modified; } } catch (Exception ex) { ErrorLoggerData.ErrorRoutine(ex, "LangLabelData", "GetLangLabelByCode"); } return hsh; }
/// <summary> /// Purpose: Grabs all administrators /// Accepts: Boolean /// Returns: List<Administrator> /// </summary> public List<Administrator> GetAllAdministrators(bool onlyActive) { QuickStart_DBEntities dbContext; List<Administrator> alladministrators = null; try { dbContext = new QuickStart_DBEntities(); if (onlyActive == true) //only the active administrators are returned { alladministrators = dbContext.Administrators.Where(a => a.IsActive == true).ToList(); } else //all administrators are returned { alladministrators = dbContext.Administrators.ToList(); } } catch (Exception ex) { ErrorRoutine(ex, "AdministratorData", "GetAllAdministrators"); } return alladministrators; }
/// <summary> /// Purpose: Grabs all products /// Accepts: Boolean /// Returns: List<Product> /// </summary> public List<Product> GetAllProducts(bool onlyActive) { QuickStart_DBEntities dbContext; List<Product> allproducts = null; try { dbContext = new QuickStart_DBEntities(); if (onlyActive == true) //only the active products are returned { allproducts = dbContext.Products.Where(p => p.isActive == true).ToList(); } else //all products are returned { allproducts = dbContext.Products.ToList(); } } catch (Exception ex) { ErrorRoutine(ex, "ProductData", "GetAllProducts"); } return allproducts; }
/// <summary> /// Purpose: Grabs all categories /// Accepts: Boolean /// Returns: List<Category> /// </summary> public List<Category> GetAllCategories(bool onlyActive) { QuickStart_DBEntities dbContext; List<Category> allCategories = null; try { dbContext = new QuickStart_DBEntities(); if (onlyActive == true) //only the active categories are returned { allCategories = dbContext.Categories.Where(c => c.IsActive == true).ToList(); } else //all categories are returned { allCategories = dbContext.Categories.ToList(); } } catch (Exception ex) { ErrorRoutine(ex, "CategoryData", "GetAllCategories"); } return allCategories; }
/// <summary> /// Purpose: Grabs administrator ID based on administrator login information /// Accepts: Hashtable /// Returns: Int /// </summary> public int Login(Hashtable hsh) { QuickStart_DBEntities dbContext; int retAdminID = -1; try { String username = Convert.ToString(hsh["username"]); String password = Convert.ToString(hsh["password"]); dbContext = new QuickStart_DBEntities(); //Use Linq to Entities syntax to retrieve desired Administrator Administrator admin = null; admin = dbContext.Administrators.FirstOrDefault(a => a.Username == username); if (admin != null) { if (admin.Password == password) { retAdminID = admin.AdministratorID; } } } catch (Exception ex) { ErrorLoggerData.ErrorRoutine(ex, "AdministratorData", "Login"); retAdminID = -1; } return retAdminID; }
/// <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: Grabs product information based on product code /// Accepts: String /// Returns: Hashtable /// </summary> public Hashtable GetProductByCode(string code) { Product obj = new Product(); QuickStart_DBEntities dbContext; Hashtable hsh = new Hashtable(); try { dbContext = new QuickStart_DBEntities(); obj = dbContext.Products.FirstOrDefault(p => p.ProductCode == code); if (obj != null) { hsh["productcode"] = obj.ProductCode; hsh["name"] = obj.Name; hsh["brand"] = obj.Brand; hsh["description"] = obj.Description; hsh["categoryid"] = obj.CategoryID; hsh["msrp"] = obj.MSRP; hsh["isfreeshipping"] = obj.isFreeShipping; hsh["istaxfree"] = obj.isTaxFree; hsh["quantityinstock"] = obj.QuantityInStock; hsh["isquantityunlimited"] = obj.IsQuantityUnlimited; hsh["created"] = obj.Created; hsh["modified"] = obj.Modified; hsh["isactive"] = obj.isActive; } } catch (Exception ex) { ErrorLoggerData.ErrorRoutine(ex, "ProductData", "GetProductByCode"); } return hsh; }
/// <summary> /// Purpose: Grabs user information based on ID /// Accepts: Int /// Returns: Hashtable /// </summary> public Hashtable GetUserByID(int id) { User obj = new User(); QuickStart_DBEntities dbContext; Hashtable hsh = new Hashtable(); try { dbContext = new QuickStart_DBEntities(); obj = dbContext.Users.FirstOrDefault(u => u.UserID == id); if (obj != null) { hsh["userid"] = obj.UserID; hsh["username"] = obj.Username; hsh["password"] = obj.Password; hsh["salutation"] = obj.Salutation; hsh["firstname"] = obj.FirstName; hsh["lastname"] = obj.LastName; hsh["address1"] = obj.Address1; hsh["address2"] = obj.Address2; hsh["city"] = obj.City; hsh["stateprovinceid"] = obj.StateProvinceID; hsh["zippostalcode"] = obj.ZipPostalCode; hsh["email"] = obj.Email; hsh["isreceivenewsletters"] = obj.IsReceiveNewsletters; hsh["created"] = obj.Created; hsh["modified"] = obj.Modified; } } catch (Exception ex) { ErrorLoggerData.ErrorRoutine(ex, "UserData", "GetUserByID"); } return hsh; }