public IEnumerable <Studentkurs> getStudentKurs(int id)
 {
     using (var context = new PageBazaContext())
     {
         return(context.Studentkurs.ToList());
     }
 }
 public IEnumerable <Kurs> getKursevi()
 {
     using (var context = new PageBazaContext())
     {
         return(context.Kurs.ToList());
     }
 }
Example #3
0
 public IEnumerable <Student> Get()
 {
     using (var context = new PageBazaContext())
     {
         return(context.Student.ToList());
     }
 }
        public Kurs getKurs(int id)
        {
            using (var context = new PageBazaContext())
            {
                var  pomocna = context.Kurs.Where(k => k.Kursid == id).ToList();
                Kurs kurs    = new Kurs();
                kurs.Nazivkursa = pomocna[0].Nazivkursa;

                return(kurs);
            }
        }
Example #5
0
        public Student ViewStudent(int id)
        {
            using (var context = new PageBazaContext())
            {
                var     pomocna = context.Student.Where(stud => stud.Studentid == id).ToList();
                Student student = new Student();
                student.Ime              = pomocna[0].Ime;
                student.Prezime          = pomocna[0].Prezime;
                student.Brojindeksa      = pomocna[0].Brojindeksa;
                student.Statusstudentaid = pomocna[0].Statusstudentaid;
                student.Godina           = pomocna[0].Godina;
                student.Studentid        = pomocna[0].Studentid;

                return(student);
            }
        }
Example #6
0
        public HttpResponseMessage Remove(int id)
        {
            using (var context = new PageBazaContext())
            {
                Student student = context.Student.Find(id);
                if (student != null)
                {
                    context.Remove(student);
                    context.SaveChanges();

                    return(new HttpResponseMessage(HttpStatusCode.OK));
                }
                else
                {
                    return(new HttpResponseMessage(HttpStatusCode.BadRequest));
                }
            }
        }
        public void kreirajKurs(string Ime, [FromUri] int[] niz)
        {
            using (var context = new PageBazaContext())
            {
                Kurs kurs = new Kurs();
                kurs.Nazivkursa = Ime;
                context.Add(kurs);
                context.SaveChanges();
                var a          = context.Kurs.Where(cur => cur.Nazivkursa == Ime).ToList();
                int poslednjid = a[0].Kursid;
                for (int i = 0; i < niz.Length; i++)
                {
                    Studentkurs stud = new Studentkurs();
                    stud.Kursid    = poslednjid;
                    stud.Studentid = niz[i];

                    context.Add(stud);
                    context.SaveChanges();
                }
            }
        }
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            var identity = new ClaimsIdentity(context.Options.AuthenticationType);


            using (var baza = new PageBazaContext())
            {
                List <Korisnici> korisnici = baza.Korisnici.ToList();
                foreach (Korisnici k in korisnici)
                {
                    if (k.Username == context.UserName && k.Password == context.Password)
                    {
                        identity.AddClaim(new Claim(ClaimTypes.Role, "admin"));
                        identity.AddClaim(new Claim("username", k.Username));
                        identity.AddClaim(new Claim(ClaimTypes.Name, k.Username));
                        context.Validated(identity);
                        return;
                    }
                }
            }
            context.SetError("invalid_grant", "Neispravni podaci za logovanje!!!");
        }
Example #9
0
        public HttpResponseMessage editStudentPost([FromBody] StudentRequestModel student)
        {
            using (var context = new PageBazaContext())
            {
                if (ModelState.IsValid)
                {
                    Student stud = context.Student.Find(student.Studentid);
                    stud.Ime              = student.Ime;
                    stud.Prezime          = student.Prezime;
                    stud.Statusstudentaid = student.Statusstudentaid;
                    stud.Godina           = student.Godina;
                    stud.Brojindeksa      = student.Brojindeksa;

                    context.SaveChanges();

                    return(new HttpResponseMessage(HttpStatusCode.OK));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
                }
            }
        }
Example #10
0
        public IHttpActionResult registrujKorisnika([FromBody] LoginRequestModel user)
        {
            Boolean poklapanje = false;

            using (var baza = new PageBazaContext())
            {
                List <Korisnici> korisnici = baza.Korisnici.ToList();
                foreach (Korisnici k in korisnici)
                {
                    if (user.Username == k.Username)
                    {
                        poklapanje = true;
                        return(Ok("Username " + user.Username + " vec postoji!"));
                    }
                }
                Korisnici kor = new Korisnici();
                kor.Username = user.Username;
                kor.Password = user.Password;

                baza.Add(kor);
                baza.SaveChanges();
                return(Ok(true));
            }
        }
Example #11
0
 public IHttpActionResult getForAdmin([FromBody] LoginRequestModel user)
 {
     using (var baza = new PageBazaContext())
     {
         List <Korisnici> korisnici = baza.Korisnici.ToList();
         foreach (Korisnici k in korisnici)
         {
             if (user.Username == k.Username && user.Password == k.Password)
             {
                 var identity = (ClaimsIdentity)User.Identity;
                 var roles    = identity.Claims.Where(c => c.Type == ClaimTypes.Role).Select(c => c.Value);
                 foreach (var rol in roles)
                 {
                     if (rol == "admin")
                     {
                         return(Ok(true));
                     }
                 }
                 return(Ok(false));
             }
         }
         return(Ok(false));
     }
 }