public HttpResponseMessage GetRoomByTrackId(int trackId, int codeCampId) { try { RoomInfo room = null; var track = TrackDataAccess.GetItems(codeCampId).Where(t => t.TrackId == trackId).FirstOrDefault(); if (track != null) { room = RoomDataAccess.GetItem(track.RoomId.Value, codeCampId); } var response = new ServiceResponse <RoomInfo> { Content = room }; if (room == null) { ServiceResponseHelper <RoomInfo> .AddNoneFoundError("rooms", ref response); } return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson())); } catch (Exception ex) { Exceptions.LogException(ex); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE)); } }
public HttpResponseMessage UpdateRoom(RoomInfo room) { try { var originalRoom = RoomDataAccess.GetItem(room.RoomId, room.CodeCampId); var updatesToProcess = false; if (!string.Equals(originalRoom.RoomName, room.RoomName)) { originalRoom.RoomName = room.RoomName; updatesToProcess = true; } if (!string.Equals(originalRoom.Description, room.Description)) { originalRoom.Description = room.Description; updatesToProcess = true; } if (originalRoom.MaximumCapacity != room.MaximumCapacity) { originalRoom.MaximumCapacity = room.MaximumCapacity; updatesToProcess = true; } if (updatesToProcess) { room.LastUpdatedByDate = DateTime.Now; room.LastUpdatedByUserId = UserInfo.UserID; RoomDataAccess.UpdateItem(room); } var savedRoom = RoomDataAccess.GetItem(room.RoomId, room.CodeCampId); var response = new ServiceResponse <RoomInfo> { Content = savedRoom }; return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson())); } catch (Exception ex) { Exceptions.LogException(ex); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE)); } }
public HttpResponseMessage GetRoom(int itemId, int codeCampId) { try { var room = RoomDataAccess.GetItem(itemId, codeCampId); var response = new ServiceResponse <RoomInfo> { Content = room }; if (room == null) { ServiceResponseHelper <RoomInfo> .AddNoneFoundError("room", ref response); } return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson())); } catch (Exception ex) { Exceptions.LogException(ex); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE)); } }