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"));; }
public void Add(FuelInvoice fuelInvoice) { _context.FuelInvoices.Add(fuelInvoice); _context.SaveChanges(); }