Exemple #1
0
        /// <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);
        }
Exemple #2
0
        /// <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);
        }