示例#1
0
        public finalproject.User.Users AuthonticateUser(string email, string password)
        {
            try
            {
                if (File.Exists(USER_DATA))
                {
                    string userId      = "";
                    string accountType = "";
                    string firstName   = "";
                    string lastName    = "";
                    string jobType     = "";
                    string phone       = "";
                    string address1    = "";
                    string address2    = "";
                    string city        = "";
                    string province    = "";
                    string zipCode     = "";
                    string education   = "";
                    string phoneNumber = "";

                    XElement doc = XElement.Load(USER_DATA);
                    IEnumerable <XElement> childList =
                        from el in doc.Descendants("user")
                        where (string)el.Element("email") == email &&
                        (string)el.Element("password") == password
                        select el;

                    foreach (XElement e in childList)
                    {
                        userId      = e.Element("userId").Value;
                        accountType = e.Element("accountType").Value;
                        firstName   = e.Element("firstName").Value;
                        lastName    = e.Element("lastName").Value;
                        jobType     = e.Element("jobType").Value;
                        phone       = e.Element("phone").Value;
                        address1    = e.Element("address1").Value;
                        address2    = e.Element("address2").Value;
                        city        = e.Element("city").Value;
                        province    = e.Element("province").Value;
                        zipCode     = e.Element("zipCode").Value;
                        education   = e.Element("education").Value;
                        phoneNumber = e.Element("phone").Value;
                    }
                    logIn.LogIn(userId, accountType, firstName, lastName, email, jobType, phone, address1, address2, city, province, zipCode, education, phoneNumber);
                    return(logIn);
                }
                else
                {
                    throw new System.ArgumentException("Configuration error!", "original");
                }
            }
            catch (Exception ex)
            {
                throw new System.ArgumentException(ex.ToString(), "original");
            }
        }