Exemple #1
0
        public static ProjectServiceModel FromViewModel(ProjectViewModel viewModel)
        {
            var nestedProjectBlocks = viewModel.ProjectBlocks.Select(o => ProjectBlock.FromViewModel(o));

            nestedProjectBlocks = nestedProjectBlocks.Process((tower) =>
            {
                tower.ProjectId    = viewModel.Id;
                tower.EntityTypeId = EntityTypeSeed.Tower.Id;
                tower.Children     = tower.Children.Process(floor => {
                    floor.EntityTypeId = EntityTypeSeed.Floor.Id;
                    floor.Children     = floor.Children.Process(room =>
                    {
                        room.EntityTypeId = EntityTypeSeed.Room.Id;
                        return(room);
                    }).ToList();
                    return(floor);
                }).ToList();
                return(tower);
            });

            var taxonomyIds = new List <long>();

            if (viewModel.ProjectTypeId != default)
            {
                taxonomyIds.Add(viewModel.ProjectTypeId);
            }
            if (viewModel.ProjectStatusId != default)
            {
                taxonomyIds.Add(viewModel.ProjectStatusId);
            }

            return(new ProjectServiceModel
            {
                Id = viewModel.Id,
                Name = viewModel.Name,
                Detail = new ProjectDetail
                {
                    ProjectId = viewModel.Id,
                    Title = viewModel.Title,
                    Language = viewModel.Language,
                    Area = viewModel.Area,
                    Investor = viewModel.Invertor,
                    StartedYear = viewModel.StartedYear,
                    TotalApartment = viewModel.TotalApartment,
                    Website = viewModel.Website,
                    Street = viewModel.Street,
                    MapLatitude = viewModel.MapLatitude,
                    MapLongitude = viewModel.MapLongitude
                },

                ProjectBlocks = nestedProjectBlocks,
                AvatarFileId = viewModel.Avatar.FileId,
                TaxonomyIds = taxonomyIds,
                CityId = viewModel.CityId,
            });
        }
        public static ProjectServiceModel FromViewModel(ProjectViewModel viewModel)
        {
            var nestedProjectBlocks = viewModel.ProjectBlocks.Select(o => ProjectBlock.FromViewModel(o));

            nestedProjectBlocks = nestedProjectBlocks.Select((tower) =>
            {
                tower.ProjectId    = viewModel.ProjectId;
                tower.EntityTypeId = EntityTypeSeed.RoomType.Id;
                tower.Children     = tower.Children.Select(floor => {
                    floor.EntityTypeId = EntityTypeSeed.RoomLayout.Id;
                    floor.Children     = floor.Children.Select(room =>
                    {
                        room.EntityTypeId = EntityTypeSeed.Perspective.Id;
                        return(room);
                    }).ToList();
                    return(floor);
                }).ToList();
                return(tower);
            });

            var taxonomyIds = new List <long>();

            if (viewModel.ProjectTypeId != default)
            {
                taxonomyIds.Add(viewModel.ProjectTypeId);
            }
            if (viewModel.ProjectStatusId != default)
            {
                taxonomyIds.Add(viewModel.ProjectStatusId);
            }

            var projectName = viewModel.Title.ToEntityName();

            return(new ProjectServiceModel
            {
                Id = viewModel.ProjectId,
                Name = projectName,
                Detail = AutoMapper.Mapper.Map <ProjectDetail>(viewModel),
                ProjectBlocks = nestedProjectBlocks,
                BudgetMin = viewModel.BudgetMin,
                BudgetMax = viewModel.BudgetMax,
                AvatarFileId = viewModel.Avatar.FileId,
                LocationImageId = viewModel.LocationImage.FileId,
                SiteMapImageId = viewModel.SiteMapImage.FileId,

                TaxonomyIds = taxonomyIds,
                CityId = viewModel.CityId,
            });
        }