Ejemplo n.º 1
0
        public ActionResult Create(FuelInvoiceFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.FuelTypes     = _unitOfWork.FuelTypes.GetFuelTypes();
                viewModel.CurrencyTypes = _unitOfWork.CurrencyTypes.GetCurrencyTypes();
                viewModel.GasStations   = _unitOfWork.GasStations.GetGasStations();
                return(View("Create", viewModel));
            }

            var fuelInvoice = new FuelInvoice
            {
                InvoiceTypeId = (int)InvoiceTypeEnum.FuelInvoice,
                InvoiceNumber = viewModel.InvoiceNumber,
                FuelTypeId    = viewModel.FuelType,
                RefuelingDate = DateTime.Parse(viewModel.RefuelingDate),
                Amount        = viewModel.Amount.Value,
                CurrencyId    = viewModel.CurrencyType,
                UnitPrice     = viewModel.UnitPrice.Value,
                Quantity      = viewModel.Quantity.Value,
                GasStationId  = viewModel.GasStation,
                MeterStatus   = viewModel.MeterStatus.Value,
                UserId        = User.Identity.GetUserId()
            };

            _unitOfWork.FuelInvoices.Add(fuelInvoice);
            _unitOfWork.Complete();

            return(RedirectToAction("Index", "Manage"));;
        }
Ejemplo n.º 2
0
 public void Add(FuelInvoice fuelInvoice)
 {
     _context.FuelInvoices.Add(fuelInvoice);
     _context.SaveChanges();
 }