public void AdaugaRezervare(int cursaCurenta, string numeAdaugare, string prenumeAdaugare, int numarLocuriAdaugare)
 {
     try
     {
         _server.AdaugaRezervare(cursaCurenta, numeAdaugare, prenumeAdaugare, numarLocuriAdaugare);
     }
     catch (AppException e)
     {
         throw e;
     }
 }
Beispiel #2
0
        private IResponse HandleRequest(IRequest request)
        {
            IResponse response = null;

            if (request is LoginRequest)
            {
                Console.WriteLine("Login request...");
                var loginRequest = (LoginRequest)request;
                var personalDTO  = loginRequest.PersonalDto;
                var personal     = DTOUtils.GetFromDTO(personalDTO);

                try
                {
                    lock (_server)
                    {
                        _server.Login(personal, this);
                    }
                    return(new OkResponse());
                }
                catch (AppException e)
                {
                    _connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetCurseRequest)
            {
                Console.WriteLine("Get curse request...");
                var req  = (GetCurseRequest)request;
                var pers = req.PersonalDto;
                try
                {
                    Cursa[] curse;
                    lock (_server)
                    {
                        curse = _server.GetAllCurse(DTOUtils.GetFromDTO(pers));
                    }

                    var curseDTO = DTOUtils.GetFromDTO(curse);
                    return(new GetCurseResponse(curseDTO));
                }
                catch (AppException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetDestinatiiRequest)
            {
                Console.WriteLine("Get destinatii request...");
                var req = (GetDestinatiiRequest)request;
                try
                {
                    Destinatie[] destinatii;
                    lock (_server)
                    {
                        destinatii = _server.GetAllDestinatii();
                    }

                    var destinatieDTO = DTOUtils.GetFromDTO(destinatii);
                    return(new GetDestinatiiResponse(destinatieDTO));
                }
                catch (AppException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetLocuriRequest)
            {
                Console.WriteLine("Get locuri request...");
                var req = (GetLocuriRequest)request;
                try
                {
                    Loc[] locuri;
                    lock (_server)
                    {
                        locuri = _server.GetLocuri(req.IdCursa);
                    }

                    var locuriDTO = DTOUtils.GetFromDTO(locuri);
                    return(new GetLocuriResponse(locuriDTO));
                }
                catch (AppException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is FindCursaRequest)
            {
                Console.WriteLine("Get cursa pt detalii request...");
                var req = (FindCursaRequest)request;
                try
                {
                    Cursa cursa = new Cursa();
                    lock (_server)
                    {
                        cursa = _server.FindCursa(req.Data, DTOUtils.GetFromDTO(req.Destinatie));
                    }

                    return(new FindCursaResponse(new CursaDTO(cursa.Id, cursa.DataPlecare, cursa.LocPlecare, cursa.NrLocuriDisponibile, cursa.IdDestinatie)));
                }
                catch (AppException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is AddRezervareRequest)
            {
                Console.WriteLine("adauga o rezervare request...");
                var req = (AddRezervareRequest)request;
                try
                {
                    lock (_server)
                    {
                        _server.AdaugaRezervare(req.AdaugaRezervareDto.IdCursa, req.AdaugaRezervareDto.Nume, req.AdaugaRezervareDto.Prenume, req.AdaugaRezervareDto.NrLocuri);
                    }

                    return(new OkResponse());
                }
                catch (AppException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            return(response);
        }