public async Task <IActionResult> AzurirajAuto([FromBody] AutomobilViewModel automobil)
        {
            try
            {
                if (automobil == null)
                {
                    throw new Exception("Greska prilikom azuriranja auta!");
                }

                var auto = automobil.ToModel();

                var updatedAuto = await _autoService.AzurirajAutomobil(auto);

                return(Ok(updatedAuto.ToViewModel()));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public async Task <IActionResult> SnimiAutomobil([FromBody] AutomobilViewModel automobil)
        {
            try
            {
                if (automobil == null)
                {
                    throw new Exception("Greska auto ne moze biti null!");
                }

                var auto = automobil.ToModel();

                var createdAuto = await _autoService.SnimiAutomobil(auto);

                return(Ok(createdAuto.ToViewModel()));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 3
0
 public static Automobil ToModel(this AutomobilViewModel automobilViewModel)
 {
     return(new Automobil()
     {
         Id = automobilViewModel.Id,
         Marka = automobilViewModel.Marka,
         Godiste = automobilViewModel.Godiste,
         Boja = automobilViewModel.Boja,
         Opis = automobilViewModel.Opis,
         Kilometri = automobilViewModel.Kilometri,
         GrijaciSjedista = automobilViewModel.GrijaciSjedista,
         Klima = automobilViewModel.Klima,
         Zastita = automobilViewModel.Zastita,
         Xenoni = automobilViewModel.Xenoni,
         Siber = automobilViewModel.Siber,
         ServoVolan = automobilViewModel.ServoVolan,
         Registrovan = automobilViewModel.Registrovan,
         PodizaciStakala = automobilViewModel.PodizaciStakala,
         Motor = automobilViewModel.Motor,
         ProizvId = automobilViewModel.ProizvodId.GetValueOrDefault()
     });
 }