Exemple #1
0
        public ProjectVM GetProjectById(int?id)
        {
            var project   = id.HasValue ? _projects.FindById(id.Value) : _projects.FirstOrDefault();
            var projectVM = Map <Project, ProjectVM>(project);

            projectVM.ProjectSections = _projectSections.GetSectionsByProjectId(project.Id).Select(x => new ProjectSectionVM
            {
                Id          = x.Id,
                ProjectName = project.ProjectName,
                SectionName = x.SectionName,
                Description = x.Description,
                Images      = _projectSectionImages.GetSectionImagesBySectionId(x.Id).Select(i => new ProjectSectionImageVM {
                    Id = i.Id, Image = i.Image
                })
            }).ToList();
            return(projectVM);
        }
Exemple #2
0
        public ProjectBLL(IDbConnection connection)
        {
            _projects             = new ProjectDao(connection);
            _projectSections      = new ProjectSectionDao(connection);
            _projectSectionImages = new ProjectSectionImageDao(connection);

            Mapper = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <ProjectSectionImageVM, ProjectSectionImage>();
                cfg.CreateMap <ProjectSectionImage, ProjectSectionImageVM>();
                cfg.CreateMap <ProjectSection, ProjectSectionVM>().AfterMap((m, vm) =>
                {
                    vm.Images = _projectSectionImages.GetSectionImagesBySectionId(m.Id).Select(x => new ProjectSectionImageVM {
                        Id = x.Id, Image = x.Image
                    });
                    vm.ProjectName = _projects.FindById(m.ProjectId)?.ProjectName;
                });
                cfg.CreateMap <ProjectSectionVM, ProjectSection>();
                cfg.CreateMap <Project, ProjectVM>();
                cfg.CreateMap <ProjectVM, Project>();
            }).CreateMapper();
        }