private void HandleUpdate(IUpdateResponse update) { if (update is ShowModifiesResponse) { ShowModifiesResponse newMatchDto = (ShowModifiesResponse)update; Match newMatch = DTOUtils.GetFromDTO(newMatchDto.Match); _client.ShowUpdates(newMatch); } }
private IResponse HandleRequest(Request request) { IResponse response = null; if (request is LoginRequest) { Console.WriteLine(value: "Login request ..."); LoginRequest logReq = (LoginRequest)request; UserDTO udto = logReq.User; User user = DTOUtils.GetFromDTO(usdto: udto); try { lock (server) { server.Login(user: user, client: this); } return(new OkResponse()); } catch (ControllerException e) { _connected = false; return(new ErrorResponse(message: e.Message)); } } if (request is LogoutRequest) { Console.WriteLine(value: "Logout request"); LogoutRequest logReq = (LogoutRequest)request; UserDTO udto = logReq.User; User user = DTOUtils.GetFromDTO(usdto: udto); try { lock (server) { server.Logout(user: user, client: this); } //_connected = false; return(new OkResponse()); } catch (ControllerException e) { _connected = false; return(new ErrorResponse(message: e.Message)); } } if (request is GetAllRequest) { Console.WriteLine(value: "GetAllRequest"); GetAllRequest getAllRequest = (GetAllRequest)request; try { List <Match> list = null; lock (server) { list = server.GetAllMatches(); } // _connected = false; response = new GetAllReponse(list: list); } catch (Exception e) { _connected = false; response = new ErrorResponse(message: e.Message); } } if (request is GetAllFilteredAndSortedRequest) { Console.WriteLine(value: "GetAllFilteredAndSortedRequest"); GetAllFilteredAndSortedRequest getAllRequest = (GetAllFilteredAndSortedRequest)request; try { List <Match> list = null; lock (server) { list = server.GetFilteredAndSortedMatches(); } // _connected = false; response = new GetAllFilteredAndSortedResponse(list: list); } catch (Exception e) { _connected = false; response = new ErrorResponse(message: e.Message); } } if (request is SellTicketsRequest) { Console.WriteLine(value: "Worker - sellTickets"); SellTicketsRequest sellTicketsRequest = (SellTicketsRequest)request; try { SalesDTO sale = sellTicketsRequest.Sale; lock (server) { this.server.SellTickets(idMatch: sale.IdMatch, quantity: sale.Quantity, buyerPerson: sale.Person, username: sale.Username); } response = new OkResponse(); } catch (Exception e) { _connected = false; response = new ErrorResponse(e.Message); } } return(response); }