Esempio n. 1
0
        public static DetailsViewModel DtoMapper <T>(T entity)
        {
            Type             dtoType          = typeof(T);
            DetailsViewModel detailsViewModel = new DetailsViewModel();
            var properties = dtoType.GetProperties();

            foreach (var property in properties)
            {
                if (property.HasAttribute <DetailsOrderAttribute>())
                {
                    var attribute = property.GetAttribute <DetailsOrderAttribute>();
                    int order     = attribute.Order;
                    DetailsPropertyViewModel detailsProperty = new DetailsPropertyViewModel();
                    detailsProperty.Name  = string.IsNullOrEmpty(attribute.Title) ? StringFunctions.SplitWordsByCapitalLetters(property.Name) : attribute.Title;
                    detailsProperty.Value = property.GetValue(entity);
                    detailsProperty.Type  = TableCellType.Text;
                    if (property.GetCustomAttributes(typeof(TableCellAttribute), false).Length > 0)
                    {
                        detailsProperty.Type = ((TableCellAttribute)property.GetCustomAttributes(typeof(TableCellAttribute), false).FirstOrDefault()).Type;
                    }

                    detailsViewModel.AddProperty(detailsProperty, order);
                }
            }

            return(detailsViewModel);
        }
Esempio n. 2
0
        public void Initialize(FileViewModel fileViewModel, FilePropertiesDto dto, ITargetedRestClient restClient)
        {
            var properties = GeneralPropertyViewModel.CreateFileProperties(fileViewModel, dto).ToList();

            GeneralProperties = CreateGeneralProperties(properties);
            Entry             = fileViewModel;
            DetailsViewModel  = new DetailsPropertyViewModel(dto.Properties);

            if (!Entry.IsDirectory)
            {
                HashViewModels = Enum.GetValues(typeof(FileHashAlgorithm)).Cast <FileHashAlgorithm>()
                                 .Select(x => new ComputeHashViewModel(Entry.Source.Path, x, restClient)).ToList();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Map entities to <see cref="DetailsViewModel"/> by using the decorated properties of the view model entity implementation by <seealso cref="DetailsFieldAttribute"/>.
        /// </summary>
        /// <typeparam name="T">ViewModel entity implementation.</typeparam>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static DetailsViewModel Map <T>(T entity)
        {
            Type             dtoType          = typeof(T);
            DetailsViewModel detailsViewModel = new DetailsViewModel();
            var properties = dtoType.GetProperties();

            foreach (var property in properties)
            {
                if (property.HasAttribute <DetailsFieldAttribute>())
                {
                    var attribute = property.GetAttribute <DetailsFieldAttribute>();
                    int order     = attribute.Order;
                    DetailsPropertyViewModel detailsProperty = new DetailsPropertyViewModel();
                    detailsProperty.Name  = string.IsNullOrEmpty(attribute.Title) ? StringFunctions.SplitWordsByCapitalLetters(property.Name) : attribute.Title;
                    detailsProperty.Value = property.GetValue(entity);
                    detailsProperty.DetailsFieldElement = (IDetailsFieldElement)Activator.CreateInstance(attribute.UIElementType);
                    detailsProperty.Order = order;
                    detailsViewModel.AddProperty(detailsProperty);
                }
            }

            return(detailsViewModel);
        }
Esempio n. 4
0
 public List <string> Resolve(RentalsInfo source, DetailsPropertyViewModel destination, List <string> member, ResolutionContext context)
 {
     return(source.Property.Images?.Where(i => Math.Abs(i.ImageRatio - 1.5F) < 0.1).Select(i => i.ImagePath).ToList());
 }