public void logout() { server.logout(this); }
private Response handleRequest(Request request) { Response response = null; //LOGIN if (request is LoginRequest) { Console.WriteLine("Login request... "); LoginRequest loginRequest = (LoginRequest)request; Volunteer volunteer = loginRequest.Volunteer; try { lock (server) { server.login(this, volunteer.Username, volunteer.Password); } return(new OKResponse()); } catch (TeledonException e) { connected = false; return(new ErrorResponse(e.Message)); } } //LOGOUT if (request is LogoutRequest) { Console.WriteLine("Logout request... "); LogoutRequest logoutRequest = (LogoutRequest)request; try { lock (server) { server.logout(this); } connected = false; return(new OKResponse()); } catch (TeledonException e) { return(new ErrorResponse(e.Message)); } } //GET ALL CASES if (request is GetAllCasesRequest) { Console.WriteLine("Get all cases request... "); GetAllCasesRequest getAllCasesRequest = (GetAllCasesRequest)request; try { lock (server) { IEnumerable <Case> cases = server.getAllCases(); return(new GetAllCasesResponse(cases)); } } catch (TeledonException e) { return(new ErrorResponse(e.Message)); } } //GET ALL DONORS if (request is GetAllDonorsRequest) { Console.WriteLine("Get all donors request..."); GetAllDonorsRequest getAllDonorsRequest = (GetAllDonorsRequest)request; string subtring = getAllDonorsRequest.Substring; try { lock (server) { IEnumerable <Donor> donors = server.searchDonorByName(subtring); return(new GetAllDonorsResponse(donors)); } } catch (TeledonException e) { return(new ErrorResponse(e.Message)); } } //NEW DONATION if (request is NewDonationRequest) { Console.WriteLine("New donation request..."); NewDonationRequest newDonationRequest = (NewDonationRequest)request; int donorId = newDonationRequest.DonorId; String name = newDonationRequest.Name; String address = newDonationRequest.Address; String telephone = newDonationRequest.Telephone; Double sum = newDonationRequest.Sum; int caseId = newDonationRequest.CaseId; try { lock (server) { server.saveDonation(donorId, name, address, telephone, sum, caseId); return(new OKResponse()); } } catch (TeledonException e) { return(new ErrorResponse(e.Message)); } } return(response); }
private Response handleRequest(Request request) { //Response response = null; Request.Types.Type reqType = request.Type; switch (reqType) { case Request.Types.Type.Login: { Console.WriteLine("Login request... "); //LoginRequest loginRequest = (LoginRequest) request; //Volunteer volunteer = loginRequest.Volunteer; MPP_TeledonClientServer.model.Volunteer volunteer = ProtoUtils.getVoluneer(request); try { lock (server) { server.login(this, volunteer.Username, volunteer.Password); } return(ProtoUtils.createOKResponse()); } catch (TeledonException e) { connected = false; return(ProtoUtils.createErrorResponse(e.Message)); } } case Request.Types.Type.Logout: { Console.WriteLine("Logout request... "); try { lock (server) { server.logout(this); } connected = false; return(ProtoUtils.createOKResponse()); } catch (TeledonException e) { return(ProtoUtils.createErrorResponse(e.Message)); } } case Request.Types.Type.GetAllCases: { Console.WriteLine("Get all cases request... "); try { lock (server) { IEnumerable <MPP_TeledonClientServer.model.Case> cases = server.getAllCases(); return(ProtoUtils.createGetAllCasesResponse(cases)); } } catch (TeledonException e) { return(ProtoUtils.createErrorResponse(e.Message)); } } case Request.Types.Type.GetAllDonors: { Console.WriteLine("Get all donors request..."); string subtring = ProtoUtils.getSubstring(request); try { lock (server) { IEnumerable <MPP_TeledonClientServer.model.Donor> donors = server.searchDonorByName(subtring); return(ProtoUtils.createGetAllDonorsResponse(donors)); } } catch (TeledonException e) { return(ProtoUtils.createErrorResponse(e.Message)); } } case Request.Types.Type.NewDonation: { Console.WriteLine("New donation request..."); int donorId = ProtoUtils.getDonorId(request); String name = ProtoUtils.getName(request); String address = ProtoUtils.getAddress(request); String telephone = ProtoUtils.getTelephone(request); Double sum = ProtoUtils.getSum(request); int caseId = ProtoUtils.getCaseId(request); try { lock (server) { server.saveDonation(donorId, name, address, telephone, sum, caseId); return(ProtoUtils.createOKResponse()); } } catch (TeledonException e) { return(ProtoUtils.createErrorResponse(e.Message)); } } } return(null); }