コード例 #1
0
        private PositionFilter ConvertFilterDTOToFilterEntity(Position_PositionFilterDTO Position_PositionFilterDTO)
        {
            PositionFilter PositionFilter = new PositionFilter();

            PositionFilter.Selects   = PositionSelect.ALL;
            PositionFilter.Skip      = Position_PositionFilterDTO.Skip;
            PositionFilter.Take      = Position_PositionFilterDTO.Take;
            PositionFilter.OrderBy   = Position_PositionFilterDTO.OrderBy;
            PositionFilter.OrderType = Position_PositionFilterDTO.OrderType;

            PositionFilter.Id        = Position_PositionFilterDTO.Id;
            PositionFilter.Code      = Position_PositionFilterDTO.Code;
            PositionFilter.Name      = Position_PositionFilterDTO.Name;
            PositionFilter.StatusId  = Position_PositionFilterDTO.StatusId;
            PositionFilter.CreatedAt = Position_PositionFilterDTO.CreatedAt;
            PositionFilter.UpdatedAt = Position_PositionFilterDTO.UpdatedAt;
            return(PositionFilter);
        }
コード例 #2
0
        public async Task <ActionResult <int> > Count([FromBody] Position_PositionFilterDTO Position_PositionFilterDTO)
        {
            if (UnAuthorization)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            PositionFilter PositionFilter = ConvertFilterDTOToFilterEntity(Position_PositionFilterDTO);

            PositionFilter = await PositionService.ToFilter(PositionFilter);

            int count = await PositionService.Count(PositionFilter);

            return(count);
        }
コード例 #3
0
        public async Task <ActionResult <List <Position_PositionDTO> > > List([FromBody] Position_PositionFilterDTO Position_PositionFilterDTO)
        {
            if (UnAuthorization)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            PositionFilter PositionFilter = ConvertFilterDTOToFilterEntity(Position_PositionFilterDTO);

            PositionFilter = await PositionService.ToFilter(PositionFilter);

            List <Position> Positions = await PositionService.List(PositionFilter);

            List <Position_PositionDTO> Position_PositionDTOs = Positions
                                                                .Select(c => new Position_PositionDTO(c)).ToList();

            return(Position_PositionDTOs);
        }
コード例 #4
0
        public async Task <ActionResult> ExportTemplate([FromBody] Position_PositionFilterDTO Position_PositionFilterDTO)
        {
            if (UnAuthorization)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            string path = "Templates/Position_Template.xlsx";

            byte[]       arr    = System.IO.File.ReadAllBytes(path);
            MemoryStream input  = new MemoryStream(arr);
            MemoryStream output = new MemoryStream();
            dynamic      Data   = new ExpandoObject();

            using (var document = StaticParams.DocumentFactory.Open(input, output, "xlsx"))
            {
                document.Process(Data);
            };
            return(File(output.ToArray(), "application/octet-stream", "Position.xlsx"));
        }
コード例 #5
0
        public async Task <ActionResult> Export([FromBody] Position_PositionFilterDTO Position_PositionFilterDTO)
        {
            if (UnAuthorization)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            MemoryStream memoryStream = new MemoryStream();

            using (ExcelPackage excel = new ExcelPackage(memoryStream))
            {
                #region Position
                var PositionFilter = ConvertFilterDTOToFilterEntity(Position_PositionFilterDTO);
                PositionFilter.Skip = 0;
                PositionFilter.Take = int.MaxValue;
                PositionFilter      = await PositionService.ToFilter(PositionFilter);

                List <Position> Positions = await PositionService.List(PositionFilter);

                var PositionHeaders = new List <string[]>()
                {
                    new string[] {
                        "Id",
                        "Code",
                        "Name",
                        "StatusId",
                        "RowId",
                        "Used",
                    }
                };
                List <object[]> PositionData = new List <object[]>();
                for (int i = 0; i < Positions.Count; i++)
                {
                    var Position = Positions[i];
                    PositionData.Add(new Object[]
                    {
                        Position.Id,
                        Position.Code,
                        Position.Name,
                        Position.StatusId,
                        Position.RowId,
                        Position.Used,
                    });
                }
                excel.GenerateWorksheet("Position", PositionHeaders, PositionData);
                #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", "Position.xlsx"));
        }