示例#1
0
 /// <summary>
 /// 用于向 ItemTables EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToItemTables(ItemTable itemTable)
 {
     base.AddObject("ItemTables", itemTable);
 }
 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>
 /// 创建新的 ItemTable 对象。
 /// </summary>
 /// <param name="id">Id 属性的初始值。</param>
 /// <param name="name">Name 属性的初始值。</param>
 /// <param name="userId">UserId 属性的初始值。</param>
 /// <param name="categoryId">CategoryId 属性的初始值。</param>
 /// <param name="amount">Amount 属性的初始值。</param>
 /// <param name="image">Image 属性的初始值。</param>
 /// <param name="time">Time 属性的初始值。</param>
 /// <param name="describe">Describe 属性的初始值。</param>
 public static ItemTable CreateItemTable(global::System.Int32 id, global::System.String name, global::System.Int32 userId, global::System.Int32 categoryId, global::System.Int32 amount, global::System.Byte[] image, global::System.String time, global::System.String describe)
 {
     ItemTable itemTable = new ItemTable();
     itemTable.Id = id;
     itemTable.Name = name;
     itemTable.UserId = userId;
     itemTable.CategoryId = categoryId;
     itemTable.Amount = amount;
     itemTable.Image = image;
     itemTable.Time = time;
     itemTable.Describe = describe;
     return itemTable;
 }