Ejemplo n.º 1
0
        public static ProjectViewModel FromEntity(Project entity)
        {
            var entityDetail    = entity.Details.FirstOrDefault();
            var resultViewModel = AutoMapper.Mapper.Map <ProjectViewModel>(entityDetail);

            var projectType = entity.EntityTaxonomies.FirstOrDefault(o => o.Taxonomy.TaxonomyTypeId == ProjectTypeSeed.ProjectType.Id);

            resultViewModel.City = GeographicaLocationViewModel.FromEntity(entity.City);

            resultViewModel.CityId    = entity.CityId;
            resultViewModel.Id        = entity.Id;
            resultViewModel.Name      = entity.Name;
            resultViewModel.BudgetMin = entity.BudgetMin;
            resultViewModel.BudgetMax = entity.BudgetMax;

            resultViewModel.ProjectTypeId = projectType.TaxonomyId;
            resultViewModel.ProjectType   = TaxomonyViewModel.FromEntity(projectType.Taxonomy);

            var projectStatus = entity.EntityTaxonomies.FirstOrDefault(o => o.Taxonomy.TaxonomyTypeId == ProjectStatusSeed.ProjectStatus.Id);

            if (projectStatus != null)
            {
                resultViewModel.ProjectStatusId = projectStatus.TaxonomyId;
                resultViewModel.ProjectType     = TaxomonyViewModel.FromEntity(projectStatus.Taxonomy);
            }

            var avatarFile = entity.EntityFiles.FirstOrDefault(o => o.UsingType == (int)FileUsingType.Avatar).FileEntity;

            resultViewModel.Avatar = FileEntityInfo.FromEntity(avatarFile);

            var locationImage = entity.EntityFiles.FirstOrDefault(o => o.UsingType == (int)FileUsingType.LocationImage)?.FileEntity;

            if (locationImage != null)
            {
                resultViewModel.LocationImage = FileEntityInfo.FromEntity(locationImage);
            }

            var siteMapImage = entity.EntityFiles.FirstOrDefault(o => o.UsingType == (int)FileUsingType.SiteMapImage)?.FileEntity;

            if (locationImage != null)
            {
                resultViewModel.SiteMapImage = FileEntityInfo.FromEntity(siteMapImage);
            }

            resultViewModel.ProjectBlocks = entity.ProjectBlocks.Select(o => ProjectBlockViewModelExtension.FromEnitity(o));

            return(resultViewModel);
        }
Ejemplo n.º 2
0
        public static ProjectViewModelExtended FromEntity(Project entity, ProjectViewModelExtended baseViewModel = null)
        {
            var entityDetail  = entity.ProjectDetails.FirstOrDefault();
            var avatarFile    = entity.EnitityFiles.FirstOrDefault(o => o.UsingType == (int)FileUsingType.Avatar).FileEntity;
            var projectType   = entity.EntityTaxonomies.FirstOrDefault(o => o.Taxonomy.TaxonomyTypeId == ProjectTypeSeed.ProjectType.Id);
            var projectStatus = entity.EntityTaxonomies.FirstOrDefault(o => o.Taxonomy.TaxonomyTypeId == ProjectStatusSeed.ProjectStatus.Id);

            var resultViewModel = baseViewModel ?? new ProjectViewModelExtended();

            resultViewModel.Id   = entity.Id;
            resultViewModel.Name = entity.Name;

            resultViewModel.Title          = entityDetail.Title;
            resultViewModel.Area           = entityDetail.Area;
            resultViewModel.Language       = entityDetail.Language;
            resultViewModel.Street         = entityDetail.Street;
            resultViewModel.StartedYear    = entityDetail.StartedYear;
            resultViewModel.TotalApartment = entityDetail.TotalApartment;
            resultViewModel.Website        = entityDetail.Website;
            resultViewModel.Invertor       = entityDetail.Investor;
            resultViewModel.MapLatitude    = entityDetail.MapLatitude;
            resultViewModel.MapLongitude   = entityDetail.MapLongitude;

            resultViewModel.CityId        = entity.CityId;
            resultViewModel.ProjectTypeId = projectType.TaxonomyId;
            resultViewModel.ProjectType   = TaxomonyViewModel.FromEntity(projectType.Taxonomy);

            if (projectStatus != null)
            {
                resultViewModel.ProjectStatusId = projectStatus.TaxonomyId;
                resultViewModel.ProjectType     = TaxomonyViewModel.FromEntity(projectStatus.Taxonomy);
            }

            resultViewModel.ProjectBlocks = entity.ProjectBlocks.Select(o => ProjectBlockViewModelExtension.FromEnitity(o));

            resultViewModel.Avatar = FileEntityInfo.FromEntity(avatarFile);

            return(resultViewModel);
        }