public bool Add() { if (this.Valid()) { this.AddDate = DateTime.Now; using (WMContext context = new WMContext()) { UserSets model = ( from us in context.UserSets where us.TypeId == this.TypeId && us.UserId.Equals(this.UserId) && us.GoodId.Equals(this.GoodId) select us ).FirstOrDefault(); if (model != null) { model.AddDate = this.AddDate; } else { model = new UserSets { Id = General.UniqueString(this.Id), TypeId = this.TypeId, UserId = this.UserId, GoodId = this.GoodId, AddDate = this.AddDate }; context.UserSets.Add(model); if (this.TypeId == 401) { //商品的被收藏数量获得递增 Goods good = context.Goods.Find(this.GoodId); if (good != null) { good.Saves++; } } } context.SaveChanges(); } return(true); } return(false); }
public static bool Delete(string id) { if (!General.IsNullable(id)) { using (WMContext context = new WMContext()) { UserSets model = context.UserSets.Find(id); if (model != null) { context.UserSets.Remove(model); context.SaveChanges(); return(true); } } } return(false); }
public bool Add() { if (this.Valid()) { this.AddDate = DateTime.Now; using (WMContext context = new WMContext()) { UserSets model = ( from us in context.UserSets where us.TypeId == this.TypeId && us.UserId.Equals(this.UserId) && us.GoodId.Equals(this.GoodId) select us ).FirstOrDefault(); if (model != null) model.AddDate = this.AddDate; else { model = new UserSets { Id = General.UniqueString(this.Id), TypeId = this.TypeId, UserId = this.UserId, GoodId = this.GoodId, AddDate = this.AddDate }; context.UserSets.Add(model); if (this.TypeId == 401) { //商品的被收藏数量获得递增 Goods good = context.Goods.Find(this.GoodId); if (good != null) good.Saves++; } } context.SaveChanges(); } return true; } return false; }