예제 #1
0
        public static CazCaritabil getFromDTO(CazCaritabilDTO cazDTO)
        {
            int    id         = cazDTO.Id;
            string denumire   = cazDTO.Denumire;
            double sumaTotala = cazDTO.SumaTotala;

            return(new CazCaritabil(id, denumire, sumaTotala));
        }
예제 #2
0
 public static CazCaritabilDTO[] getDTO(CazCaritabil[] cazuri)
 {
     CazCaritabilDTO[] frDTO = new CazCaritabilDTO[cazuri.Length];
     for (int i = 0; i < cazuri.Length; i++)
     {
         frDTO[i] = getDTO(cazuri[i]);
     }
     return(frDTO);
 }
예제 #3
0
        public void updateCazCaritabil(CazCaritabil nou)
        {
            CazCaritabilDTO newDTO = DTOUtils.getDTO(nou);

            sendRequest(new UpdateCazRequest(newDTO));
            Response response = readResponse();

            if (response is ErrorResponse)
            {
                ErrorResponse err = (ErrorResponse)response;
                throw new MyException(err.Message);
            }
        }
예제 #4
0
        public void updateSC(CazCaritabil caz)
        {
            CazCaritabilDTO dto = DTOUtils.getDTO(caz);

            Console.WriteLine("CazCaritabil received  " + caz);
            try
            {
                sendResponse(new UpdateCazResponse(dto));
            }
            catch (Exception e)
            {
                throw new MyException("Sending error: " + e);
            }
        }
 public UpdateCazResponse(CazCaritabilDTO2 caz)
 {
     this.caz = caz;
 }
예제 #6
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);
        }
 public UpdateCazRequest(CazCaritabilDTO caz)
 {
     this.caz = caz;
 }