private ScheduleMasterFilter ConvertFilterDTOToFilterEntity(ScheduleMaster_ScheduleMasterFilterDTO ScheduleMaster_ScheduleMasterFilterDTO)
        {
            ScheduleMasterFilter ScheduleMasterFilter = new ScheduleMasterFilter();

            ScheduleMasterFilter.Selects   = ScheduleMasterSelect.ALL;
            ScheduleMasterFilter.Skip      = ScheduleMaster_ScheduleMasterFilterDTO.Skip;
            ScheduleMasterFilter.Take      = ScheduleMaster_ScheduleMasterFilterDTO.Take;
            ScheduleMasterFilter.OrderBy   = ScheduleMaster_ScheduleMasterFilterDTO.OrderBy;
            ScheduleMasterFilter.OrderType = ScheduleMaster_ScheduleMasterFilterDTO.OrderType;

            ScheduleMasterFilter.Id             = ScheduleMaster_ScheduleMasterFilterDTO.Id;
            ScheduleMasterFilter.ManagerId      = ScheduleMaster_ScheduleMasterFilterDTO.ManagerId;
            ScheduleMasterFilter.SalerId        = ScheduleMaster_ScheduleMasterFilterDTO.SalerId;
            ScheduleMasterFilter.Name           = ScheduleMaster_ScheduleMasterFilterDTO.Name;
            ScheduleMasterFilter.Code           = ScheduleMaster_ScheduleMasterFilterDTO.Code;
            ScheduleMasterFilter.StatusId       = ScheduleMaster_ScheduleMasterFilterDTO.StatusId;
            ScheduleMasterFilter.RecurDays      = ScheduleMaster_ScheduleMasterFilterDTO.RecurDays;
            ScheduleMasterFilter.StartDate      = ScheduleMaster_ScheduleMasterFilterDTO.StartDate;
            ScheduleMasterFilter.EndDate        = ScheduleMaster_ScheduleMasterFilterDTO.EndDate;
            ScheduleMasterFilter.StartDayOfWeek = ScheduleMaster_ScheduleMasterFilterDTO.StartDayOfWeek;
            ScheduleMasterFilter.DisplayOrder   = ScheduleMaster_ScheduleMasterFilterDTO.DisplayOrder;
            ScheduleMasterFilter.Description    = ScheduleMaster_ScheduleMasterFilterDTO.Description;
            ScheduleMasterFilter.CreatedAt      = ScheduleMaster_ScheduleMasterFilterDTO.CreatedAt;
            ScheduleMasterFilter.UpdatedAt      = ScheduleMaster_ScheduleMasterFilterDTO.UpdatedAt;
            return(ScheduleMasterFilter);
        }
        public async Task <ActionResult <int> > Count([FromBody] ScheduleMaster_ScheduleMasterFilterDTO ScheduleMaster_ScheduleMasterFilterDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            ScheduleMasterFilter ScheduleMasterFilter = ConvertFilterDTOToFilterEntity(ScheduleMaster_ScheduleMasterFilterDTO);

            ScheduleMasterFilter = ScheduleMasterService.ToFilter(ScheduleMasterFilter);
            int count = await ScheduleMasterService.Count(ScheduleMasterFilter);

            return(count);
        }
        public async Task <ActionResult <List <ScheduleMaster_ScheduleMasterDTO> > > List([FromBody] ScheduleMaster_ScheduleMasterFilterDTO ScheduleMaster_ScheduleMasterFilterDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            ScheduleMasterFilter ScheduleMasterFilter = ConvertFilterDTOToFilterEntity(ScheduleMaster_ScheduleMasterFilterDTO);

            ScheduleMasterFilter = ScheduleMasterService.ToFilter(ScheduleMasterFilter);
            List <ScheduleMaster> ScheduleMasters = await ScheduleMasterService.List(ScheduleMasterFilter);

            List <ScheduleMaster_ScheduleMasterDTO> ScheduleMaster_ScheduleMasterDTOs = ScheduleMasters
                                                                                        .Select(c => new ScheduleMaster_ScheduleMasterDTO(c)).ToList();

            return(ScheduleMaster_ScheduleMasterDTOs);
        }
        public async Task <FileResult> ExportTemplate([FromBody] ScheduleMaster_ScheduleMasterFilterDTO ScheduleMaster_ScheduleMasterFilterDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            MemoryStream memoryStream = new MemoryStream();

            using (ExcelPackage excel = new ExcelPackage(memoryStream))
            {
                #region ScheduleMaster
                var ScheduleMasterHeaders = new List <string[]>()
                {
                    new string[] {
                        "Id",
                        "ManagerId",
                        "SalerId",
                        "Name",
                        "Code",
                        "StatusId",
                        "RecurDays",
                        "StartDate",
                        "EndDate",
                        "NoEndDate",
                        "StartDayOfWeek",
                        "DisplayOrder",
                        "Description",
                    }
                };
                List <object[]> ScheduleMasterData = new List <object[]>();
                excel.GenerateWorksheet("ScheduleMaster", ScheduleMasterHeaders, ScheduleMasterData);
                #endregion

                #region AppUser
                var AppUserFilter = new AppUserFilter();
                AppUserFilter.Selects   = AppUserSelect.ALL;
                AppUserFilter.OrderBy   = AppUserOrder.Id;
                AppUserFilter.OrderType = OrderType.ASC;
                AppUserFilter.Skip      = 0;
                AppUserFilter.Take      = int.MaxValue;
                List <AppUser> AppUsers = await AppUserService.List(AppUserFilter);

                var AppUserHeaders = new List <string[]>()
                {
                    new string[] {
                        "Id",
                        "Username",
                        "DisplayName",
                        "Address",
                        "Email",
                        "Phone",
                        "PositionId",
                        "Department",
                        "OrganizationId",
                        "StatusId",
                        "Avatar",
                        "ProvinceId",
                        "SexId",
                        "Birthday",
                    }
                };
                List <object[]> AppUserData = new List <object[]>();
                for (int i = 0; i < AppUsers.Count; i++)
                {
                    var AppUser = AppUsers[i];
                    AppUserData.Add(new Object[]
                    {
                        AppUser.Id,
                        AppUser.Username,
                        AppUser.DisplayName,
                        AppUser.Address,
                        AppUser.Email,
                        AppUser.Phone,
                        AppUser.PositionId,
                        AppUser.Department,
                        AppUser.OrganizationId,
                        AppUser.StatusId,
                        AppUser.Avatar,
                        AppUser.ProvinceId,
                        AppUser.SexId,
                        AppUser.Birthday,
                    });
                }
                excel.GenerateWorksheet("AppUser", AppUserHeaders, AppUserData);
                #endregion
                #region Status
                var StatusFilter = new StatusFilter();
                StatusFilter.Selects   = StatusSelect.ALL;
                StatusFilter.OrderBy   = StatusOrder.Id;
                StatusFilter.OrderType = OrderType.ASC;
                StatusFilter.Skip      = 0;
                StatusFilter.Take      = int.MaxValue;
                List <Status> Statuses = await StatusService.List(StatusFilter);

                var StatusHeaders = new List <string[]>()
                {
                    new string[] {
                        "Id",
                        "Code",
                        "Name",
                    }
                };
                List <object[]> StatusData = new List <object[]>();
                for (int i = 0; i < Statuses.Count; i++)
                {
                    var Status = Statuses[i];
                    StatusData.Add(new Object[]
                    {
                        Status.Id,
                        Status.Code,
                        Status.Name,
                    });
                }
                excel.GenerateWorksheet("Status", StatusHeaders, StatusData);
                #endregion
                excel.Save();
            }
            return(File(memoryStream.ToArray(), "application/octet-stream", "ScheduleMaster.xlsx"));
        }