Ejemplo n.º 1
0
        public async Task <ViewModels.BookDto> GetBookDto(int id)
        {
            var book   = new ViewModels.BookDto();
            var dbbook = await context.Books.FirstOrDefaultAsync(q => q.Id == id);

            ViewModels.BookDto.FillDto(dbbook, book);
            var dbbookfiles = await this.context.ViewBookFiles.Where(q => q.BookId == id).ToListAsync();

            book.BookFiles = new List <ViewBookFileX>();
            foreach (var x in dbbookfiles)
            {
                var bf = new ViewBookFileX();
                ViewBookFileX.FillDto(x, bf);
                book.BookFiles.Add(bf);
            }

            book.BookKeywords = await context.BookKeywords.Where(q => q.BookId == id).Select(q => q.Value).ToListAsync();

            book.BookAuthors = await context.BookAutors.Where(q => q.BookId == id).Select(q => q.PersonMiscId).ToListAsync();

            book.BookRelatedAircraftTypes = (await(from x in context.BookRelatedAircraftTypes
                                                   join y in context.ViewAircraftTypes on x.AircraftTypeId equals y.Id
                                                   where x.BookId == id
                                                   select y).ToListAsync()).Select(q => new ViewModels.AircraftType()
            {
                Id             = q.Id,
                Manufacturer   = q.Manufacturer,
                ManufacturerId = q.ManufacturerId,
                Remark         = q.Remark,
                Type           = q.Type
            }).ToList();


            book.BookRelatedEmployees = (await(from x in context.BookRelatedEmployees
                                               join y in context.ViewEmployees on x.EmployeeId equals y.Id
                                               where x.BookId == id
                                               select y).ToListAsync()).Select(q => new ViewModels.EmployeeView()
            {
                Name            = q.Name,
                NID             = q.NID,
                PID             = q.PID,
                Location        = q.Location,
                CaoCardNumber   = q.CaoCardNumber,
                NDTNumber       = q.NDTNumber,
                DateJoinCompany = q.DateJoinCompany,
                Id   = q.Id,
                IDNo = q.IDNo,
            }).ToList();
            book.BookRelatedGroups = (await(from x in context.BookRelatedGroups
                                            join y in context.ViewJobGroups on x.GroupId equals y.Id
                                            where x.BookId == id
                                            select y).ToListAsync()).Select(q => new ViewModels.JobGroup()
            {
                Title    = q.Title,
                FullCode = q.FullCode,
                Remark   = q.Remark,
                Parent   = q.Parent,
                Id       = q.Id,
            }).ToList();
            book.BookRelatedStudyFields = (await(from x in context.BookRelatedStudyFields
                                                 join y in context.ViewOptions on x.StudyFieldId equals y.Id
                                                 where x.BookId == id
                                                 select y).ToListAsync()).Select(q => new ViewModels.Option()
            {
                Title = q.Title,

                Parent = q.Parent,
                Id     = q.Id,
            }).ToList();


            return(book);
        }
Ejemplo n.º 2
0
        public async Task <ViewModels.BookDto> GetEmployeeBookDto(int id, int employeeId)
        {
            var book   = new ViewModels.BookDto();
            var dbbook = await context.ViewBookApplicableEmployees.FirstOrDefaultAsync(q => q.BookId == id && q.EmployeeId == employeeId);

            ViewModels.BookDto.FillDto(dbbook, book);
            var dbbookfiles = await this.context.ViewBookFiles.Where(q => q.BookId == id).ToListAsync();

            book.BookFiles = new List <ViewBookFileX>();
            foreach (var x in dbbookfiles)
            {
                var bf = new ViewBookFileX();
                ViewBookFileX.FillDto(x, bf);
                book.BookFiles.Add(bf);
            }

            //book.BookKeywords = await context.BookKeywords.Where(q => q.BookId == id).Select(q => q.Value).ToListAsync();
            //book.BookAuthors = await context.BookAutors.Where(q => q.BookId == id).Select(q => q.PersonMiscId).ToListAsync();

            //book.BookRelatedAircraftTypes = (await (from x in context.BookRelatedAircraftTypes
            //                                        join y in context.ViewAircraftTypes on x.AircraftTypeId equals y.Id
            //                                        where x.BookId == id
            //                                        select y).ToListAsync()).Select(q => new ViewModels.AircraftType()
            //                                        {
            //                                            Id = q.Id,
            //                                            Manufacturer = q.Manufacturer,
            //                                            ManufacturerId = q.ManufacturerId,
            //                                            Remark = q.Remark,
            //                                            Type = q.Type
            //                                        }).ToList();


            //book.BookRelatedEmployees = (await (from x in context.BookRelatedEmployees
            //                                    join y in context.ViewEmployees on x.EmployeeId equals y.Id
            //                                    where x.BookId == id
            //                                    select y).ToListAsync()).Select(q => new ViewModels.EmployeeView()
            //                                    {
            //                                        Name = q.Name,
            //                                        NID = q.NID,
            //                                        PID = q.PID,
            //                                        Location = q.Location,
            //                                        CaoCardNumber = q.CaoCardNumber,
            //                                        NDTNumber = q.NDTNumber,
            //                                        DateJoinCompany = q.DateJoinCompany,
            //                                        Id = q.Id,
            //                                        IDNo = q.IDNo,


            //                                    }).ToList();
            //book.BookRelatedGroups = (await (from x in context.BookRelatedGroups
            //                                 join y in context.ViewJobGroups on x.GroupId equals y.Id
            //                                 where x.BookId == id
            //                                 select y).ToListAsync()).Select(q => new ViewModels.JobGroup()
            //                                 {
            //                                     Title = q.Title,
            //                                     FullCode = q.FullCode,
            //                                     Remark = q.Remark,
            //                                     Parent = q.Parent,
            //                                     Id = q.Id,
            //                                 }).ToList();
            //book.BookRelatedStudyFields = (await (from x in context.BookRelatedStudyFields
            //                                      join y in context.ViewOptions on x.StudyFieldId equals y.Id
            //                                      where x.BookId == id
            //                                      select y).ToListAsync()).Select(q => new ViewModels.Option()
            //                                      {
            //                                          Title = q.Title,

            //                                          Parent = q.Parent,
            //                                          Id = q.Id,

            //                                      }).ToList();


            return(book);
        }