Beispiel #1
0
        public static Voluntar getFromDTO(VoluntarDTO voldto)
        {
            int    id   = voldto.Id;
            string pass = voldto.Parola;

            return(new Voluntar(id, pass));
        }
Beispiel #2
0
 public static VoluntarDTO[] getDTO(Voluntar[] voluntari)
 {
     VoluntarDTO[] frDTO = new VoluntarDTO[voluntari.Length];
     for (int i = 0; i < voluntari.Length; i++)
     {
         frDTO[i] = getDTO(voluntari[i]);
     }
     return(frDTO);
 }
Beispiel #3
0
        public virtual void logout(Voluntar voluntar, IObserver client)
        {
            VoluntarDTO udto = DTOUtils.getDTO(voluntar);

            sendRequest(new LogoutRequest(udto));
            Response response = readResponse();

            closeConnection();
            if (response is ErrorResponse)
            {
                ErrorResponse err = (ErrorResponse)response;
                throw new MyException(err.Message);
            }
        }
Beispiel #4
0
        public virtual void login(Voluntar voluntar, IObserver client)
        {
            initializeConnection();
            VoluntarDTO vdto = DTOUtils.getDTO(voluntar);

            sendRequest(new LoginRequest(vdto));
            Response response = readResponse();

            if (response is OkResponse)
            {
                this.client = client;

                return;
            }
            if (response is ErrorResponse)
            {
                ErrorResponse err = (ErrorResponse)response;
                closeConnection();
                throw new MyException(err.Message);
            }
        }
Beispiel #5
0
        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);
        }