public NormalResult UpdateCoupon(Coupon_Info coupon) { //coupon.modify_date_time = DateTime.Now; using (Entities db = new Entities()) { if (db.Coupon_Info.Any(s => s.name == coupon.name && s.id != coupon.id)) { return(new NormalResult("优惠券名称重复,已被其他优惠券占用。")); } IQueryable <Coupon_Info> queryable = db.Coupon_Info; Coupon_Info dbCoupon_Info = queryable.FirstOrDefault(e => e.id == coupon.id); if (dbCoupon_Info == null) { return(new NormalResult("指定的数据不存在。")); } ShengMapper.SetValuesSkipVirtual(coupon, dbCoupon_Info); 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 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 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 UpdatePointExchange(Point_Exchange pointExchange) { using (Entities db = new Entities()) { IQueryable <Point_Exchange> queryable = db.Point_Exchange; Point_Exchange dbPointExchange = queryable.FirstOrDefault(e => e.id == pointExchange.id); if (dbPointExchange == null) { return(new NormalResult("指定的数据不存在。")); } ShengMapper.SetValuesSkipVirtual(pointExchange, dbPointExchange); db.SaveChanges(); } return(new NormalResult()); }
public NormalResult UpdateProductAttribute(Product_Attribute productAttribute) { using (Entities db = new Entities()) { IQueryable <Product_Attribute> queryable = db.Product_Attribute; Product_Attribute dbProduct_Attribute = queryable.FirstOrDefault(e => e.id == productAttribute.id); if (dbProduct_Attribute == null) { return(new NormalResult("指定的数据不存在。")); } ShengMapper.SetValuesSkipVirtual(productAttribute, dbProduct_Attribute); 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()); }
public void SetValuesTest() { 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(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < 100000; i++) { //全部属性拷贝 ShengMapper.SetValues(a, b); //拷贝指定的属性 // ShengMapper.SetValuesWithProperties(a, b, new string[] { "Name", "Age", "P1" }); //排除指定的属性 //ShengMapper.SetValuesWithoutProperties(a, b, new string[] { "Name", "Age", "P1" }); } stopwatch.Stop(); Console.WriteLine("对包含 10 个属性的对象的属性值拷贝 10 万次,耗时:" + stopwatch.Elapsed.ToString()); Console.ReadLine(); }
public NormalResult UpdateMicroClassInfo(Micro_Class_Info microClassInfo) { microClassInfo.update_time = DateTime.Now; using (Entities db = new Entities()) { IQueryable <Micro_Class_Info> queryable = db.Micro_Class_Info; Micro_Class_Info dbMicro_Class_Info = queryable.FirstOrDefault(e => e.id == microClassInfo.id); if (dbMicro_Class_Info == null) { return(new NormalResult("指定的数据不存在。")); } ShengMapper.SetValuesSkipVirtual(microClassInfo, dbMicro_Class_Info); db.SaveChanges(); } return(new NormalResult()); }
public NormalResult UpdateRole(Role role, List <string> roleAuthorization) { if (role == null) { return(new NormalResult("参数错误。")); } using (Entities db = new Entities()) { if (db.Role.Any(s => s.name == role.name && s.id != role.id)) { return(new NormalResult("指定的角色名称重复,已被其它角色占用。")); } Role dbRole = db.Role.FirstOrDefault(s => s.id == role.id); if (dbRole == null) { return(new NormalResult("指定的数据不存在。")); } ShengMapper.SetValuesSkipVirtual(role, dbRole); dbRole.RoleAuthorization.Clear(); foreach (var item in roleAuthorization) { dbRole.RoleAuthorization.Add(new RoleAuthorization() { roleId = dbRole.id, authorizationKey = item }); } db.SaveChanges(); } return(new NormalResult()); }
public NormalResult UpdateProductQRCode(Product_Anti_Fake product) { using (Entities db = new Entities()) { if (db.Product_Anti_Fake.Any(s => s.product_code == product.product_code && s.id != product.id)) { return(new NormalResult("商品编码重复,已被其他商品占用。")); } IQueryable <Product_Anti_Fake> queryable = db.Product_Anti_Fake; Product_Anti_Fake dbProduct_Anti_Fake = queryable.FirstOrDefault(e => e.id == product.id); if (dbProduct_Anti_Fake == null) { return(new NormalResult("指定的数据不存在。")); } ShengMapper.SetValuesSkipVirtual(product, dbProduct_Anti_Fake); db.SaveChanges(); } return(new NormalResult()); }