/// <summary> /// 更新付出类型状态 /// </summary> /// <param></param> /// <returns></returns> public bool ChangePaymentTypeStatus(int ID) { //1:改削有效状态的排序 //2:改削自己记录的排序 //3:改削无效状态的排序 //4:本记录不在有效无效列表记录中计算 try { using (TransactionScope scope = new TransactionScope()) { using (var dbContext = new ConfigDbContext()) { var paymenttype = dbContext.PaymentType.Find(ID);//本笔记录 if (paymenttype != null) { //实时的状态信息,不考虑并发,状态转换 var status = paymenttype.Status == (byte)EnumPaymentTypeStatus.valid ? (byte)EnumPaymentTypeStatus.invalid : (byte)EnumPaymentTypeStatus.valid; var commerid = ConfigManager.GetCurrentLoginInfoCommercialTenantID();//商户id var paymentlist = dbContext.PaymentType.Where(p => p.CommercialTenantID == commerid).ToList();//全部列表 //有效且非自己凭据品级排序 var paymentstatuslist = paymentlist.Where(p => p.Status == (byte)EnumPaymentTypeStatus.valid & p.ID != ID).OrderBy(p => p.Level).ToList(); //有效状态,从1开始从头排序 foreach (var item in paymentstatuslist) { item.Level = (byte)(paymentstatuslist.IndexOf(item) + 1); dbContext.Update(item, false); } dbContext.SaveChanges(); //自己这笔记录的排序,即是除了自己之外的有效状态总数加1 dbContext.PaymentType.Where(p => p.ID == ID).Update(p => new PaymentType() { Status = status, Level = (byte)(paymentstatuslist.Count() + 1) }); //无效状态除本笔记录列表 var paymentinvalidlist = paymentlist.Where(p => p.Status == (byte)EnumPaymentTypeStatus.invalid & p.ID != ID).OrderBy(p => p.Level).ToList(); foreach (var item in paymentinvalidlist) { item.Level = (byte)(paymentinvalidlist.IndexOf(item) + 1 + paymentstatuslist.Count() + 1); dbContext.Update(item, false); } dbContext.SaveChanges(); scope.Complete(); return true; } else { return false; } } } } catch (Exception) { return false; } }
,