/// <summary>
 /// 用于向 MerChantTables EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToMerChantTables(MerChantTable merChantTable)
 {
     base.AddObject("MerChantTables", merChantTable);
 }
       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>
 /// 创建新的 MerChantTable 对象。
 /// </summary>
 /// <param name="id">Id 属性的初始值。</param>
 /// <param name="userName">UserName 属性的初始值。</param>
 /// <param name="passWord">PassWord 属性的初始值。</param>
 /// <param name="phone">Phone 属性的初始值。</param>
 /// <param name="longitude">Longitude 属性的初始值。</param>
 /// <param name="latitude">Latitude 属性的初始值。</param>
 /// <param name="address">Address 属性的初始值。</param>
 /// <param name="storeName">StoreName 属性的初始值。</param>
 /// <param name="avatar">Avatar 属性的初始值。</param>
 public static MerChantTable CreateMerChantTable(global::System.Int32 id, global::System.String userName, global::System.String passWord, global::System.String phone, global::System.Decimal longitude, global::System.Decimal latitude, global::System.String address, global::System.String storeName, global::System.Byte[] avatar)
 {
     MerChantTable merChantTable = new MerChantTable();
     merChantTable.Id = id;
     merChantTable.UserName = userName;
     merChantTable.PassWord = passWord;
     merChantTable.Phone = phone;
     merChantTable.Longitude = longitude;
     merChantTable.Latitude = latitude;
     merChantTable.Address = address;
     merChantTable.StoreName = storeName;
     merChantTable.Avatar = avatar;
     return merChantTable;
 }