public NormalResult UpdateUser(User user) { using (Entities db = new Entities()) { if (db.User.Any(s => s.account == user.account && s.id != user.id)) { return(new NormalResult("指定的登录账户重复,已被其它用户占用。")); } IQueryable <User> queryable = db.User; User dbUser = queryable.FirstOrDefault(e => e.id == user.id); if (dbUser == null) { return(new NormalResult("指定的数据不存在。")); } ShengMapper.SetValuesWithoutProperties(user, dbUser, new string[] { "password" }, true); db.SaveChanges(); } return(new NormalResult()); }
public void SetValuesWithoutPropertiesTest() { A a = new A() { Name = "张三", Age = 10, Class = "一班", CObject = new SubC() { Message = "Hello" }, P1 = "1", P2 = "2", P3 = "3", P4 = "4", P5 = "5", P6 = "6" }; B b = new B(); //排除指定的属性 ShengMapper.SetValuesWithoutProperties(a, b, new string[] { "Name", "Age", "P1" }); Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(a)); Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(b)); }
public NormalResult UpdateMember(Member member) { if (member.pic_path == null) { member.pic_path = ""; } using (Entities db = new Entities()) { if (db.Member.Any(s => s.phone_num == member.phone_num && s.id != member.id)) { return(new NormalResult("手机号码重复,已被其他会员占用。")); } IQueryable <Member> queryable = db.Member; Member dbMember = queryable.FirstOrDefault(e => e.id == member.id); if (dbMember == null) { return(new NormalResult("指定的数据不存在。")); } //不更新密码 ShengMapper.SetValuesWithoutProperties(member, dbMember, new string[] { "password", "total_point", "total_amount" }, true); dbMember.update_time = DateTime.Now; db.SaveChanges(); } return(new NormalResult()); }
public NormalResult UpdateProduct(Product_Info product, int [] catalogIdList, int[] attributeIdList) { product.modify_date_time = DateTime.Now; using (Entities db = new Entities()) { if (db.Product_Info.Any(s => s.product_code == product.product_code && s.id != product.id)) { return(new NormalResult("商品编码重复,已被其他商品占用。")); } IQueryable <Product_Info> queryable = db.Product_Info.Include(c => c.Product_Category); Product_Info dbProduct_Info = queryable.FirstOrDefault(e => e.id == product.id); if (dbProduct_Info == null) { return(new NormalResult("指定的数据不存在。")); } ShengMapper.SetValuesWithoutProperties(product, dbProduct_Info, new string[] { "sales_num", "browse_count" }, true); dbProduct_Info.Product_Category.Clear(); if (catalogIdList != null && catalogIdList.Length > 0) { List <Product_Category> dictionaryItemList = db.Product_Category.Where(c => catalogIdList.Contains(c.id)).ToList(); foreach (var item in dictionaryItemList) { dbProduct_Info.Product_Category.Add(item); } } dbProduct_Info.Product_Attribute.Clear(); if (attributeIdList != null && attributeIdList.Length > 0) { List <Product_Attribute> dictionaryItemList = db.Product_Attribute.Where(c => attributeIdList.Contains(c.id)).ToList(); foreach (var item in dictionaryItemList) { dbProduct_Info.Product_Attribute.Add(item); } } dbProduct_Info.modify_date_time = DateTime.Now; db.SaveChanges(); } return(new NormalResult()); }
public NormalResult UpdateProductCatalog(Product_Category productCatalog) { using (Entities db = new Entities()) { IQueryable <Product_Category> queryable = db.Product_Category; Product_Category dbProduct_Category = queryable.FirstOrDefault(e => e.id == productCatalog.id); if (dbProduct_Category == null) { return(new NormalResult("指定的数据不存在。")); } ShengMapper.SetValuesWithoutProperties(productCatalog, dbProduct_Category, new string[] { "sales_num", "browse_count" }, true); db.SaveChanges(); } return(new NormalResult()); }