private void handleUpdate(UpdateResponse update)
 {
     if (update is BuyTicketResponse)
     {
         BuyTicketResponse response = (BuyTicketResponse)update;
         Ticket            ticket   = DtoUtils.GetFromDto(response.Ticket);
         Console.WriteLine("HANDLE UPDATE " + ticket);
         client.TicketSold(ticket);
     }
 }
        private Response handleRequest(Request request)
        {
            Response response = null;

            if (request is LoginRequest)
            {
                Console.WriteLine("Login request ...");
                LoginRequest logReq = (LoginRequest)request;
                UserDto      udto   = logReq.User;
                User         user   = DtoUtils.GetFromDto(udto);
                try
                {
                    lock (server)
                    {
                        server.Login(user, this);
                    }
                    return(new OkResponse());
                }
                catch (Error e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is LogoutRequest)
            {
                Console.WriteLine("Logout request");
                LogoutRequest logReq = (LogoutRequest)request;
                UserDto       udto   = logReq.User;
                User          user   = DtoUtils.GetFromDto(udto);
                try
                {
                    lock (server)
                    {
                        server.Logout(user, this);
                    }
                    connected = false;
                    return(new OkResponse());
                }
                catch (Error e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetShowsRequest)
            {
                Console.WriteLine("Get shows request");
                GetShowsRequest getShowsRequest = (GetShowsRequest)request;
                try
                {
                    Show[]    shows    = server.GetAll();
                    ShowDto[] showDtos = DtoUtils.getDto(shows);
                    return(new GetShowsResponse(showDtos));
                }
                catch (Error e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetArtistsByDateRequest)
            {
                Console.WriteLine("Get artists by date request");
                GetArtistsByDateRequest getArtistsByDateRequest = (GetArtistsByDateRequest)request;
                String date = getArtistsByDateRequest.Date;
                try
                {
                    Artist[]    artists    = server.GetArtists(date);
                    ArtistDto[] artistDtos = DtoUtils.GetDto(artists);
                    return(new GetArtistsByDateResponse(artistDtos));
                }
                catch (Error e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is BuyTicketRequest)
            {
                Console.WriteLine("Buy ticket request");
                BuyTicketRequest buyTicketRequest = (BuyTicketRequest)request;
                TicketDto        ticketDto        = buyTicketRequest.TicketDto;
                Ticket           ticket           = DtoUtils.GetFromDto(ticketDto);
                try
                {
                    lock (server)
                    {
                        server.SellTickets(ticket);
                    }
                    return(new OkResponse());
                }
                catch (InvalidPurchaseException e)
                {
                    return(new ErrorResponse(e.Message));
                }
                catch (Error e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }
            return(response);
        }