public async Task <IActionResult> GetContractInvoiceView(long contractInvoiceId)
        {
            ContractInvoiceModule invMod = new ContractInvoiceModule();

            ContractInvoiceView view = await invMod.ContractInvoice.Query().GetViewById(contractInvoiceId);

            return(Ok(view));
        }
        public async Task <IActionResult> DeleteContractInvoice([FromBody] ContractInvoiceView view)
        {
            ContractInvoiceModule invMod          = new ContractInvoiceModule();
            ContractInvoice       contractInvoice = await invMod.ContractInvoice.Query().MapToEntity(view);

            invMod.ContractInvoice.DeleteContractInvoice(contractInvoice).Apply();

            return(Ok(view));
        }
        public async Task <IActionResult> UpdateContractInvoice([FromBody] ContractInvoiceView view)
        {
            ContractInvoiceModule invMod = new ContractInvoiceModule();

            ContractInvoice contractInvoice = await invMod.ContractInvoice.Query().MapToEntity(view);


            invMod.ContractInvoice.UpdateContractInvoice(contractInvoice).Apply();

            ContractInvoiceView retView = await invMod.ContractInvoice.Query().GetViewById(contractInvoice.ContractInvoiceId);


            return(Ok(retView));
        }
        public async Task <IActionResult> AddContractInvoice([FromBody] ContractInvoiceView view)
        {
            ContractInvoiceModule invMod = new ContractInvoiceModule();

            NextNumber nnContractInvoice = await invMod.ContractInvoice.Query().GetNextNumber();

            view.ContractInvoiceNumber = nnContractInvoice.NextNumberValue;

            ContractInvoice contractInvoice = await invMod.ContractInvoice.Query().MapToEntity(view);

            invMod.ContractInvoice.AddContractInvoice(contractInvoice).Apply();

            ContractInvoiceView newView = await invMod.ContractInvoice.Query().GetViewByNumber(view.ContractInvoiceNumber);


            return(Ok(newView));
        }
Example #5
0
        public async Task TestObserver()
        {
            InvoiceModule         invMod             = new InvoiceModule();
            ContractInvoiceModule contractInvoiceMod = new ContractInvoiceModule();

            Customer customer = await invMod.Customer.Query().GetEntityById(9);

            AddressBook addressBookCustomer = await invMod.AddressBook.Query().GetEntityById(customer?.AddressId);

            NextNumber nextNumber = await invMod.Invoice.Query().GetNextNumber();

            TaxRatesByCode taxRatesByCode = await invMod.TaxRatesByCode.Query().GetEntityById(1);

            InvoiceView invoiceView = new InvoiceView();

            invoiceView.InvoiceDocument  = "Inv-99";
            invoiceView.InvoiceDate      = DateTime.Parse("8/10/2018");
            invoiceView.Amount           = 1500.0M;
            invoiceView.CustomerId       = customer?.CustomerId;
            invoiceView.CustomerName     = addressBookCustomer?.Name;
            invoiceView.Description      = "VNW Fixed Asset project";
            invoiceView.PaymentTerms     = "Net 30";
            invoiceView.TaxAmount        = 0;
            invoiceView.CompanyId        = 1;
            invoiceView.TaxRatesByCodeId = taxRatesByCode.TaxRatesByCodeId;

            invoiceView.InvoiceNumber = nextNumber.NextNumberValue;

            Invoice newInvoice = await invMod.Invoice.Query().MapToEntity(invoiceView);

            Observer mediator = new Observer();

            mediator.SubscribeToObserver(invMod, invMod.MessageFromObserver);
            mediator.SubscribeToObserver(contractInvoiceMod, contractInvoiceMod.MessageFromObserver);


            IObservableAction observedAction = new ObservableAction();

            MessageAction action = new MessageAction {
                targetByName = nameof(Invoice), command_action = TypeOfObservableAction.InsertData, Invoice = newInvoice
            };

            observedAction.Actions.Add(action);

            NextNumber nextNumberContractInvoice = await invMod.ContractInvoice.Query().GetNextNumber();

            ContractInvoiceView contractInvoiceView = new ContractInvoiceView
            {
                InvoiceId             = 5,
                ContractId            = 1,
                ContractInvoiceNumber = nextNumberContractInvoice.NextNumberValue
            };

            ContractInvoice contractInvoice = await invMod.ContractInvoice.Query().MapToEntity(contractInvoiceView);

            MessageAction actionContractInvoice = new MessageAction {
                targetByName = nameof(ContractInvoice), command_action = TypeOfObservableAction.InsertData, ContractInvoice = contractInvoice
            };

            observedAction.Actions.Add(actionContractInvoice);

            mediator.TransmitMessage(observedAction);

            if (observedAction.Actions.Count() > 0)
            {
                Assert.True(false);
            }

            Invoice lookupInvoice = await invMod.Invoice.Query().GetEntityByNumber(invoiceView.InvoiceNumber);

            lookupInvoice.Amount = 9999;

            ContractInvoice lookupContractInvoice = await contractInvoiceMod.ContractInvoice.Query().GetEntityByNumber(contractInvoiceView.ContractInvoiceNumber);


            //*******Contract Invoice


            MessageAction actionInvoiceUpdate = new MessageAction
            {
                targetByName   = nameof(Invoice),
                command_action = TypeOfObservableAction.UpdateData,
                Invoice        = lookupInvoice
            };

            observedAction.Actions.Add(actionInvoiceUpdate);

            MessageAction actionInvoiceDelete = new MessageAction
            {
                targetByName   = nameof(Invoice),
                command_action = TypeOfObservableAction.DeleteData,
                Invoice        = lookupInvoice
            };

            observedAction.Actions.Add(actionInvoiceDelete);

            MessageAction actionContractInvoiceDelete = new MessageAction
            {
                targetByName    = nameof(ContractInvoice),
                command_action  = TypeOfObservableAction.DeleteData,
                ContractInvoice = lookupContractInvoice
            };

            observedAction.Actions.Add(actionContractInvoiceDelete);

            mediator.TransmitMessage(observedAction);

            if (observedAction.Actions.Count() > 0)
            {
                Assert.True(false);
            }

            await Task.Yield();

            Assert.True(true);
        }