Beispiel #1
0
        public Model.Korisnik Insert(KorisniciInsertRequest request)
        {
            var alreadyExists = _db.Korisnik.Where(k => k.Username == request.Username || k.Email == request.Email).FirstOrDefault();

            if (alreadyExists != null)
            {
                throw new UserException("Korisnik sa tim nazivom/emailom već postoji!");
            }

            if (request.Password != request.PasswordConfirmation)
            {
                throw new UserException("Passwordi nisu jednaki!");
            }

            var temp = _mapper.Map <Database.Korisnik>(request);

            //Automatski postavlja korisnicku ulogau, ukoliko nije drugacije specifirano od strane administratora
            temp.UlogaId = (request.UlogaId != 0) ? request.UlogaId : _db.Uloga.Where(x => x.Naziv == Roles.User).Select(y => y.UlogaId).FirstOrDefault();

            temp.LozinkaSalt = GenerateSalt();
            temp.LozinkaHash = GenerateHash(temp.LozinkaSalt, request.Password);

            var korisnikDetails = new KorisnikDetails();

            _db.KorisnikDetails.Add(korisnikDetails);
            _db.SaveChanges();
            temp.KorisnikDetailsId = korisnikDetails.KorisnikDetailsId;

            _db.Korisnik.Add(temp);
            _db.SaveChanges();

            return(_mapper.Map <Model.Korisnik>(temp));
        }
        public OcjenaVM Insert(OcjenaVM request)
        {
            var temp = _mapper.Map <Database.Ocjena>(request);

            _db.Ocjena.Add(temp);
            _db.SaveChanges();

            return(request);
        }
        public NarudzbaDetailsVM Insert(NarudzbaDetailsVM request)
        {
            var temp = _mapper.Map <Database.NarudzbaDetails>(request);

            _db.NarudzbaDetails.Add(temp);
            _db.SaveChanges();

            return(request);
        }
Beispiel #4
0
        public ProizvodVM Insert(ProizvodVM request)
        {
            var temp = _mapper.Map <Database.Proizvod>(request);

            _db.Proizvod.Add(temp);
            _db.SaveChanges();

            return(request);
        }
Beispiel #5
0
        public RacunVM Insert(RacunVM request)
        {
            var temp = _mapper.Map <Database.Racun>(request);

            _db.Racun.Add(temp);
            _db.SaveChanges();

            return(request);
        }
        public Model.Requests.Dostava.Dostava Insert(Model.Requests.Dostava.Dostava request)
        {
            var temp = _mapper.Map <Database.Dostava>(request);

            var test = _db.Dostava.Add(temp);

            _db.SaveChanges();

            request.DostavaId = test.Entity.DostavaId;
            return(request);
        }
Beispiel #7
0
        public NarudzbaVM Insert(NarudzbaVM request)
        {
            request.Dostava    = null;
            request.Korisnik   = null;
            request.Zaposlenik = null;

            var temp = _mapper.Map <Database.Narudzba>(request);

            var test = _db.Narudzba.Add(temp);

            _db.SaveChanges();

            request.NarudzbaId = test.Entity.NarudzbaId;
            return(request);
        }
        public ProizvodacPoklona Insert(ProizvodacPoklona request)
        {
            var validation1 = _db.ProizvodacPoklona.Where(x => x.Naziv == request.Naziv).FirstOrDefault();

            if (validation1 != null)
            {
                throw new UserException(Constants.AlreadyExistsErrorMessag + request.Naziv);
            }

            var temp = _mapper.Map <Database.ProizvodacPoklona>(request);

            _db.ProizvodacPoklona.Add(temp);
            _db.SaveChanges();

            return(request);
        }
        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);
        }