Beispiel #1
0
        public ActionResult Update(int id, [FromBody] StudentUpdateVM x)
        {
            Student student = _dbContext.Student.Include(s => s.opstina_rodjenja.drzava).FirstOrDefault(s => s.id == id);

            if (student == null)
            {
                return(BadRequest("pogresan ID"));
            }

            student.ime                 = x.ime.RemoveTags();
            student.prezime             = x.prezime.RemoveTags();
            student.broj_indeksa        = x.broj_indeksa;
            student.datum_rodjenja      = x.datum_rodjenja;
            student.opstina_rodjenja_id = x.opstina_rodjenja_id;

            _dbContext.SaveChanges();
            return(Get(id));
        }
Beispiel #2
0
        public ActionResult Update(int id, [FromBody] StudentUpdateVM x)
        {
            if (!HttpContext.GetLoginInfo().isLogiran)
            {
                return(BadRequest("nije logiran"));
            }

            Student student;

            if (id == 0)
            {
                student = new Student
                {
                    slika_korisnika = Config.SlikeURL + "empty.png",
                    created_time    = DateTime.Now
                };
                _dbContext.Add(student);
            }
            else
            {
                student = _dbContext.Student.Include(s => s.opstina_rodjenja.drzava).FirstOrDefault(s => s.id == id);
                if (student == null)
                {
                    return(BadRequest("pogresan ID"));
                }
            }

            student.ime                 = x.ime.RemoveTags();
            student.prezime             = x.prezime.RemoveTags();
            student.broj_indeksa        = x.broj_indeksa;
            student.datum_rodjenja      = x.datum_rodjenja;
            student.opstina_rodjenja_id = x.opstina_rodjenja_id;

            _dbContext.SaveChanges();
            return(Get(student.id));
        }