//0修改失败,-1修改重复 public int UpdateProgram(DiscountProgram Program) { int flag = 0; using (ChooseDishesEntities entities = new ChooseDishesEntities()) { //查询折扣方案是否存在 var type = entities.DiscountProgram.SingleOrDefault(bt => bt.DiscountId == Program.DiscountId && bt.Deleted == 0); if (type != null) { //设置属性是否参与修改 ,设置为false则无法更新数据 type.Code = Program.Code; type.Name = Program.Name; type.ByDish = Program.ByDish; type.Rate = Program.Rate; type.UpdateDatetime = Program.UpdateDatetime; type.UpdateBy = Program.UpdateBy; try { //关闭实体验证,不关闭验证需要整个对象全部传值 entities.Configuration.ValidateOnSaveEnabled = false; //操作数据库 flag = entities.SaveChanges(); entities.Configuration.ValidateOnSaveEnabled = true; } catch (Exception ex) { ex.ToString(); } } } return(flag); }
public DiscountProgramBean CreateDiscountProgramBean(DiscountProgram bean) { this.DiscountId = bean.DiscountId; this.Code = bean.Code; this.Name = bean.Name; this.ByDish = bean.ByDish; this.Rate = bean.Rate; this.CreateDatetime = bean.CreateDatetime; this.CreateBy = bean.CreateBy; this.Deleted = bean.Deleted; this.Status = bean.Status; this.UpdateDatetime = bean.UpdateDatetime; this.UpdateBy = bean.UpdateBy; return(this); }
public DiscountProgram CreateDiscountProgram(DiscountProgramBean bean) { DiscountProgram beanBack = new DiscountProgram(); beanBack.DiscountId = bean.DiscountId; beanBack.Code = bean.Code; beanBack.Name = bean.Name; beanBack.ByDish = bean.ByDish; beanBack.Rate = bean.Rate; beanBack.CreateDatetime = bean.CreateDatetime; beanBack.CreateBy = bean.CreateBy; beanBack.Deleted = bean.Deleted; beanBack.Status = bean.Status; beanBack.UpdateDatetime = bean.UpdateDatetime; beanBack.UpdateBy = bean.UpdateBy; return(beanBack); }
public void UserWithSufficientAccount_GotCharged_AccountAndDiscountCardAmountsAlter( DiscountProgram discountProgram, Money price, Account accountBeforeCharge, Account accountAfterCharge, DiscountCard discountCardBeforeCharge, DiscountCard discountCardAfterCharge) { // Arrange var sut = new User(discountCardBeforeCharge, accountBeforeCharge); // Act sut.Charge(price, discountProgram); // Assert sut.DiscountCard.Should().NotBeNull().And.BeEquivalentTo(discountCardAfterCharge); sut.Account.Should().NotBeNull().And.BeEquivalentTo(accountAfterCharge); }
private void SaveDiscounts_OnClick(object sender, RoutedEventArgs e) { using (var entities = new RPPBAContext()) { foreach (var discountProgramModel in removingDiscountPrograms) { if (discountProgramModel.Id != 0) { entities.DiscountPrograms.Remove( entities.DiscountPrograms.First(x => x.DiscountId == discountProgramModel.Id)); } } foreach (var discountProgramModel in _discountPrograms) { if (discountProgramModel.Id != 0) { var discountProgram = entities.DiscountPrograms.FirstOrDefault(x => x.DiscountId == discountProgramModel.Id); discountProgram.Discount = discountProgramModel.Discount; discountProgram.EndSum = discountProgramModel.End; discountProgram.StartSum = discountProgramModel.Begin; entities.SaveChanges(); } else { var discountProgram = new DiscountProgram() { Discount = discountProgramModel.Discount, EndSum = discountProgramModel.End, StartSum = discountProgramModel.Begin }; entities.Add(discountProgram); entities.SaveChanges(); } } entities.SaveChanges(); AddDiscount.Visibility = Visibility.Hidden; DiscountProgramsEditable.Visibility = Visibility.Hidden; LoadData(); } }
//添加折扣方案 0 添加失败 public int AddProgram(DiscountProgram Program) { int flag = 0; using (ChooseDishesEntities entities = new ChooseDishesEntities()) { //实体绑定MODEL entities.DiscountProgram.Add(Program); try { //操作数据库 entities.SaveChanges(); flag = Program.DiscountId; } catch (Exception ex) { ex.ToString(); } } return(flag); }