예제 #1
0
        public async Task <IActionResult> GetRentedPlaceById(string id)
        {
            int ID     = Convert.ToInt32(id);
            var entity = await RentedPlaceDTO.ToEntity(ID, _context);

            if (entity == null)
            {
                return(NotFound());
            }

            return(Ok(entity));
        }
예제 #2
0
        public async Task <IActionResult> Delete(int id)
        {
            var entity = await RentedPlaceDTO.ToEntity(id, _context);

            if (entity == null)
            {
                return(NotFound());
            }
            _context.RentedPlaces.Remove(entity);
            await _context.SaveChangesAsync();

            return(NoContent());
        }
예제 #3
0
        public async Task <IActionResult> Put(RentedPlaceDTO dto)
        {
            var entity = await RentedPlaceDTO.ToEntity(dto, _context);

            if (entity == null)
            {
                return(NotFound());
            }

            _context.Entry(entity).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(CreatedAtAction("Get", new { }, dto));
        }
예제 #4
0
        public async Task <ActionResult <RentedPlaceDTO> > Post(RentedPlaceDTO dto)
        {
            var entity = await RentedPlaceDTO.ToEntity(dto, _context);

            if (entity == null)
            {
                return(NotFound());
            }

            await _context.RentedPlaces.AddAsync(entity);

            await _context.SaveChangesAsync();

            var contractDto = RentedPlaceDTO.FromEntity(entity);

            return(CreatedAtAction("Get", new { }, contractDto));
        }