Beispiel #1
0
        private static MusicBrainzReleaseEvent Map(DataContext context, JsonMusicBrainzRequest.Release.ReleaseEvent json)
        {
            DateTime?parsedDate = DateTimeParserPipe.Process(json.Date);

            MusicBrainzReleaseEvent events = new MusicBrainzReleaseEvent
            {
                Date   = parsedDate
                , Area = null == json.Area ? null : Map(context, json.Area)
            };

            events.UniqueHash = Comparator.ComputeContentHash(events);

            MusicBrainzReleaseEvent dbEvent =
                context.SetReleaseEvents.FirstOrDefault(x => x.UniqueHash.Equals(events.UniqueHash));

            if (null != dbEvent)
            {
                // already in db
                return(dbEvent);
            }

            context.SetReleaseEvents.Add(events);
            context.SaveChanges();

            return(events);
        }
Beispiel #2
0
 private static MusicBrainzReleaseEventMusicBrainzRelease NewShadow(MusicBrainzRelease release
                                                                    , MusicBrainzReleaseEvent releaseEvent)
 {
     return(new MusicBrainzReleaseEventMusicBrainzRelease
     {
         MusicBrainzRelease = release
         , MusicBrainzReleaseUniqueId = release.UniqueId
         , MusicBrainzReleaseEvent = releaseEvent
         , MusicBrainzReleaseEventUniqueId = releaseEvent.UniqueId
     });
 }
 public static Dictionary <String, Object> ToJsonDictionary(this MusicBrainzReleaseEvent revent)
 {
     return(new Dictionary <String, Object>
     {
         {
             "UniqueId", revent.UniqueId
         }
         ,
         {
             "Date", revent.Date
         }
         ,
         {
             "Area", new Dictionary <String, Object>
             {
                 {
                     "UniqueId", revent.Area?.UniqueId
                 }
                 ,
                 {
                     "Name", revent.Area?.Name
                 }
                 ,
                 {
                     "Disambiguation", revent.Area?.Disambiguation
                 }
                 ,
                 {
                     "SortName", revent.Area?.SortName
                 }
                 ,
                 {
                     "IsoCodes", revent.Area?.MusicBrainzIsoCodeMusicBrainzAreas.Select(x
                                                                                        => new Dictionary <String, Object>
                     {
                         {
                             "UniqueId", x.MusicBrainzIsoCode.UniqueId
                         }
                         ,
                         {
                             "Code", x.MusicBrainzIsoCode.Code
                         }
                     })
                 }
             }
         }
     });
 }