public async Task <IActionResult> SadrzajUpdate([FromBody] SadrzajApiModel model) { if (model == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } else { var sadrzaj = await _context.Sadrzaj.FindAsync(model.Id); if (sadrzaj == null) { return(NotFound("Traženi sadržaj ne postoji(ID = " + model.Id + ")")); } else { sadrzaj.Ime = model.Ime; sadrzaj.Opis = model.Opis; sadrzaj.Url = model.Url; sadrzaj.JeOdobren = model.JeOdobren; sadrzaj.IdAutora = model.IdAutora; sadrzaj.IdOdobrenOd = model.IdOdobrenOd; sadrzaj.IdTipa = model.IdTipa; await _context.SaveChangesAsync(); return(NoContent()); }; } }
public async Task <IActionResult> SadrzajCreate([FromBody] SadrzajApiModel model) { if (model != null && ModelState.IsValid) { Sadrzaj sadrzaj = new Sadrzaj { Ime = model.Ime, Opis = model.Opis, Url = model.Url, JeOdobren = model.JeOdobren, IdAutora = model.IdAutora, IdOdobrenOd = model.IdOdobrenOd, IdTipa = model.IdTipa }; _context.Add(sadrzaj); await _context.SaveChangesAsync(); var u = await _context.Sadrzaj .AsNoTracking() .Include(d => d.IdAutoraNavigation) .Include(d => d.IdOdobrenOdNavigation) .Include(d => d.IdTipaNavigation) .LastOrDefaultAsync(); return(new ObjectResult(new SadrzajApiModel { Id = u.Id, Ime = u.Ime, Opis = u.Opis, Url = u.Url, JeOdobren = u.JeOdobren, IdAutora = u.IdAutora, Autor = u.IdAutoraNavigation.Ime + " " + u.IdAutoraNavigation.Prezime, IdOdobrenOd = u.IdOdobrenOd, OdobrenOd = u.IdOdobrenOdNavigation.Ime + " " + u.IdOdobrenOdNavigation.Prezime, IdTipa = u.IdTipa, Tip = u.IdTipaNavigation.Ime })); } return(BadRequest(ModelState)); }