Ejemplo n.º 1
0
        public async Task <bool> Upload(IFormFile formFile)
        {
            // full path to file in temp location
            var filePath = Path.GetTempFileName();

            if (formFile.Length > 0)
            {
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    await formFile.CopyToAsync(stream);

                    string content = String.Empty;

                    using (StreamReader streamReader = new StreamReader(stream, Encoding.UTF8))
                    {
                        stream.Seek(0, SeekOrigin.Begin);

                        while ((content = streamReader.ReadLine()) != null)
                        {
                            cities.Add(content.Trim());
                        }
                    }
                }
            }

            foreach (var city in cities)
            {
                if (Startup.OpenAPIIdMappings.ContainsKey(city))
                {
                    listCityIds.Add(Startup.OpenAPIIdMappings[city]);
                }
                else
                {
                    return(false);
                }
            }

            var resultString = _apiCient.APICall(cities);

            if (String.IsNullOrEmpty(resultString))
            {
                return(false);
            }

            GenerateFiles(resultString);

            return(true);
        }