public OPResult AddOrUpdate(OrganizationGoodReturnRatePerQuarter entity) { if (RateIsExist(entity)) { return(new OPResult { IsSucceed = false, Message = "该机构已经设置了该品牌年份季度的退货率." }); } var id = entity.ID; try { if (id == default(int)) { entity.ID = LinqOP.Add <OrganizationGoodReturnRatePerQuarter, int>(entity, o => o.ID); } else { LinqOP.Update <OrganizationGoodReturnRatePerQuarter>(entity); } } catch (Exception e) { entity.ID = id; return(new OPResult { IsSucceed = false, Message = "保存失败,失败原因:\n" + e.Message }); } return(new OPResult { IsSucceed = true, Message = "保存成功." }); }
private OPResult Update(SysOrganizationBO organization) { var brandIDs = CurrentOrganization.Brands.Select(o => o.ID); List <OrganizationBrand> obs = new List <OrganizationBrand>(); foreach (var b in organization.Brands) { OrganizationBrand ob = new OrganizationBrand { OrganizationID = organization.ID, BrandID = b.ID, CreatorID = VMGlobal.CurrentUser.ID, CreateTime = DateTime.Now }; obs.Add(ob); } OPResult result = null; using (TransactionScope scope = new TransactionScope()) { try { LinqOP.Update <SysOrganization>(organization); VMGlobal.SysProcessQuery.LinqOP.Delete <OrganizationBrand>(ob => brandIDs.Contains(ob.BrandID) && ob.OrganizationID == organization.ID); VMGlobal.SysProcessQuery.LinqOP.Add <OrganizationBrand>(obs); scope.Complete(); result = new OPResult { IsSucceed = true, Message = "更新成功!" }; } catch (Exception e) { result = new OPResult { IsSucceed = false, Message = "更新失败,失败原因:\n" + e.Message }; } } if (result.IsSucceed) { int index = VMGlobal.ChildOrganizations.FindIndex(o => o.ID == organization.ID); if (organization.Flag) { if (index == -1) { VMGlobal.ChildOrganizations.Add(organization); } else { VMGlobal.ChildOrganizations[index] = organization; } } else if (index != -1) { VMGlobal.ChildOrganizations.RemoveAt(index); } _currentAndChildrenOrganizations = null; } return(result); }
private OPResult Update(SysUserBO user) { var roleIDs = RolesCurrentUserCover.Select(rs => rs.ID);//加上ToList()在下面执行时就抛出Contains不支持的异常,坑爹 List <SysUserRole> urs = new List <SysUserRole>(); foreach (var rs in user.Roles) { SysUserRole ur = new SysUserRole { UserId = user.ID, RoleId = rs.ID, CreatorID = VMGlobal.CurrentUser.ID }; urs.Add(ur); } var brandIDs = VMGlobal.PoweredBrands.Select(bs => bs.ID); List <UserBrand> ubs = new List <UserBrand>(); foreach (var bs in user.Brands) { UserBrand ub = new UserBrand { UserID = user.ID, BrandID = bs.ID, CreatorID = VMGlobal.CurrentUser.ID }; ubs.Add(ub); } using (TransactionScope scope = new TransactionScope()) { try { LinqOP.Update <SysUser>(user); LinqOP.Delete <SysUserRole>(ur => roleIDs.Contains(ur.RoleId) && ur.UserId == user.ID); VMGlobal.SysProcessQuery.LinqOP.Delete <UserBrand>(ub => brandIDs.Contains(ub.BrandID) && ub.UserID == user.ID); LinqOP.Add <SysUserRole>(urs); VMGlobal.SysProcessQuery.LinqOP.Add <UserBrand>(ubs); scope.Complete(); return(new OPResult { IsSucceed = true, Message = "更新成功." }); } catch (Exception e) { return(new OPResult { IsSucceed = false, Message = "更新失败,失败原因:\n" + e.Message }); } } }
public OPResult Audit(VoucherReceiveMoney entity) { if (entity.ID == default(int)) { return(new OPResult { IsSucceed = false, Message = "请先保存单据." }); } if (entity.Status) { return(new OPResult { IsSucceed = false, Message = "该收款单已审核." }); } entity.Status = true; entity.CheckerID = VMGlobal.CurrentUser.ID; entity.CheckTime = DateTime.Now; using (TransactionScope scope = new TransactionScope()) { try { LinqOP.Update <VoucherReceiveMoney>(entity); LinqOP.Add <OrganizationFundAccount>( new OrganizationFundAccount { BrandID = entity.BrandID, OrganizationID = entity.OrganizationID, NeedIn = 0.0M, AlreadyIn = entity.ReceiveMoney, CreatorID = entity.CreatorID, BillKind = (int)BillTypeEnum.VoucherReceiveMoney, Remark = "收款单生成", RefrenceBillCode = entity.Code }); scope.Complete(); return(new OPResult { IsSucceed = true, Message = "审核成功." }); } catch (Exception e) { entity.Status = false; return(new OPResult { IsSucceed = false, Message = "审核失败,失败原因:\n" + e.Message }); } } }
private OPResult Update(SysRoleBO role) { List <SysRoleModule> rms = new List <SysRoleModule>(); foreach (var m in role.Modules) { SysRoleModule rm = new SysRoleModule { RoleId = role.ID, ModuleId = m.ID }; rms.Add(rm); } //该角色被删除的菜单权限,拥有该角色的用户的所有下级用户的相应菜单权限也要一起删除,若同样权限是其它角色赋予则不删除 //var oldrms = _query.LinqOP.Search<SysRoleModule>(rm => rm.RoleId == role.ID).ToList(); //oldrms.Except(rms);//原列表中有新列表中没有的权限映射(待级联删除的) using (TransactionScope scope = new TransactionScope()) { try { LinqOP.Update <SysRole>(role); LinqOP.Delete <SysRoleModule>(rm => rm.RoleId == role.ID); LinqOP.Add <SysRoleModule>(rms); VMGlobal.SysProcessQuery.DB.ExecuteNonQuery("CleanUpDirtyProcess", role.ID); scope.Complete(); } catch (Exception e) { return(new OPResult { IsSucceed = false, Message = "更新失败,失败原因:\n" + e.Message }); } } if (_rolesOfCurrentOrgnization != null) { var roleUpdate = _rolesOfCurrentOrgnization.FirstOrDefault(r => r.ID == role.ID); if (roleUpdate != null) { int index = _rolesOfCurrentOrgnization.IndexOf(roleUpdate); _rolesOfCurrentOrgnization[index] = role; //roleUpdate = role; } } return(new OPResult { IsSucceed = true, Message = "更新成功." }); }
public OPResult Unfreeze(VoucherReceiveMoney entity) { if (!entity.IsMoneyFrozen) { return(new OPResult { IsSucceed = false, Message = "该收款单资金已解冻." }); } entity.IsMoneyFrozen = false; try { LinqOP.Update <VoucherReceiveMoney>(entity); return(new OPResult { IsSucceed = true, Message = "资金解冻成功." }); } catch (Exception e) { entity.Status = false; return(new OPResult { IsSucceed = false, Message = "资金解冻失败,失败原因:\n" + e.Message }); } }
private OPResult Update(ProStyleBO style) { SetStyleBYQ(style); ProStyle orginStyle = LinqOP.GetById <ProStyle>(style.ID); List <Product> productsExist = LinqOP.Search <Product>(p => p.StyleID == style.ID).ToList(); List <Product> products = new List <Product>(); foreach (var color in style.Colors) { foreach (var size in style.Sizes) { var pcode = style.Code + color.Code + size.Code; Product product = productsExist.FirstOrDefault(p => p.ColorID == color.ID && p.SizeID == size.ID); if (product != null) { if (orginStyle.Code != style.Code) { product.Code = pcode; products.Add(product); } } else { product = new Product { Code = pcode, StyleID = style.ID, ColorID = color.ID, SizeID = size.ID, CreatorID = VMGlobal.CurrentUser.ID }; products.Add(product); } } } string changeMsg = ""; if (orginStyle.Price != style.Price) { changeMsg += string.Format("单价从{0}变动为{1},", orginStyle.Price, style.Price); } if (orginStyle.Code != style.Code) { changeMsg += string.Format("款号从{0}变动为{1},", orginStyle.Code, style.Code); } if (products.Count > 0) { changeMsg += "增加了SKU码:"; products.ForEach(o => { changeMsg += (o.Code + ","); }); } changeMsg = changeMsg.TrimEnd(','); OPResult result = null; using (TransactionScope scope = new TransactionScope()) { try { LinqOP.Update <ProStyle>(style); LinqOP.AddOrUpdate <Product>(products); if (!string.IsNullOrEmpty(changeMsg)) { ProStyleChange change = new ProStyleChange { CreateTime = DateTime.Now, CreatorID = VMGlobal.CurrentUser.ID, Description = changeMsg, StyleID = style.ID }; LinqOP.Add <ProStyleChange>(change); style.Changes.Insert(0, change); } result = new OPResult { IsSucceed = true, Message = "更新成功!" }; scope.Complete(); } catch (Exception e) { result = new OPResult { IsSucceed = false, Message = "更新失败,失败原因:\n" + e.Message }; } } if (result.IsSucceed && !string.IsNullOrEmpty(changeMsg)) { IMHelper.AsyncSendMessageTo(IMHelper.OnlineUsers, new IMessage { Message = changeMsg }, IMReceiveAccessEnum.成品资料变动); } return(result); }