示例#1
0
        public override bool Save()
        {
            var valid = new QSValidator <ServiceClaim> (UoWGeneric.Root);

            if (valid.RunDlgIfNotValid((Window)this.Toplevel))
            {
                return(false);
            }

            CounterpartyContract contract = CounterpartyContractRepository.GetCounterpartyContractByPaymentType
                                                (UoWGeneric, UoWGeneric.Root.Counterparty, UoWGeneric.Root.Counterparty.PersonType, UoWGeneric.Root.Payment);

            if (contract == null)
            {
                RunContractCreateDialog();
                return(false);
            }

            UoWGeneric.Session.Refresh(contract);
            if (!contract.RepairAgreementExists())
            {
                RunAgreementCreateDialog(contract);
                return(false);
            }

            if (UoWGeneric.Root.InitialOrder != null)
            {
                UoWGeneric.Root.InitialOrder.AddServiceClaimAsInitial(UoWGeneric.Root);
            }

            if (UoWGeneric.Root.FinalOrder != null)
            {
                UoWGeneric.Root.FinalOrder.AddServiceClaimAsFinal(UoWGeneric.Root);
            }

            if (UoWGeneric.IsNew)
            {
                UoWGeneric.Root.AddHistoryRecord(UoWGeneric.Root.Status,
                                                 String.IsNullOrWhiteSpace(textComment.Buffer.Text) ? "Заявка зарегистрирована" : textComment.Buffer.Text);
            }

            logger.Info("Сохраняем заявку на обслуживание...");
            UoWGeneric.Save();
            logger.Info("Ok");
            return(true);
        }