Exemplo n.º 1
0
        public async Task <IActionResult> PutKursStudent(int id, KursStudent kursStudent)
        {
            if (id != kursStudent.KursId)
            {
                return(BadRequest());
            }

            _context.Entry(kursStudent).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!KursStudentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <ActionResult <KursStudent> > PostKursStudent(KursStudent kursStudent)
        {
            _context.KursStudenti.Add(kursStudent);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (KursStudentExists(kursStudent.KursId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetKursStudent", new { id = kursStudent.KursId }, kursStudent));
        }
Exemplo n.º 3
0
        public async Task <ActionResult <Kurs> > PostKurs(KursStudentRequestModel kurs)
        {
            Kurs new_kurs = new Kurs()
            {
                Naziv = kurs.Naziv
            };

            _context.Kursevi.Add(new_kurs);
            await _context.SaveChangesAsync();

            new_kurs = await _context.Kursevi.FirstOrDefaultAsync(x => x.Naziv == kurs.Naziv);

            for (int i = 0; i < kurs.OdabraniStudenti.Count; i++)
            {
                KursStudent new_ks = new KursStudent()
                {
                    KursId = new_kurs.KursId, StudentId = kurs.OdabraniStudenti[i]
                };
                _context.KursStudenti.Add(new_ks);
                await _context.SaveChangesAsync();
            }
            return(CreatedAtAction("GetKurs", new { id = kurs.KursId }, kurs));
        }