示例#1
0
 /// <summary>
 /// 用于向 PhotoTrendTables EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToPhotoTrendTables(PhotoTrendTable photoTrendTable)
 {
     base.AddObject("PhotoTrendTables", photoTrendTable);
 }
 public string Post(PostItem postItem)
 {
    UserTable user= db.UserTables.SingleOrDefault(c=>c.Id==postItem.UserId);
    Console.WriteLine(user.UserName + "Post" + postItem.Name);
    user.Point += postItem.GetPoints;
     ItemTable item = new ItemTable()
     {
         Amount=postItem.Amount,
         CategoryId=postItem.CategoryId,
         Describe=postItem.Describe,
         Name=postItem.Name,
         UserId=postItem.UserId,      
         Image=postItem.PostImage,
         Time=DateTime.Now.ToShortDateString()
     };
     db.ItemTables.AddObject(item);
     db.SaveChanges();
     Console.WriteLine(user.UserName + "Post" + postItem.Name + "Save To DataBase Success");
     PostAffectTable postAffect = new PostAffectTable()
     {
         UserId=postItem.UserId,
         Time=DateTime.Now.ToShortDateString(),
         PostAffect=postItem.PostAffect,
         Describe="Posts "+postItem.Amount+"  "+postItem.Name,
      };
     db.PostAffectTables.AddObject(postAffect);
     PhotoTrendTable photoTrendTable = new PhotoTrendTable()
     {
         Describe=" posts "+ postItem.Name,
         ItemId=item.Id,
         Time = DateTime.Now.ToShortDateString(),
         UserId=postItem.UserId
     };
     db.PhotoTrendTables.AddObject(photoTrendTable);
     db.SaveChanges();
     int i = 0;
     foreach (UserTable userTable in db.UserTables.ToList().OrderByDescending(c => c.Point))
     {
         i++;
         if (userTable.Id == postItem.UserId)
         {
             user.NowRank = i;
             break;
         }
     }
     i = 0;
     foreach (UserTable userTable in db.UserTables.Where(c=>c.City==user.City).ToList().OrderByDescending(c => c.Point))
     {
         i++;
         if (userTable.Id == postItem.UserId)
         {
             user.NowCityRank = i;
             break;
         }
     }
     dealWithAchievement(user);
     user.UserRank = user.NowRank - user.LastRank;
     user.CityRank = user.NowCityRank - user.CityLastRank;
     user.LastRank = user.NowRank;
     user.CityLastRank = user.NowCityRank;
     db.SaveChanges();
     return postItem.Name+"Unload OK";
 }
示例#3
0
 /// <summary>
 /// 创建新的 PhotoTrendTable 对象。
 /// </summary>
 /// <param name="id">Id 属性的初始值。</param>
 /// <param name="userId">UserId 属性的初始值。</param>
 /// <param name="describe">Describe 属性的初始值。</param>
 /// <param name="time">Time 属性的初始值。</param>
 /// <param name="itemId">ItemId 属性的初始值。</param>
 public static PhotoTrendTable CreatePhotoTrendTable(global::System.Int32 id, global::System.Int32 userId, global::System.String describe, global::System.String time, global::System.Int32 itemId)
 {
     PhotoTrendTable photoTrendTable = new PhotoTrendTable();
     photoTrendTable.Id = id;
     photoTrendTable.UserId = userId;
     photoTrendTable.Describe = describe;
     photoTrendTable.Time = time;
     photoTrendTable.ItemId = itemId;
     return photoTrendTable;
 }