public async Task <IActionResult> Placanje(NarudzbaPlacanjeVM nacinPlacanja) { NarudzbaUpdateRequest updateRequest = new NarudzbaUpdateRequest(); if (nacinPlacanja.NazivPlacanja == "Pouzećem") { updateRequest = new NarudzbaUpdateRequest { NazivPlacanja = nacinPlacanja.NazivPlacanja, }; } else if (nacinPlacanja.NazivPlacanja == "Karticom") { if (ModelState.IsValid) { updateRequest = new NarudzbaUpdateRequest { NazivPlacanja = nacinPlacanja.NazivPlacanja, BrojKartice = nacinPlacanja.BrojKartice, CVV = nacinPlacanja.CVV }; } else { return(View(nacinPlacanja)); } } await _restoranApi.UpdateNarudzbaAsync(nacinPlacanja.NarudzbaID, updateRequest); return(RedirectToAction("UspjesnaNarudzba")); }
public async Task <NarudzbaResponse> Update(int id, NarudzbaUpdateRequest request) { var entity = _context.Set <Narudzba>().Find(id); if (!string.IsNullOrEmpty(request.Adresa)) { entity.Adresa = request.Adresa; } if (request.Telefon != null) { entity.Telefon = request.Telefon; } _context.Set <Narudzba>().Attach(entity); _context.Set <Narudzba>().Update(entity); await _context.SaveChangesAsync(); var nacinPlacanja = _context.Set <NacinPlacanja>().Find(entity.NacinPlacanjaID); if (request.NazivPlacanja == "Karticom") { nacinPlacanja.Naziv = request.NazivPlacanja; nacinPlacanja.BrojKartice = request.BrojKartice; nacinPlacanja.CVV = request.CVV; } await _context.SaveChangesAsync(); return(_mapper.Map <NarudzbaResponse>(entity)); }
public async Task <ActionResult <NarudzbaResponse> > Update(int id, NarudzbaUpdateRequest request) { var response = await _service.Update(id, request); if (response == null) { return(NotFound()); } return(Ok(response)); }