Ejemplo n.º 1
0
        public void Read(HttpPostedFileBase file)
        {
            if (file != null && file.ContentLength > 0)
            {
                var reader = new BinaryReader(file.InputStream);
                byte[] binData = reader.ReadBytes((int)file.InputStream.Length);
                
                string result = System.Text.Encoding.UTF7.GetString(binData);
                var strings = result.Split('\r','\n').Where(x => !string.IsNullOrWhiteSpace(x));

                foreach (var s in strings)
                {
                    var show = s.Trim();

                    var indexOfFirstSpace = show.IndexOf(' ');

                    var dateStr = show.Substring(0, indexOfFirstSpace);

                    if (dateStr.Length == 6)
                    {
                        dateStr = "20" + dateStr;
                    }
                    var date = DateTime.ParseExact(dateStr, "yyyyMMdd", CultureInfo.InvariantCulture);

                    var showStr = show.Substring(indexOfFirstSpace, show.Length - indexOfFirstSpace).Trim();

                    string artist;
                    if (!showStr.Contains('-'))
                    {
                        artist = showStr;
                        CreateShow(date, artist);
                    }
                    else
                    {
                        var placeAndArtist = showStr.Split('-');
                        artist = placeAndArtist[1].Trim();

                        Venue venue;
                        if (placeAndArtist[0].Contains(','))
                        {
                            var venueAndCity = placeAndArtist[0].Split(',');
                            venue = new Venue
                            {
                                Name = venueAndCity[0],
                                City = venueAndCity[1]
                            };
                        }
                        else
                        {
                            venue = new Venue
                            {
                                Name = placeAndArtist[0].Trim()
                            };
                        }
                        CreateShow(date, artist, venue);    
                    }
                }
            }

        }
Ejemplo n.º 2
0
 private void CreateShow(DateTime date, string artist, Venue venue = null)
 {
     var show = new Concert
     {
         Artist = new Artist { Name = artist },
         Date = date,
         Venue = venue
     };
     _showRepository.Add(show);
 }