public Booking GetBookingById(string id)
        {
            Booking booking = new Booking();
            int     idConverted;
            bool    success = int.TryParse(id, out idConverted);

            if (success == false)
            {
                throw new WebFaultException <string>("Please input a number instead ", HttpStatusCode.BadRequest);
            }

            try
            {
                booking = dataBaseRepository.GetBookingById(idConverted);
            }
            catch (Exception ex)
            {
                SaveException.Log("webErrors.txt", ex);
                throw new WebFaultException <string>("Sorry something went wrong when trying to get booking from Database ", HttpStatusCode.InternalServerError);
            }
            if (booking == null)
            {
                throw new WebFaultException <string>("Sorry no booking found at position " + id, HttpStatusCode.InternalServerError);
            }

            return(booking);
        }
Exemplo n.º 2
0
        // Place to add logging of faults that occurs this is an async call, will not be a performance problem
        // I chosed to just dump into a file the prefered method for real projects is probably to
        // make the dump into a database table
        public bool HandleError(Exception error)
        {
            Exception ex = error;

            SaveException.Log(@"Error.txt", ex);

            return(true);
        }
 public void AddCustomer(CustomerInfo customer)
 {
     try
     {
         dataBaseRepository.AddCustomer(customer);
     }
     catch (Exception ex)
     {
         SaveException.Log("webErrors.txt", ex);
         throw new WebFaultException <string>("Sorry something went wrong when trying to add customer to Database ", HttpStatusCode.InternalServerError);
     }
 }
 public List <Car> GetAvaliableCars(string starttime, string stoptime)
 {
     try
     {
         return(dataBaseRepository.AvaliableCars(Convert.ToDateTime(starttime), Convert.ToDateTime(stoptime)));
     }
     catch (Exception ex)
     {
         SaveException.Log("webErrors.txt", ex);
         throw new WebFaultException <string>("Sorry something went wrong when trying to get a list of cars from Database", HttpStatusCode.InternalServerError);
     }
 }
 public void RemoveCustomer(CustomerRequest customerRequest)
 {
     try
     {
         dataBaseRepository.RemoveCustomer(customerRequest);
     }
     catch (FaultException ex)
     {
         throw new WebFaultException <string>(ex.Reason.ToString(), HttpStatusCode.BadRequest);
     }
     catch (Exception ex)
     {
         SaveException.Log("webErrors.txt", ex);
         throw new WebFaultException <string>("Sorry something went wrong when trying to remove customer from Database", HttpStatusCode.InternalServerError);
     }
 }
        public void RemoveBookingById(string id)
        {
            int  idConverted;
            bool success = int.TryParse(id, out idConverted);

            if (success == false)
            {
                throw new WebFaultException <string>("Please input a number instead ", HttpStatusCode.BadRequest);
            }

            try
            {
                dataBaseRepository.RemoveBookingById(idConverted);
            }
            catch (Exception ex)
            {
                SaveException.Log("webErrors.txt", ex);
                throw new WebFaultException <string>("Sorry something went wrong when trying to delete at position " + id, HttpStatusCode.InternalServerError);
            }
        }
        public CustomerInfo GetCustomer(string customerId, string license)
        {
            int  id;
            bool success = int.TryParse(customerId, out id);

            if (success == false)
            {
                throw new WebFaultException <string>("Please input a number instead ", HttpStatusCode.BadRequest);
            }

            CustomerInfo    customerInfo    = new CustomerInfo();
            CustomerRequest customerRequest = new CustomerRequest();

            customerRequest.LicenseKey = license;
            customerRequest.CustomerId = id;

            try
            {
                customerInfo = dataBaseRepository.GetCustomer(customerRequest);
            }
            catch (FaultException ex)
            {
                throw new WebFaultException <string>(ex.Reason.ToString(), HttpStatusCode.BadRequest);
            }
            catch (Exception ex)
            {
                SaveException.Log("webErrors.txt", ex);
                throw new WebFaultException <string>("Sorry something went wrong when trying to get customer from Database ", HttpStatusCode.InternalServerError);
            }
            if (customerInfo == null)
            {
                throw new WebFaultException <string>("Sorry no customer found at position " + customerId, HttpStatusCode.InternalServerError);
            }

            return(customerInfo);
        }