Exemplo n.º 1
0
        public async Task <IActionResult> Kupi(int id, [Bind("Id,NazivPoklona,Iznos,Kupljeno")] Pokloni pokloni)
        {
            if (id != pokloni.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    pokloni = await _context.Pokloni.FindAsync(id);

                    pokloni.Kupljeno = true;
                    _context.Update(pokloni);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PokloniExists(pokloni.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(pokloni));
        }
        public KorisniciDetailsGetRequest Update(KorisniciDetailsGetRequest request, int id)
        {
            var model = _db.KorisnikDetails.Find(id) ?? throw new ServerException(Constants.NotFoundErrorMessage + id);

            _mapper.Map(request, model);

            _db.Update(model);
            _db.SaveChanges();

            return(request);
        }
Exemplo n.º 3
0
        public Model.Korisnik Update(KorisniciUpdateRequest request, int id)
        {
            if (request.Password != request.PasswordConfirmation)
            {
                throw new UserException("Passwordi nisu jednaki!");
            }

            var x = _db.Korisnik.Where(s => s.KorisnikId == id).FirstOrDefault() ?? throw new Exception(Constants.NotFoundErrorMessage + id);

            _mapper.Map(request, x);

            _db.Update(x);
            _db.SaveChanges();

            return(_mapper.Map <Model.Korisnik>(x));
        }