1. Modele Model/DataModels/Pojazd.cs ViewModels/ViewModels/DodajPojazdVm.cs / PojazdVm.cs public class Pojazd { public int Id { get; set; } public string Rodzaj {get; set;} public string Model {get; set;} public int Rocznik {get; set;} public decimal Pojemnosc {get; set;} } 2. Interfejs Services/Interfaces/IPojazd.cs public interface IPojazd { PojazdVm DodajPojazd(DodajPojazdVm pojazdVm); } 3. DbContext DAL/EF/MyDbContext.cs public DbSet Pojazdy { get; set; } 4. Serwis Services/Services/PojazdService.cs using AutoMapper; using DAL.EF; using Model.DataModels; using Services.Interfaces; using ViewModels.ViewModels; namespace Services.Services; public class PojazdService : BaseService, IPojazd { public PojazdService(MyDbContext db, IMapper mapper) : base(db, mapper) { } public PojazdVm DodajPojazd(DodajPojazdVm pojazdVm) { var pojazdEntity = _mapper.Map(pojazdVm); _dbContext.Pojazdy.Add(pojazdEntity); _dbContext.SaveChanges(); return _mapper.Map(pojazdEntity); } } Web/Program.cs builder.Services.AddScoped(); 5. Controller Web/Controllers/PojazdController.cs public class PojazdController : Controller { private IPojazd service; public PojazdController(IPojazd service) { this.service = service; } [HttpGet] public IActionResult DodajPojazd() { return View(); } [HttpPost] public IActionResult DodajPojazd(DodajPojazdVm modell) { if (!ModelState.IsValid) { return View(modell); } var pojazdVm = service.DodajPojazd(modell); return View("DodanyPojazd", pojazdVm); } } 6. Widok Web/Views/Pojazd/DodajPojazd.cshtml @model ViewModels.ViewModels.DodajPojazdVm

Dodaj pojazd

Web/Views/Pojazd/DodanyPojazd.cshtml @model ViewModels.ViewModels.PojazdVm

Dodano pojazd

Model @Model.Model

Rocznik @Model.Rocznik

Pojemnosc @Model.Pojemnosc

7. Layout Web/Views/Shared/_Layout.cshtml Dodaj Pojazd 8. AutoMapper Web/Configuration/AMProfiles/MainProfile.cs CreateMap().ReverseMap(); CreateMap().ReverseMap(); 9. Migracja