/// <summary> /// 用于向 PostAffectTables EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddToPostAffectTables(PostAffectTable postAffectTable) { base.AddObject("PostAffectTables", postAffectTable); }
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"; }
/// <summary> /// 创建新的 PostAffectTable 对象。 /// </summary> /// <param name="id">Id 属性的初始值。</param> /// <param name="userId">UserId 属性的初始值。</param> /// <param name="describe">Describe 属性的初始值。</param> /// <param name="time">Time 属性的初始值。</param> /// <param name="postAffect">PostAffect 属性的初始值。</param> public static PostAffectTable CreatePostAffectTable(global::System.Int32 id, global::System.Int32 userId, global::System.String describe, global::System.String time, global::System.String postAffect) { PostAffectTable postAffectTable = new PostAffectTable(); postAffectTable.Id = id; postAffectTable.UserId = userId; postAffectTable.Describe = describe; postAffectTable.Time = time; postAffectTable.PostAffect = postAffect; return postAffectTable; }