public void Execute(UpdateKorisnikDto request)
        {
            if (_context.Korisnici.Any(x => x.Id == request.Id))
            {
                if (request.IdUloga != 17)
                {
                    var jedanKorisnik = _context.Korisnici.Find(request.Id);
                    idValidator.ValidateAndThrow(request);
                    _validator.ValidateAndThrow(request);
                    if (jedanKorisnik.Email == request.Email)
                    {
                        _validator.ValidateAndThrow(request);

                        jedanKorisnik.Ime      = request.Ime;
                        jedanKorisnik.Prezime  = request.Prezime;
                        jedanKorisnik.Email    = request.Email;
                        jedanKorisnik.IdUloga  = request.IdUloga;
                        jedanKorisnik.Password = MD5function.MD5Hash(request.Password);
                        _context.SaveChanges();
                    }
                    else
                    {
                        if (_context.Korisnici.Any(x => x.Email == request.Email))
                        {
                            emailValidator.ValidateAndThrow(request);
                        }
                        else
                        {
                            _validator.ValidateAndThrow(request);

                            jedanKorisnik.Ime      = request.Ime;
                            jedanKorisnik.Prezime  = request.Prezime;
                            jedanKorisnik.Email    = request.Email;
                            jedanKorisnik.IdUloga  = request.IdUloga;
                            jedanKorisnik.Password = MD5function.MD5Hash(request.Password);
                            _context.SaveChanges();
                        }
                    }
                }
                else
                {
                    throw new NotFoundException(request.IdUloga, typeof(Uloga));
                }
            }
            else
            {
                throw new NotFoundException(request.Id, typeof(Korisnik));
            }
        }
示例#2
0
 public void Put([FromForm] UpdateKorisnikDto dto, [FromServices] IUpdateKorisnikCommand command)
 {
     executor.ApplayCommand(command, dto);
 }