Esempio n. 1
0
 internal static MusicDocument Map(MusicAddRequest request)
 {
     return(new MusicDocument
     {
         Album = request.Album,
         Artist = request.Artist,
         ArtistAlphabetIndex = MusicHelper.CalculateAlphabetIndex(artistFirstChar: request.Artist[0]),
         IsFavorite = request.IsFavorite,
         Length = request.Length,
         Path = request.Path,
         Title = request.Title,
         CreatedDate = DateTime.UtcNow,
         UpdatedDate = DateTime.UtcNow
     });
 }
Esempio n. 2
0
        public static UpdateDefinition <MusicDocument> BuildUpdateQuery(IMusicUpdateQuery query)
        {
            List <UpdateDefinition <MusicDocument> > updates = new List <UpdateDefinition <MusicDocument> >();

            if (!string.IsNullOrEmpty(query.Album))
            {
                updates.Add(updateBuilder.Set(m => m.Album, query.Album));
            }

            if (!string.IsNullOrEmpty(query.Artist))
            {
                updates.Add(updateBuilder.Set(m => m.Artist, query.Artist));
                updates.Add(updateBuilder.Set(m => m.ArtistAlphabetIndex, MusicHelper.CalculateAlphabetIndex(artistFirstChar: query.Artist[0])));
            }

            if (query.Length > 0)
            {
                updates.Add(updateBuilder.Set(m => m.Length, query.Length));
            }

            if (!string.IsNullOrEmpty(query.Path))
            {
                updates.Add(updateBuilder.Set(m => m.Path, query.Path));
            }

            if (!string.IsNullOrEmpty(query.Title))
            {
                updates.Add(updateBuilder.Set(m => m.Title, query.Title));
            }

            if (query.IsFavorite.HasValue)
            {
                updates.Add(updateBuilder.Set(m => m.IsFavorite, query.IsFavorite));
            }

            if (updates.Any())
            {
                updates.Add(updateBuilder.Set(m => m.UpdatedDate, DateTime.UtcNow));
            }

            return(updates.Any() ? updateBuilder.Combine(updates) : null);
        }