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);
        }
Example #2
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 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);
        }