/// <summary>
 /// 创建新的 CityTable 对象。
 /// </summary>
 /// <param name="id">Id 属性的初始值。</param>
 /// <param name="name">Name 属性的初始值。</param>
 /// <param name="point">Point 属性的初始值。</param>
 /// <param name="lastRank">LastRank 属性的初始值。</param>
 public static CityTable CreateCityTable(global::System.Int32 id, global::System.String name, global::System.Int32 point, global::System.Int32 lastRank)
 {
     CityTable cityTable = new CityTable();
     cityTable.Id = id;
     cityTable.Name = name;
     cityTable.Point = point;
     cityTable.LastRank = lastRank;
     return cityTable;
 }
       public string  Register(RegisterUser user)
        {
            Console.WriteLine(user.UserName + "Register");
            if (user.UserType == 0)
            {
                UserTable userTable = new UserTable()
                {
                    UserName = user.UserName,
                    Address = user.Address,
                    City = getCity(user.Address),
                    Latitude = user.Latitude,
                    Longitude = user.Longitude,
                    Password = user.Passwrod,
                    Point = 10,
                    Avatar = user.ImageFileData,
                    LastRank = 200,
                    CityLastRank=100,
                    NowRank=200,
                    NowCityRank=100,
                    UserRank=100,
                    CityRank=100
                };
                db.UserTables.AddObject(userTable);
                db.SaveChanges();
                UserTable userTable1 = db.UserTables.SingleOrDefault(c => c.UserName == userTable.UserName && c.Password == userTable.Password);
                foreach (UserTable item in db.UserTables.Where(c=>c.City==userTable1.City))
                {
                    FriendTable Friend = new FriendTable()
                    {
                        UserId = userTable1.Id,
                        FriendId=item.Id
                    };
                    if (Friend.UserId != Friend.FriendId)
                    {
                        db.FriendTables.AddObject(Friend);
                      //  db.SaveChanges();
                    }
                    FriendTable Friend1 = new FriendTable()
                    {
                        UserId = item.Id,
                        FriendId = userTable1.Id
                    };
                    if (Friend1.UserId != Friend1.FriendId)
                    {
                        db.FriendTables.AddObject(Friend1);
                      //  db.SaveChanges();
                    }
                }
            }
            if (user.UserType == 1)
            {
                AcquirerTable acquirer = new AcquirerTable()
                {
                    UserName = user.UserName,
                    Address = user.Address,
                    City = getCity(user.Address),
                    Latitude = user.Latitude,
                    Longitude = user. Longitude,
                    PassWord = user.Passwrod,
                    Phone=user.Phone,
                    BinName=user.StoreBinName,
                    Avatar = user.ImageFileData,
                };
                db.AcquirerTables.AddObject(acquirer);
            }
            if (user.UserType == 2)
            {
                MerChantTable merchant = new MerChantTable()
                {
                    UserName = user.UserName,
                    Address = user.Address,
                    Latitude = user.Latitude,
                    Longitude = user.Longitude,
                    PassWord = user.Passwrod,
                    Phone = user.Phone,
                    StoreName = user.StoreBinName,
                    Avatar = user.ImageFileData,
                };
                db.MerChantTables.AddObject(merchant);
            }
            if (!db.CityTables.Select(c => c.Name).Contains(getCity(user.Address)))
                {
                    CityTable city = new CityTable()
                    {
                        Name = user.City,
                        LastRank = 100,
                        Point = 10
                    };
                    db.CityTables.AddObject(city);
                }
               
                db.SaveChanges();

            return "Register Success";
        }
 /// <summary>
 /// 用于向 CityTables EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToCityTables(CityTable cityTable)
 {
     base.AddObject("CityTables", cityTable);
 }