public async Task <IActionResult> PutRestaurante(int id, Restaurante restaurante) { if (id != restaurante.Id) { return(BadRequest()); } _context.Entry(restaurante).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RestauranteExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutMKV(string id, MKV mKV) { if (id != mKV.Key) { return(BadRequest()); } _context.Entry(mKV).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MKVExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <IEnumerable <MovieView> > > Put([FromRoute] int id, [FromBody] MovieView param) { var selectedMovie = await dbContext.Movies.SingleOrDefaultAsync(item => item.Id == id); if (selectedMovie == null) { return(StatusCode(StatusCodes.Status404NotFound)); } selectedMovie.Title = param.Title; selectedMovie.DurationInHour = param.DurationInHour; await dbContext.SaveChangesAsync(); return(StatusCode(StatusCodes.Status200OK)); }
public async Task <ActionResult <IEnumerable <BookView> > > Put([FromRoute] int id, [FromBody] BookView param) { var selectedBook = await dbContext.Books.SingleOrDefaultAsync(item => item.Id == id); if (selectedBook == null) { return(StatusCode(StatusCodes.Status404NotFound)); } selectedBook.Title = param.Title; selectedBook.Date = param.Date; await dbContext.SaveChangesAsync(); return(StatusCode(StatusCodes.Status200OK)); }
[HttpPost] //dikasih tau kalo ini post(atribut) public async Task <ActionResult <IEnumerable <BookView> > > Post([FromBody] BookView param) //menerima body dalam bentuk JSON secara default { //SELECT COUNT(*) var newId = await dbContext.Books.CountAsync() + 1; dbContext.Add(new Book { Id = newId, Title = param.Title, Date = param.Date }); await dbContext.SaveChangesAsync(); return(StatusCode(StatusCodes.Status201Created));//return biasa untuk post/patch => 201 }
public async Task <IActionResult> Regist([FromBody] MUser user) { if (!ModelState.IsValid) { return(BadRequest()); } if (_context.SUser.Any(u => u.ID == user.ID)) { return(Forbid()); } user.RegistDate = DateTime.Now; _context.SUser.Add(user); await _context.SaveChangesAsync(); return(Ok()); }