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 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 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)); } } }
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)); } }