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); }
public bool CheckDiscoutAndSavetempDiscountType(IConnectionHandler connectionHandler, IConnectionHandler filemanagerconnection, DiscountType discountType, Guid tempId) { var fileTransactionalFacade = FileManagerComponent.Instance.FileTransactionalFacade(filemanagerconnection); var discountType1 = new DiscountTypeBO().Get(connectionHandler, discountType.Id); var added = false; var discount = base.FirstOrDefault(connectionHandler, c => c.TempId == tempId && c.DiscountTypeId == discountType.Id, true); if (discount == null) { discount = new TempDiscount() { TempId = tempId, DiscountTypeId = discountType1.Id, }; } else { added = true; } if (discountType1.ForceAttach) { if (discount.AttachId.HasValue) { fileTransactionalFacade.Update(discountType.UserAttachedFile, (Guid)discount.AttachId); } else { if (discountType.UserAttachedFile == null) { throw new Exception(Resources.Payment.PleaseEnterDiscountAttachFile); } discount.AttachId = fileTransactionalFacade.Insert(discountType.UserAttachedFile); } } if (discountType1.ForceCode) { if (string.IsNullOrEmpty(discountType.UserCode)) { throw new Exception(Resources.Payment.PleaseEnterDiscountCode); } if (discountType1.IsAutoCode) { var firstOrDefault = new DiscountTypeAutoCodeBO().FirstOrDefault(connectionHandler, x => x.DiscountTypeId == discountType1.Id && x.Code == discountType.UserCode); if (firstOrDefault == null) { throw new Exception(Resources.Payment.Discountcodeenteredisnotcorrect); } if (!added) { if (firstOrDefault.Used) { throw new Exception(Resources.Payment.Enterdiscountcodehasalreadybeenused); } firstOrDefault.Used = true; if (!new DiscountTypeAutoCodeBO().Update(connectionHandler, firstOrDefault)) { throw new Exception(Resources.Payment.ErrorInSaveDiscountCode); } } } else { if (discountType1.Code != discountType.UserCode) { throw new Exception(Resources.Payment.Discountcodeenteredisnotcorrect); } if (!added) { if (discountType1.RemainCapacity == 0) { throw new Exception(Resources.Payment.Usingthecapacityfilledrebates); } discountType1.RemainCapacity--; if (!new DiscountTypeBO().Update(connectionHandler, discountType1)) { throw new Exception(Resources.Payment.ErrorInSaveDiscountCode); } } } } if (added) { if (!this.Update(connectionHandler, discount)) { throw new Exception(Resources.Payment.ErrorInSaveTransactionDiscount); } } else { if (!this.Insert(connectionHandler, discount)) { throw new Exception(Resources.Payment.ErrorInSaveTransactionDiscount); } } return(true); }