public static Donatie getFromDTO(DonatieDTO donatie) { int id = donatie.Id; int idD = donatie.IdD; int idC = donatie.IdC; double sumaDonatie = donatie.SumaDonatie; return(new Donatie(id, idD, idC, sumaDonatie)); }
public static DonatieDTO[] getDTO(Donatie[] donatii) { DonatieDTO[] frDTO = new DonatieDTO[donatii.Length]; for (int i = 0; i < donatii.Length; i++) { frDTO[i] = getDTO(donatii[i]); } return(frDTO); }
public void addDonatie(Donatie donatie) { DonatieDTO donatieDTO = DTOUtils.getDTO(donatie); sendRequest(new SaveDonatieRequest(donatieDTO)); Response response = readResponse(); if (response is ErrorResponse) { ErrorResponse err = (ErrorResponse)response; throw new MyException(err.Message); } }
public void donatieAdded(Donatie donatie) { DonatieDTO dto = DTOUtils.getDTO(donatie); Console.WriteLine("Donatie received " + donatie); try { sendResponse(new SaveDonatieResponse(dto)); } catch (Exception e) { throw new MyException("Sending error: " + e); } }
public SaveDonatieResponse(DonatieDTO donatie) { this.donatie = donatie; }
private Response handleRequest(Request request) { Response response = null; if (request is GetCazuriRequest) { Console.WriteLine("GetCazuriRequest....."); GetCazuriRequest getReq = (GetCazuriRequest)request; try { CazCaritabil[] allCazuri; lock (server) { allCazuri = server.getCazuri(); } CazCaritabilDTO[] frDTO = DTOUtils.getDTO(allCazuri); return(new GetCazuriResponse(frDTO)); } catch (MyException e) { return(new ErrorResponse(e.Message)); } } if (request is GetDonatiiRequest) { Console.WriteLine("GetDonatiiRequest....."); GetDonatiiRequest getReq = (GetDonatiiRequest)request; try { Donatie[] allDonatii; lock (server) { allDonatii = server.getDonatii(); } DonatieDTO[] frDTO = DTOUtils.getDTO(allDonatii); return(new GetDonatiiResponse(frDTO)); } catch (MyException e) { return(new ErrorResponse(e.Message)); } } if (request is GetDonatoriRequest) { Console.WriteLine("GetDonatoriRequest....."); GetDonatoriRequest getReq = (GetDonatoriRequest)request; try { Donator[] allDonatori; lock (server) { allDonatori = server.getDonatori(); } DonatorDTO[] frDTO = DTOUtils.getDTO(allDonatori); return(new GetDonatoriResponse(frDTO)); } catch (MyException e) { return(new ErrorResponse(e.Message)); } } if (request is LoginRequest) { Console.WriteLine("Login request ..."); LoginRequest logReq = (LoginRequest)request; VoluntarDTO udto = logReq.User; Voluntar user = DTOUtils.getFromDTO(udto); try { lock (server) { server.login(user, this); } return(new OkResponse()); } catch (MyException e) { connected = false; return(new ErrorResponse(e.Message)); } } if (request is LogoutRequest) { Console.WriteLine("Logout request"); LogoutRequest logReq = (LogoutRequest)request; VoluntarDTO udto = logReq.User; Voluntar user = DTOUtils.getFromDTO(udto); try { lock (server) { server.logout(user, this); } connected = false; return(new OkResponse()); } catch (MyException e) { return(new ErrorResponse(e.Message)); } } if (request is SaveDonatorRequest) { Console.WriteLine("SaveDonatorRequest ..."); SaveDonatorRequest senReq = (SaveDonatorRequest)request; DonatorDTO mdto = senReq.Add; Donator message = DTOUtils.getFromDTO(mdto); try { lock (server) { server.addDonator(message); } return(new OkResponse()); } catch (MyException e) { return(new ErrorResponse(e.Message)); } } if (request is SaveDonatieRequest) { Console.WriteLine("SaveDonatieRequest ..."); SaveDonatieRequest senReq = (SaveDonatieRequest)request; DonatieDTO mdto = senReq.Add; Donatie message = DTOUtils.getFromDTO(mdto); try { lock (server) { server.addDonatie(message); } return(new OkResponse()); } catch (MyException e) { return(new ErrorResponse(e.Message)); } } if (request is UpdateCazRequest) { Console.WriteLine("UpdateCazRequest ..."); UpdateCazRequest upReq = (UpdateCazRequest)request; CazCaritabilDTO cazDTO = upReq.Caz; CazCaritabil caz = DTOUtils.getFromDTO(cazDTO); try { lock (server) { server.updateCazCaritabil(caz); } return(new OkResponse()); } catch (MyException e) { return(new ErrorResponse(e.Message)); } } return(response); }
public SaveDonatieRequest(DonatieDTO donatie) { this.donatie = donatie; }