Ejemplo n.º 1
0
        /// <summary>
        /// Register - add Customer Row row from serialized dictionary
        /// </summary>
        /// <param name="dictionaryCust">packaged customer info</param>
        /// <returns>int representing newly updated id for customer or -1 if error</returns>
        public int Register(byte[] bytCustomer)
        {
            int custId = -1;
            Customer cust = new Customer();
            eStoreDBEntities dbContext = new eStoreDBEntities();

            try
            {
                Dictionary<string, Object> dictionaryCustomer = (Dictionary<string, Object>)Deserializer(bytCustomer);
                dbContext = new eStoreDBEntities();
                //  Change to retrieve and update based on Username  when SimpleMembership is added (next 2 lines)
                String username = Convert.ToString(dictionaryCustomer["username"]);
                cust = dbContext.Customers.FirstOrDefault(c => c.Username == username);
                cust.Username = Convert.ToString(dictionaryCustomer["username"]);
                cust.FirstName = Convert.ToString(dictionaryCustomer["firstname"]);
                cust.LastName = Convert.ToString(dictionaryCustomer["lastname"]);
                cust.Email = Convert.ToString(dictionaryCustomer["email"]);
                cust.Age = Convert.ToInt32(dictionaryCustomer["age"]);
                cust.Address1 = Convert.ToString(dictionaryCustomer["address1"]);
                cust.City = Convert.ToString(dictionaryCustomer["city"]);
                cust.Mailcode = Convert.ToString(dictionaryCustomer["mailcode"]);
                cust.Region = Convert.ToString(dictionaryCustomer["region"]);
                cust.Country = Convert.ToString(dictionaryCustomer["country"]);
                cust.Creditcardtype = Convert.ToString(dictionaryCustomer["creditcardtype"]);
                dbContext.SaveChanges();
                custId = cust.CustomerID;
            }
            catch (Exception ex)
            {
                ErrorRoutine(ex, "CustomerModel", "Register");
            }
            return custId;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// GetCurrentProfile - obtain Customer Row row from db
        /// </summary>
        /// <returns>packaged customer info in a dictionary and streamed to byte array</returns>
        public byte[] GetCurrentProfile(string username)
        {
            Customer cust = new Customer();
            eStoreDBEntities dbContext = new eStoreDBEntities();
            Dictionary<string, Object> dictionaryCustomer = new Dictionary<string, Object>();
            try
            {
                dbContext = new eStoreDBEntities();
                cust = dbContext.Customers.FirstOrDefault(c => c.Username == username);

                if (cust != null)
                {
                    dictionaryCustomer["username"] = cust.Username;
                    dictionaryCustomer["firstname"] = cust.FirstName;
                    dictionaryCustomer["lastname"] = cust.LastName;
                    dictionaryCustomer["email"] = cust.Email;
                    dictionaryCustomer["age"] = cust.Age;
                    dictionaryCustomer["address1"] = cust.Address1;
                    dictionaryCustomer["city"] = cust.City;
                    dictionaryCustomer["mailcode"] = cust.Mailcode;
                    dictionaryCustomer["region"] = cust.Region;
                    dictionaryCustomer["country"] = cust.Country;
                    dictionaryCustomer["creditcardtype"] = cust.Creditcardtype;
                    dictionaryCustomer["customerid"] = cust.CustomerID;
                }
            }
            catch (Exception ex)
            {
                ErrorRoutine(ex, "CustomerModel", "GetCurrentProfile");
            }
            return Serializer(dictionaryCustomer);
        }