public async Task <ActionResult <RoomModel> > Put(RoomPutModel roomPutModel) { var response = await _roomService.PutAsync(roomPutModel); if (response.IsError) { return(StatusCode((int)response.ErrorCode, response.ErrorDescription)); } return(Ok(response.Data)); }
public async Task <ServiceResponse <RoomModel> > PutAsync(RoomPutModel roomPutModel) { try { var room = await _context.People.AsNoTracking().FirstOrDefaultAsync(f => f.Id == roomPutModel.Id); if (room == null) { return(new ServiceResponse <RoomModel> { ErrorCode = HttpStatusCode.NotFound, ErrorDescription = "Room does not exist" }); } var updatedRoom = _mapper.Map <Person>(roomPutModel); _context.Entry(updatedRoom).State = EntityState.Modified; if (await _context.SaveChangesAsync() > 0) { return(new ServiceResponse <RoomModel> { Data = _mapper.Map <RoomModel>(updatedRoom) }); } return(new ServiceResponse <RoomModel> { ErrorCode = HttpStatusCode.InternalServerError, ErrorDescription = "Internal Server Error" }); } catch (Exception e) { Debug.WriteLine(e); return(new ServiceResponse <RoomModel> { ErrorCode = HttpStatusCode.InternalServerError, ErrorDescription = "Internal Server Error" }); } }