/// <summary> /// 删除用户销售规则 /// </summary> /// <param name="userId"></param> public void RemoveSaleRuleByUserId(int userId) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { UserSaleRule saleRule = entities.UserSaleRule.Where(t => t.UserId == userId && t.Deleted == 0).Single(); if (null == saleRule) { return; } int authId = SubjectUtils.GetAuthenticationId(); DateTime now = DateTime.Now; saleRule.Deleted = 1; saleRule.UpdateBy = authId; entities.SaveChanges(); } }
public void SaveOnUpdateForUserSaleRule(int userId, UserSaleRule saleRule) { if (null == saleRule) { throw new ServiceException("参数【saleRule】不能为空!"); } using (ChooseDishesEntities entities = new ChooseDishesEntities()) { try { UserSaleRule savedSaleRule = entities.UserSaleRule.Where(t => t.Deleted == 0 && t.UserId == userId).SingleOrDefault(); //不存在销售规则,则抛出异常 if (savedSaleRule == null) { savedSaleRule = new UserSaleRule(); try { savedSaleRule.CreateBy = SubjectUtils.GetAuthenticationId(); savedSaleRule.CreateDatetime = DateTime.Now; saleRule.UserId = userId; saleRule.CreateBy = SubjectUtils.GetAuthenticationId(); saleRule.CreateDatetime = DateTime.Now; entities.UserSaleRule.Add(saleRule); entities.SaveChanges(); } catch (DbUpdateException e) { e.ToString(); } } else { // savedSaleRule.DiscountAllowanceLimit = saleRule.DiscountAllowanceLimit; savedSaleRule.DiscountLimit = saleRule.DiscountLimit; savedSaleRule.AlowanceType = saleRule.AlowanceType; savedSaleRule.AllowanceLimit = saleRule.AllowanceLimit; savedSaleRule.PresentType = saleRule.PresentType; savedSaleRule.PresentLimit = saleRule.PresentLimit; savedSaleRule.UpdateDatetime = DateTime.Now; savedSaleRule.UpdateBy = SubjectUtils.GetAuthenticationId(); entities.SaveChanges(); } } catch (DbEntityValidationException e) { e.ToString(); } } }