Exemple #1
0
        public Reader Map(ReaderBusinessModel source)
        {
            if (source == null)
            {
                return(null);
            }

            UserProfileMapper userProfileMapper = new UserProfileMapper();
            TagMapper         tagMapper         = new TagMapper();

            ICollection <Tag> preferences = new List <Tag>();

            //foreach (var tag in source.Preferences)
            //{
            //    preferences.Add(tagMapper.Map(tag));
            //}

            Reader reader = new Reader
            {
                ReaderId    = source.ReaderId,
                FirstName   = source.FirstName,
                LastName    = source.LastName,
                Address     = source.Address,
                Birthday    = source.Birthday,
                Phone       = source.Phone,
                EMail       = source.EMail,
                UserProfile = source.UserProfileBusiness != null?userProfileMapper.Map(source.UserProfileBusiness) : null,
                                  Preferences = preferences
            };

            return(reader);
        }
Exemple #2
0
        public ReaderBusinessModel Map(Reader source)
        {
            if (source == null)
            {
                return(null);
            }

            UserProfileMapper userProfileMapper = new UserProfileMapper();
            TagMapper         tagMapper         = new TagMapper();

            List <TagBusinessModel> preferences = new List <TagBusinessModel>();

            if (source.Preferences != null)
            {
                foreach (var tag in source.Preferences)
                {
                    preferences.Add(tagMapper.Map(tag));
                }
            }

            ReaderBusinessModel readerBusinessInfoModel = new ReaderBusinessModel
            {
                ReaderId            = source.ReaderId,
                FirstName           = source.FirstName,
                LastName            = source.LastName,
                Address             = source.Address,
                Birthday            = source.Birthday,
                Phone               = source.Phone,
                EMail               = source.EMail,
                UserProfileBusiness = source.UserProfile != null?userProfileMapper.Map(source.UserProfile) : null,
                                          Preferences = preferences
            };

            return(readerBusinessInfoModel);
        }
Exemple #3
0
        public DiskBusinessModel Map(Disk source)
        {
            if (source == null)
            {
                return(null);
            }

            DiskBusinessModel disk = new DiskBusinessModel()
            {
                Id       = source.Id,
                Name     = source.Name,
                Producer = source.Producer,
                Type     = source.Type,
                Year     = source.Year,
                Tags     = new Collection <TagBusinessModel>()
            };

            if (source.Tags != null)
            {
                TagMapper tagMapper = new TagMapper();
                foreach (var tag in source.Tags)
                {
                    disk.Tags.Add(tagMapper.Map(tag));
                }
            }
            return(disk);
        }
        public MagazineBusinessModel Map(Magazine source)
        {
            if (source == null)
            {
                return(null);
            }

            MagazineBusinessModel magazine = new MagazineBusinessModel()
            {
                Id        = source.Id,
                Issue     = source.Issue,
                Name      = source.Name,
                PageCount = source.PageCount,
                Publisher = source.Publisher,
                Year      = source.Year
            };

            if (source.Tags != null)
            {
                TagMapper tagMapper = new TagMapper();
                foreach (var tag in source.Tags)
                {
                    magazine.Tags.Add(tagMapper.Map(tag));
                }
            }
            return(magazine);
        }
Exemple #5
0
        public BookWithAuthorsShort Map(Book source)
        {
            if (source == null)
            {
                return(null);
            }

            var destination = new BookWithAuthorsShort
            {
                Id        = source.Id,
                Name      = source.Name,
                Year      = source.Year,
                PageCount = source.PageCount,
                Publisher = source.Publisher,
            };

            var       destTags  = new List <TagBusinessModel>();
            TagMapper tagMapper = new TagMapper();

            foreach (var tag in source.Tags)
            {
                destTags.Add(tagMapper.Map(tag));
            }

            destination.Tags = destTags;

            if (source.Authors != null)
            {
                destination.Authors =
                    source.Authors.Select(a => new AuthorShortInfo {
                    id = a.Id, name = a.FirstName + " " + a.MiddleName + " " + a.LastName
                })
                    .ToList();
            }

            return(destination);
        }
Exemple #6
0
        /// <summary>
        /// Maps the BookBusinessModel instance to the Book instance
        /// </summary>
        /// <param name="source">
        /// The source is of type BookBusinessModel
        /// </param>
        /// <returns>
        /// The <see cref="Book"/>.
        /// </returns>
        public Book Map(BookBusinessModel source)
        {
            if (source == null)
            {
                return(null);
            }

            var destination = new Book
            {
                Id        = source.Id,
                Name      = source.Name,
                Year      = source.Year,
                PageCount = source.PageCount,
                Publisher = source.Publisher
            };

            if (source.Authors != null)
            {
                var authorMapper = new AuthorMapper();
                destination.Authors =
                    source.Authors.Select(
                        a => authorMapper.Map(new AuthorBusinessModel {
                    Id = a.Id, FirstName = a.FirstName, MiddleName = a.MiddleName, LastName = a.LastName
                }))
                    .ToList();
            }

            if (source.Inventories != null)
            {
                var inventoryMapper = new InventoryMapper();
                destination.Inventories =
                    source.Inventories.Select(
                        a =>
                        inventoryMapper.Map(new InventoryBusinessModel {
                    InventoryId = a.InventoryId, IsAvailable = a.IsAvailable
                }))
                    .ToList();
            }

            if (source.ReservedItems != null)
            {
                var reservedBookMapper = new ReservedItemMapper();
                destination.ReservedItems =
                    source.ReservedItems.Select(
                        a =>
                        reservedBookMapper.Map(new ReservedItemBusinessModel {
                    Item = a.Item, Date = a.Date, Id = a.Id, Reader = a.Reader
                }))
                    .ToList();
            }
            if (source.Tags != null)
            {
                var tagMapper = new TagMapper();
                destination.Tags =
                    source.Tags.Select(
                        a => tagMapper.Map(new TagBusinessModel {
                    id = a.id, name = a.name
                }))
                    .ToList();
            }
            return(destination);
        }