Exemplo n.º 1
0
        public InvoiceModel CreateInvoice(NewInvoiceModel invoice, int locationId)
        {
            Data.Graph.Invoice inv = new Data.Graph.Invoice();

            var account = AccountRepository.GetAccount(invoice.AccountId);

            if (account == null)
            {
                account             = new Data.Graph.Account();
                account.Name        = invoice.AccountName;
                account.AccountType = AccountTypeRepository.GetAccountType(invoice.AccountTypeId);
                AccountRepository.SaveAccount(account);
            }

            inv.Account     = account;
            inv.Color       = invoice.Color;
            inv.Location    = new Data.Graph.Location(locationId);
            inv.Make        = invoice.Make;
            inv.Model       = invoice.Model;
            inv.ReceiveDate = DateTime.Now;
            inv.StockNumber = invoice.StockNumber;
            inv.Year        = invoice.Year;
            inv.TaxRate     = (decimal)account.AccountType.TaxRate;

            InvoiceRepository.SaveInvoice(inv);
            Logger.InfoFormat("Created new invoice {0} for {1} at location id {2}", inv.Id, inv.Account.Name, locationId);

            return(Mapper.Map <Data.Graph.Invoice, InvoiceModel>(inv));
        }
        public async Task <IActionResult> GenerateAsync([FromBody] NewInvoiceModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ErrorResponse.Create("Invalid model.", ModelState)));
            }

            IInvoice invoice = await _invoiceService.GenerateAsync(Mapper.Map <Invoice>(model));

            return(Ok(Mapper.Map <InvoiceModel>(invoice)));
        }
Exemplo n.º 3
0
        public ActionResult NewVehicle(NewInvoiceModel invoice)
        {
            if (ModelState.IsValid)
            {
                var newInvoice = InvoiceServices.CreateInvoice(invoice, base.LocationId);
                NavigationServices.AddVehicleToInShopList(base.LocationId, newInvoice);
                return(RedirectToAction("GetInvoice", new { id = newInvoice.Id }));
            }

            // Invalid - redisplay with errors
            ViewBag.AccountTypes = AccountTypeServices.GetAccountTypes(false, invoice.AccountTypeId);

            return(View("NewVehicle", invoice));
        }
Exemplo n.º 4
0
        public ActionResult NewVehicle()
        {
            var model = new NewInvoiceModel();

            var location = LocationServices.GetLocation(base.LocationId);

            if (location.DefaultAccountId != 0)
            {
                var defaultAccount = AccountServices.GetAccount(location.DefaultAccountId);
                model.AccountName = defaultAccount.Name;
                model.AccountId   = defaultAccount.Id;
            }

            ViewBag.AccountTypes = AccountTypeServices.GetAccountTypes(false, model.AccountTypeId);

            return(View("NewVehicle", model));
        }
 public async Task <InvoiceModel> GenerateInvoiceAsync(NewInvoiceModel model)
 {
     return(await _runner.RunAsync(() => _invoiceApi.GenerateAsync(model)));
 }