public bool Update(IConnectionHandler connectionHandler, DiscountType discountType, List <DiscountTypeAutoCode> discountTypeAutoCodes) { var discountTypeAutoCodeBo = new DiscountTypeAutoCodeBO(); var typeAutoCodes = discountTypeAutoCodeBo.Where(connectionHandler, x => x.DiscountTypeId == discountType.Id); if (discountTypeAutoCodes == null || !discountType.IsAutoCode) { foreach (var discountTypeAutoCode in typeAutoCodes) { if (!discountTypeAutoCodeBo.Delete(connectionHandler, discountTypeAutoCode.Id)) { throw new Exception(Resources.Payment.ErrorInSaveDiscountCode); } } } else { foreach (var autoCode in discountTypeAutoCodes) { if (typeAutoCodes.All(x => x.Id != autoCode.Id)) { if (!discountTypeAutoCodeBo.Insert(connectionHandler, autoCode)) { throw new Exception(Resources.Payment.ErrorInSaveDiscountCode); } } } discountType.Code = string.Empty; discountType.Capacity = null; discountType.RemainCapacity = null; } if (!base.Update(connectionHandler, discountType)) { throw new Exception(Resources.Payment.ErrorInInsertDiscount); } return(true); }