Пример #1
0
        public async Task <ActionResult <IEnumerable <MovieView> > > Post([FromBody] MovieView param)
        {
            var newMovie = new Movie {
                Title = param.Title, DurationInHour = param.DurationInHour
            };

            dbContext.Add(newMovie);
            await this.dbContext.SaveChangesAsync();

            return(CreatedAtAction(nameof(Get), new { id = newMovie.Id }, param));
        }
Пример #2
0
        public async Task <ActionResult <IEnumerable <BookView> > > Post([FromBody] BookView param)
        {
            var newId = await dbContext.Books.CountAsync() + 1;

            dbContext.Add(new Book {
                Id = newId, Title = param.Title, Date = param.Date
            });
            await this.dbContext.SaveChangesAsync();

            return(StatusCode(StatusCodes.Status201Created));
        }
Пример #3
0
        public async Task <ActionResult <IEnumerable <BookView> > > Post([FromBody] BookView param)
        {
            var newBook = new Book {
                Title = param.Title, Date = param.Date
            };

            dbContext.Add(newBook);
            await this.dbContext.SaveChangesAsync();

            return(CreatedAtAction(nameof(Get), new { id = newBook.Id }, param));
        }
Пример #4
0
        [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
        }