예제 #1
0
        //public async Task<string> DownloadMap(DownloadMapModel model)
        public string DownloadMap(DownloadMapModel model)
        {
            var fileName = $"announcementMap{model.AnnouncementId}.jpg";
            var dest     = fileName.GetDestFileName();

            dest = FilesUtilities.GetRelativePath(dest, UploadType.AnnouncementPhoto, model.AnnouncementId);
            var newFile = Path.Combine(_webRootPath, dest);

            newFile = newFile.SlashConverter();
            Path.GetDirectoryName(newFile).CreateDirectory();
            var webRequest = WebRequest.Create(model.Url);

            webRequest.Method      = "GET";
            webRequest.ContentType = "image/png";
            var webResponse = webRequest.GetResponse();
            var stream      = webResponse.GetResponseStream();

            using (var fileStream = new FileStream(newFile, FileMode.Create, FileAccess.Write))
            {
                stream?.CopyTo(fileStream);
            }
            //await Callback(Path.GetFileName(newFile), model.AnnouncementId, AttachmentType.OtherImages);

            return(!model.IsRelativeRequested ? Path.GetFileName(dest) : dest);
        }
예제 #2
0
        public async Task <string> DownloadMap(DownloadMapModel model)
        {
            var serializedModel = Utilities.SerializeObject(model);
            var content         = new StringContent(serializedModel, Encoding.UTF8, "application/json");

            using (var client = new HttpClient())
            {
                var response = await client.PostAsync($"{ConstValues.MediaBaseUrl}{ConstValues.DownloadMap}", content);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    return(null);
                }
                var serialized = await response.Content.ReadAsStringAsync();

                var deserialized = JsonConvert.DeserializeObject <ServiceResult>(serialized);
                return(!deserialized.Success ? null : deserialized.Data.ToString());
            }
        }
예제 #3
0
 public IActionResult DownloadMap([FromBody] DownloadMapModel model)
 {
     return(MakeActionCallWithModel(() => _service.DownloadMap(model), model));
 }