/// <summary>
 /// Create a new User object.
 /// </summary>
 /// <param name="userID">Initial value of the UserID property.</param>
 /// <param name="username">Initial value of the Username property.</param>
 /// <param name="firstName">Initial value of the FirstName property.</param>
 /// <param name="lastName">Initial value of the LastName property.</param>
 /// <param name="isSuperUser">Initial value of the IsSuperUser property.</param>
 /// <param name="displayName">Initial value of the DisplayName property.</param>
 /// <param name="updatePassword">Initial value of the UpdatePassword property.</param>
 /// <param name="isDeleted">Initial value of the IsDeleted property.</param>
 public static User CreateUser(global::System.Int32 userID, global::System.String username, global::System.String firstName, global::System.String lastName, global::System.Boolean isSuperUser, global::System.String displayName, global::System.Boolean updatePassword, global::System.Boolean isDeleted)
 {
     User user = new User();
     user.UserID = userID;
     user.Username = username;
     user.FirstName = firstName;
     user.LastName = lastName;
     user.IsSuperUser = isSuperUser;
     user.DisplayName = displayName;
     user.UpdatePassword = updatePassword;
     user.IsDeleted = isDeleted;
     return user;
 }
Пример #2
0
        public static bool InsertIntoDB(XmlTextReader xml, fanlive4Entities entity)
        {
            bool insideOrganization = false;
            bool insideShippingAddress = false;
            bool insidePaymentType = false;
            bool insideBillingAddress = false;
            bool insideExtensions = false;
            bool insideDefaultMailingAddress = false;
            bool insideUsers = false;
            bool insidePyamentType = false;
            bool isDefault = false;
            User newdealer = new User();
            string paymentTerms = string.Empty;
            int userid = 0;
            bool net30 = false;
            UserProfile dealerprofile = new UserProfile();
            string pricelist = string.Empty;
            string nodeName = "";
            try
            {
                while (xml.Read())
                {

                    switch (xml.NodeType)
                    {
                        case XmlNodeType.Element: // The node is an element.
                            if (xml.Name.Equals("organization"))
                            {
                                insideOrganization = true;
                                newdealer = new User();
                                newdealer.IsSuperUser = false;
                            }
                            else if (xml.Name.Equals("users"))
                                insideUsers = true;
                            else if (xml.Name.Equals("shippingAddress"))
                                insideShippingAddress = true;
                            else if (xml.Name.Equals("paymentType"))
                                insidePyamentType = true;
                            else if (xml.Name.Equals("extensions"))
                                insideExtensions = true;
                            else
                                nodeName = xml.Name;
                            break;
                        case XmlNodeType.Text: //Display the text in each element.
                            if (nodeName.Equals("name"))
                            {
                                if (xml.Value != null && xml.Value.Contains("Charmaine"))
                                    newdealer.FirstName = xml.Value;
                                newdealer.DisplayName = xml.Value;

                            }
                            else if (nodeName.Equals("description"))
                            {
                                newdealer.LastName = xml.Value;
                            }
                            else if (insideShippingAddress)
                            {
                                if (nodeName.Equals("default") && xml.Value.Equals("true"))
                                {
                                    isDefault = true;
                                }
                                else if (isDefault)
                                {
                                }
                            }
                            else if (insideExtensions && !insideShippingAddress && !insideUsers && !insidePyamentType)
                            {

                                if (nodeName.Equals("taaAccountId") && xml.Value.Trim().Contains("162859"))
                                {

                                }
                                if (nodeName.Equals("priceList"))
                                {

                                    pricelist = xml.Value;

                                }
                                else if (nodeName.Equals("residential"))
                                {

                                }
                                else if (nodeName.Equals("country"))
                                {

                                }
                                else if (nodeName.Equals("email"))
                                {
                                    if (xml.Value.Contains("*****@*****.**"))
                                        newdealer.Email = xml.Value;
                                    newdealer.Email = xml.Value;
                                    newdealer.Username = xml.Value;

                                }
                                else if (nodeName.Equals("paymentTerm"))
                                {
                                    paymentTerms = xml.Value;
                                    if (paymentTerms.Contains("NET30")) net30 = true;

                                }

                            }
                            break;
                        case XmlNodeType.EndElement: //Display the end of the element.
                            if (xml.Name.Equals("organization"))
                            {

                                if (newdealer.Email != null && newdealer.FirstName != null && newdealer.LastName != null && IsValid(newdealer.Email))
                                {

                                    var user = (from u in entity.Users where u.Email.Equals(newdealer.Email) select u).FirstOrDefault();

                                    if (user != null)
                                    {
                                        /// password format is 2 from existing users
                                        Console.WriteLine(user.UserID);
                                        //lovely changes from teamwork
                                        if (pricelist.ToLower().Equals("dealer"))
                                            pricelist = "Regular";
                                        UserProfile userprofile = (from u in entity.UserProfiles where u.UserID == user.UserID && u.PropertyDefinitionID == 69 select u).FirstOrDefault();

                                        if (userprofile != null)
                                        {
                                            userprofile.PropertyValue = pricelist;
                                        }
                                        else
                                        {
                                            userprofile = new UserProfile();
                                            userprofile.UserID = user.UserID;
                                            userprofile.PropertyDefinitionID = 69;
                                            userprofile.Visibility = 2;
                                            user.LastModifiedOnDate = DateTime.Now;
                                            userprofile.PropertyValue = pricelist;
                                            entity.UserProfiles.AddObject(userprofile);
                                        }
                                        // entity.SaveChanges();

                                    }

                                }

                            }
                            else if (xml.Name.Equals("shippingAddress"))
                                insideShippingAddress = false;
                            else if (xml.Name.Equals("paymentType"))
                                insidePyamentType = false;
                            else if (xml.Name.Equals("extensions"))
                                insideExtensions = false;
                            else if (xml.Name.Equals("users"))
                                insideUsers = false;

                            break;

                    }
                }
                return true;
            }
            catch (XmlException exception)
            {
                Console.WriteLine(exception.Message);

                return false;
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Users EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToUsers(User user)
 {
     base.AddObject("Users", user);
 }