public async Task <IActionResult> PutPriceListing(long id, PriceListing priceListing) { if (id != priceListing.Id) { return(BadRequest()); } var priceListingDb = await _context.PriceListings.FindAsync(id); if (priceListingDb == null) { return(NotFound()); } priceListingDb.Url = priceListing.Url; priceListingDb.ItemPrice = priceListing.ItemPrice; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) when(!PriceListingExists(id)) { return(NotFound()); } return(NoContent()); }
public async Task <Korisnik> Register(Korisnik korisnik) { try { await _context.Korisnici.AddAsync(korisnik); await _context.SaveChangesAsync(); return(korisnik); } catch (Exception ex) { Debug.WriteLine(">>>>>>> " + ex.Message); return(null); } }
static async Task InitializeDatabase() { await _priceContext.Database.EnsureCreatedAsync(); if (_priceContext.ProductPrices.Any()) { return; } for (int i = 0; i <= 6; i++) { _priceContext.ProductPrices.Add(new ProductPrice(i * 100, i + 10)); } await _priceContext.SaveChangesAsync(); }
public async Task <double> SavePoints(List <Pitanje> pitanja, int korisnikID) { try { var pitanjaIzBaze = await _context.Pitanja.Include(p => p.Odgovori).ToListAsync(); if (pitanjaIzBaze == null) { return(-500); } if (pitanjaIzBaze.Count != pitanja.Count) { return(-500); } var poeni = pitanjaIzBaze.CalculatePoints(pitanja); var korisnik = await _context.Korisnici.FirstOrDefaultAsync(x => x.KorisnikID == korisnikID); if (korisnik == null) { return(-500); } korisnik.Poeni = poeni; korisnik.DatumUcesca = DateTime.Now; await _context.SaveChangesAsync(); return(poeni); } catch (Exception ex) { Debug.WriteLine(">>>>>> " + ex.Message); return(-500); } }