Esempio n. 1
0
        public ServiceResponse PostFile()
        {
            return(new ServiceResponse("Poiler yüklenemedi",
                                       delegate()
            {
                var httpRequest = HttpContext.Current.Request;
                if (httpRequest.Files.Count == 1)
                {
                    var postedFile = httpRequest.Files[0];
                    string extension = postedFile.FileName.Split('.').Last();
                    if (extension != "csv")
                    {
                        return "Lütfen bir .csv dosyası seçiniz!";
                    }
                    CultureInfo ci = new CultureInfo("en-US");

                    var str = new StreamReader(postedFile.InputStream, Encoding.Default).ReadToEnd().Replace("\r", "");
                    var lines = str.Split(new string[1] {
                        "\n"
                    }, StringSplitOptions.None);
                    var keys = lines[0].Split(new string[1] {
                        "\n"
                    }, StringSplitOptions.None);
                    for (int i = 1; i < lines.Length; i++)
                    {
                        var temp = lines[i].Split(';');
                        Category cat = m_CategoryOperations.GetCategory(temp[1]) as Category;
                        if (cat == null)
                        {
                            cat = new Category()
                            {
                                IconID = 1,
                                ListOrder = 999,
                                RenderOrder = 999,
                                Name = temp[1]
                            };
                            cat = m_CategoryOperations.CreateCategory(cat) as Category;
                        }
                        Poi poi = new Poi();
                        poi.CustomID = temp[0];
                        poi.CategoryID = cat.ID;
                        poi.ProvinceID = Int32.Parse(temp[2], ci);
                        poi.DistrictID = Int32.Parse(temp[3], ci);
                        poi.NeighborhoodID = Int32.Parse(temp[4], ci);
                        poi.TableName = temp[5];
                        poi.Longitude = double.Parse(temp[6].Replace(',', '.'), ci);
                        poi.Longitude = double.Parse(temp[7].Replace(',', '.'), ci);
                        poi.Address = temp[8];
                        m_PoiOperations.CreatePoi(poi);
                    }

                    return "";
                }
                else
                {
                    return "Lütfen bir dosya seçiniz";
                }
            }));
        }