Beispiel #1
0
        /// <summary>
        /// Map entity to dto
        /// </summary>
        /// <param name="entity">Object to extension</param>
        /// <param name="addAuthors">Indicate if add authors data in dto</param>
        /// <param name="useLazy">Indicate if load related data in dto</param>
        public static UserDto Map(this User entity, bool addAuthors, bool useLazy)
        {
            if (entity == null)
            {
                return(null);
            }

            UserDto dto = new UserDto();

            if (entity.Valid)
            {
                dto.Id = entity.Id;
                if (addAuthors)
                {
                    AuthorMap.Map(dto, entity);
                }
            }
            else
            {
                dto.AddNotifications(entity.Notifications);
            }

            dto.Document = entity.Document;
            dto.Name     = entity.Name;
            dto.BornDate = entity.BornDate;
            dto.Email    = entity.Email.Address;
            dto.IsActive = entity.IsActive;
            dto.Type     = entity.Type;

            if (useLazy)
            {
                LoadLazy(entity, dto);
            }

            return(dto);
        }