/// <summary>
        /// Sends an API request over http to the server running the Company Review Service to save a new customer review
        /// </summary>
        /// <param name="request">Request Information</param>
        /// <returns>The response from the server</returns>
        public ServiceBusResponse saveCompanyReview(SaveCompanyReviewRequest request)
        {
            MemoryStream memStream = new MemoryStream();
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(SaveCompanyReviewRequest));

            serializer.WriteObject(memStream, request);

            string jsonEndodedObject = Encoding.ASCII.GetString(memStream.ToArray());

            string path = $"SaveCompanyReview/{jsonEndodedObject}";
            //string path = $"GetCompanyReviews/{request.getCompanyName()}";
            HttpResponseMessage response;

            try
            {
                response = webCaller.GetAsync(path).GetAwaiter().GetResult();
            }
            catch (HttpRequestException e)
            {
                return(new ServiceBusResponse(false, "Could not connect to service API. Error messsage: " + e.Message));
            }

            if (response.IsSuccessStatusCode == true)
            {
                return(new ServiceBusResponse(true, "Success"));
            }
            return(new ServiceBusResponse(false, "Error code:" + response.StatusCode.ToString() + " Error Message:" + response.Content));
        }
        private ServiceBusResponse saveReview(SaveCompanyReviewRequest saveRequest)
        {
            SendOptions sendOptions = new SendOptions();

            sendOptions.SetDestination("CompanyListings");
            return(requestingEndpoint.Request <ServiceBusResponse>(saveRequest, sendOptions).ConfigureAwait(false).GetAwaiter().GetResult());
        }
        /// <summary>
        /// Makes a request to the Company Review Service to save a new Customer Review
        /// </summary>
        /// <param name="request">Request Information</param>
        /// <returns>The response from the service</returns>
        private ServiceBusResponse saveNewReview(SaveCompanyReviewRequest request)
        {
            if (authenticated == false)
            {
                return(new ServiceBusResponse(false, "Must be logged in to use the Company Directory Service"));
            }

            SendOptions sendOptions = new SendOptions();

            sendOptions.SetDestination("CompanyReview");

            return(requestingEndpoint.Request <ServiceBusResponse>(request, sendOptions)
                   .ConfigureAwait(false).GetAwaiter().GetResult());
        }
        public ActionResult SaveReview(string textUserReview, string rating, string companyName)
        {
            if (Globals.isLoggedIn() == false)
            {
                return(RedirectToAction("Index", "Authentication"));
            }
            ServiceBusConnection connection = ConnectionManager.getConnectionObject(Globals.getUser());

            if (connection == null)
            {
                return(RedirectToAction("Index", "Authentication"));
            }

            ReviewInstance review = new ReviewInstance(companyName, textUserReview, Convert.ToInt32(rating),
                                                       DateTimeOffset.Now.ToUnixTimeSeconds(), Globals.getUser());
            SaveCompanyReviewRequest  request  = new SaveCompanyReviewRequest(review);
            SaveCompanyReviewResponse response = connection.saveCompanyReview(request);

            return(RedirectToAction("DisplayCompany", new { id = companyName }));
        }
Exemple #5
0
        public ActionResult WriteReview(string company = "", string userReview = "", int timestamp = -1, int stars = -1)
        {
            if (Globals.isLoggedIn() == false ||
                company == "" || userReview == "" ||
                timestamp == -1 || stars == -1)
            {
                return(RedirectToAction("Index", "Authentication"));
            }

            ServiceBusConnection connection = ConnectionManager.getConnectionObject(Globals.getUser());

            if (connection == null)
            {
                return(RedirectToAction("Index", "Authentication"));
            }

            SaveCompanyReviewRequest request = new SaveCompanyReviewRequest(new CustomerReview(company, Globals.getUser(), userReview, stars, timestamp));

            ServiceBusResponse response = connection.saveCompanyReview(request);

            return(null);
        }
 /// <summary>
 /// Makes a request to the service bus to save a review of a company
 /// </summary>
 /// <param name="request">The request object, contains information needed to save the review</param>
 /// <returns>The response from the service bus</returns>
 public ServiceBusResponse saveCompanyReview(SaveCompanyReviewRequest request)
 {
     send(request);
     return(readUntilEOF());
 }
Exemple #7
0
 public SaveCompanyReviewResponse saveCompanyReview(SaveCompanyReviewRequest saveComRequest)
 {
     send(saveComRequest);
     return((SaveCompanyReviewResponse)readUntilEOF());
 }