Exemplo n.º 1
0
        public async Task <List <AppUser_SexDTO> > SingleListSex([FromBody] AppUser_SexFilterDTO AppUser_SexFilterDTO)
        {
            SexFilter SexFilter = new SexFilter();

            SexFilter.Skip      = 0;
            SexFilter.Take      = 20;
            SexFilter.OrderBy   = SexOrder.Id;
            SexFilter.OrderType = OrderType.ASC;
            SexFilter.Selects   = SexSelect.ALL;
            SexFilter.Id        = AppUser_SexFilterDTO.Id;
            SexFilter.Code      = AppUser_SexFilterDTO.Code;
            SexFilter.Name      = AppUser_SexFilterDTO.Name;
            List <Sex> Sexes = await SexService.List(SexFilter);

            List <AppUser_SexDTO> AppUser_SexDTOs = Sexes
                                                    .Select(x => new AppUser_SexDTO(x)).ToList();

            return(AppUser_SexDTOs);
        }
Exemplo n.º 2
0
        public async Task <FileResult> Export([FromBody] AppUser_AppUserFilterDTO AppUser_AppUserFilterDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            var AppUserFilter = ConvertFilterDTOToFilterEntity(AppUser_AppUserFilterDTO);

            AppUserFilter.Skip    = 0;
            AppUserFilter.Take    = int.MaxValue;
            AppUserFilter.Selects = AppUserSelect.ALL;
            AppUserFilter         = AppUserService.ToFilter(AppUserFilter);

            List <AppUser> AppUsers = await AppUserService.List(AppUserFilter);

            List <Organization> Organizations = await OrganizationService.List(new OrganizationFilter
            {
                Skip      = 0,
                Take      = int.MaxValue,
                Selects   = OrganizationSelect.Code | OrganizationSelect.Name,
                OrderType = OrderType.ASC,
                OrderBy   = OrganizationOrder.Id,
            });

            List <Sex> Sexes = await SexService.List(new SexFilter
            {
                Skip    = 0,
                Take    = int.MaxValue,
                Selects = SexSelect.ALL
            });

            List <Role> Roles = await RoleService.List(new RoleFilter
            {
                Skip    = 0,
                Take    = int.MaxValue,
                Selects = RoleSelect.Code | RoleSelect.Name
            });

            MemoryStream memoryStream = new MemoryStream();

            using (ExcelPackage excel = new ExcelPackage(memoryStream))
            {
                #region Appuser sheet
                var AppUserHeaders = new List <string[]>()
                {
                    new string[] { "STT", "Mã nhân viên", "Tên nhân viên", "Địa chỉ", "Điện thọi", "Email", "Giới tính", "Chức vụ", "Phòng ban", "Bộ phận quản lý" }
                };
                List <object[]> data = new List <object[]>();
                for (int i = 0; i < AppUsers.Count; i++)
                {
                    var appUser = AppUsers[i];
                    data.Add(new Object[]
                    {
                        i + 1,
                        appUser.Username,
                        appUser.DisplayName,
                        appUser.Address,
                        appUser.Phone,
                        appUser.Email,
                        appUser.Sex.Name,
                        appUser.Position,
                        appUser.Department,
                        appUser.Organization.Code
                    });
                }
                excel.GenerateWorksheet("AppUser", AppUserHeaders, data);
                #endregion

                #region Org sheet
                data.Clear();
                var OrganizationHeader = new List <string[]>()
                {
                    new string[]
                    {
                        "Mã",
                        "Tên"
                    }
                };
                foreach (var Organization in Organizations)
                {
                    data.Add(new object[]
                    {
                        Organization.Code,
                        Organization.Name,
                    });
                }
                excel.GenerateWorksheet("Organization", OrganizationHeader, data);
                #endregion

                #region Sex sheet
                data.Clear();
                var SexHeader = new List <string[]>()
                {
                    new string[]
                    {
                        "Mã",
                        "Tên"
                    }
                };
                foreach (var Sex in Sexes)
                {
                    data.Add(new object[]
                    {
                        Sex.Code,
                        Sex.Name,
                    });
                }
                excel.GenerateWorksheet("Sex", SexHeader, data);
                #endregion

                #region Role sheet
                data.Clear();
                var RoleHeader = new List <string[]>()
                {
                    new string[]
                    {
                        "Mã",
                        "Tên"
                    }
                };
                foreach (var Role in Roles)
                {
                    data.Add(new object[]
                    {
                        Role.Code,
                        Role.Name,
                    });
                }
                excel.GenerateWorksheet("Role", RoleHeader, data);
                #endregion
                excel.Save();
            }
            return(File(memoryStream.ToArray(), "application/octet-stream", "AppUser.xlsx"));
        }