Beispiel #1
0
        public static async Task <bool> AddListingImage(int listingId, byte[] imageArray)
        {
            var listingImage = new ListingImageModel
            {
                ListingId = listingId,
                Image     = imageArray
            };

            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();
            var json       = JsonConvert.SerializeObject(listingImage);
            var content    = new StringContent(json, Encoding.UTF8, "application/json");

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("access_token", string.Empty));
            var response = await httpClient.PostAsync($"{_apiUrl}/ListingImage", content);

            if (!response.IsSuccessStatusCode)
            {
                return(false);
            }
            return(true);
        }
Beispiel #2
0
        public HttpResponseMessage DownloadListingInfo(int listingId)
        {
            const string  tabs    = "\t";
            StringBuilder message = new StringBuilder("Listing Information - " + DateTime.Now.ToShortDateString());

            message.AppendFormat("{0}", Environment.NewLine);

            //this is the remaining input on the rooms
            ListingDownloadModel listing = _repository.ListingDownloads.FirstOrDefault(x => x.Id == listingId);

            if (listing != null)
            {
                List <ListingStepsDownloadModel> info = new List <ListingStepsDownloadModel>();
                info.Add(new ListingStepsDownloadModel()
                {
                    StepId = (int)StepType.Bedrooms, Stepname = "Bedrooms", StepItemname = listing.Bedrooms.ToString()
                });
                info.Add(new ListingStepsDownloadModel()
                {
                    StepId = (int)StepType.Bathrooms, Stepname = "Bathrooms Full", StepItemname = listing.BathsFull.ToString()
                });
                info.Add(new ListingStepsDownloadModel()
                {
                    StepId = (int)StepType.Bathrooms, Stepname = "Bathrooms 3/4", StepItemname = listing.BathsThreeQuarter.ToString()
                });
                info.Add(new ListingStepsDownloadModel()
                {
                    StepId = (int)StepType.Bathrooms, Stepname = "Bathrooms 1/2", StepItemname = listing.BathsHalf.ToString()
                });

                //these are the steps and stepitem checkboxes
                info.AddRange(_repository.ListingStepsDownloads.Where(x => x.ListingId == listingId).ToList());

                //these are the steps with "Other" inputs
                info.AddRange(_repository.ListingStepsOtherDownloads.Where(x => x.ListingId == listingId).ToList());


                message.AppendFormat("{0}{1}: {2}", Environment.NewLine, "Agent", listing.AgentName);
                message.AppendFormat("{0}{1}: {2}", Environment.NewLine, "MlsNumber", listing.MlsNumber);
                message.AppendFormat("{0}{1}: {2:M/d/yyyy}", Environment.NewLine, "List date", listing.Listdate);
                message.AppendFormat("{0}{1}: {2}", Environment.NewLine, "Street number", listing.Streetnumber);
                message.AppendFormat("{0}{1}: {2}", Environment.NewLine, "Street name", listing.Streetname);
                message.AppendFormat("{0}{1}: {2}", Environment.NewLine, "Street Designator", listing.StreetDesignator);
                message.AppendFormat("{0}{1}: {2}", Environment.NewLine, "Listing Area", listing.ListingArea);
                message.AppendFormat("{0}{1}: {2}", Environment.NewLine, "Price", listing.Price);
                message.AppendFormat("{0}{1}: {2}", Environment.NewLine, "Square Feet", listing.SquareFeet);
                message.AppendFormat("{0}{1}: {2}", Environment.NewLine, "YearBuilt", listing.YearBuilt);
                message.AppendFormat("{0}{1}: {2}", Environment.NewLine, "Floors", listing.Floors);
                message.AppendFormat("{0}{1}: {2}", Environment.NewLine, "Zoning", listing.Zoning);
                message.AppendFormat("{0}{1}: {2}", Environment.NewLine, "Tractname", listing.Tractname);
                message.AppendFormat("{0}{1}: {2}", Environment.NewLine, "County", listing.County);
                message.AppendFormat("{0}{1}: {2:M/d/yyyy}", Environment.NewLine, "Date Created", listing.DateCreated);

                info = info.OrderBy(x => x.StepId).ToList();

                foreach (ListingStepsDownloadModel item in info)
                {
                    message.AppendFormat("{0}{1}: {2}{3}", Environment.NewLine, item.Stepname, item.StepItemname, item.Text);
                }



                ListingImageModel listingImage = _repository.ListingImages.FirstOrDefault(x => x.ListingId == listingId);
                if (listingImage != null)
                {
                    message.AppendFormat("{0}{0}{1}", Environment.NewLine, "Feature Image");
                    message.AppendFormat("{0}{1}: {2}", Environment.NewLine, "URL", ConvertPathToUrl(listingImage.ImagePath, listingId));
                    message.AppendFormat("{0}{1}: {2}", Environment.NewLine, "Thumbnail", ConvertPathToThumbUrl(listingImage.ImagePath, listingId));
                }

                message.AppendFormat("{0}{0}{1}{0}", Environment.NewLine, "Posts");
                List <ListingPostDownloadModel> postsDownloadModels = _repository.ListingPostDownloads.Where(x => x.ListingId == listingId).ToList();
                foreach (ListingPostDownloadModel post in postsDownloadModels)
                {
                    message.AppendFormat("{0}{1}: {2}", Environment.NewLine, "Title", post.Title);
                    message.AppendFormat("{0}{1}: {2}", Environment.NewLine, "Post", post.Text);
                    message.AppendFormat("{0}{1}: {2}{0}", Environment.NewLine, "URL", ConvertPathToUrl(post.ImagePath, listingId));
                }

                List <ListingImageModel> listingImageVideoList = _repository.ListingImages.Where(x => x.ListingId == listingId && (x.IncludeInVideo.HasValue && x.IncludeInVideo == true)).ToList();
                message.AppendFormat("{0}{0}{1}", Environment.NewLine, "Video Images");
                foreach (ListingImageModel img in listingImageVideoList)
                {
                    message.AppendFormat("{0}{0}{1}", Environment.NewLine, img.Title);
                    message.AppendFormat("{0}{1}: {2}", Environment.NewLine, "URL", ConvertPathToUrl(img.ImagePath, listingId));
                    message.AppendFormat("{0}{1}: {2}", Environment.NewLine, "Thumbnail", ConvertPathToThumbUrl(img.ImagePath, listingId));
                }


                using (MemoryStream ms = new MemoryStream())
                {
                    using (StreamWriter sw = new StreamWriter(ms, Encoding.Unicode))
                    {
                        sw.Write(message.ToString());
                    }
                    byte[] output = new byte[] { };
                    output = ms.ToArray();
                    var result = new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new ByteArrayContent(output)
                    };
                    result.Content.Headers.ContentType        = new MediaTypeHeaderValue("application/octet-stream");
                    result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                    {
                        FileName = listing.AgentName + " Listing.txt"
                    };
                    return(result);
                }
            }
            else
            {
                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(string.Format("Lising Id {0} not found.", listingId))
                });
            }
        }