public async Task <List <Dashboard_TicketTypeDTO> > SingleListTicketType([FromBody] Dashboard_TicketTypeFilterDTO Dashboard_TicketTypeFilterDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            TicketTypeFilter TicketTypeFilter = new TicketTypeFilter();

            TicketTypeFilter.Skip      = 0;
            TicketTypeFilter.Take      = 20;
            TicketTypeFilter.OrderBy   = TicketTypeOrder.Id;
            TicketTypeFilter.OrderType = OrderType.ASC;
            TicketTypeFilter.Selects   = TicketTypeSelect.ALL;
            TicketTypeFilter.Id        = Dashboard_TicketTypeFilterDTO.Id;
            TicketTypeFilter.Name      = Dashboard_TicketTypeFilterDTO.Name;
            TicketTypeFilter.ColorCode = Dashboard_TicketTypeFilterDTO.ColorCode;
            TicketTypeFilter.StatusId  = Dashboard_TicketTypeFilterDTO.StatusId;

            List <TicketType> TicketTypes = await TicketTypeService.List(TicketTypeFilter);

            List <Dashboard_TicketTypeDTO> Dashboard_TicketTypeDTOs = TicketTypes
                                                                      .Select(x => new Dashboard_TicketTypeDTO(x)).ToList();

            return(Dashboard_TicketTypeDTOs);
        }
示例#2
0
        public async Task <ActionResult <List <TicketType_TicketTypeDTO> > > List([FromBody] TicketType_TicketTypeFilterDTO TicketType_TicketTypeFilterDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            TicketTypeFilter TicketTypeFilter = ConvertFilterDTOToFilterEntity(TicketType_TicketTypeFilterDTO);

            TicketTypeFilter = TicketTypeService.ToFilter(TicketTypeFilter);
            List <TicketType> TicketTypes = await TicketTypeService.List(TicketTypeFilter);

            List <TicketType_TicketTypeDTO> TicketType_TicketTypeDTOs = TicketTypes
                                                                        .Select(c => new TicketType_TicketTypeDTO(c)).ToList();

            return(TicketType_TicketTypeDTOs);
        }
示例#3
0
        public async Task <ActionResult> Import(IFormFile file)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }
            StatusFilter StatusFilter = new StatusFilter
            {
                Skip    = 0,
                Take    = int.MaxValue,
                Selects = StatusSelect.ALL
            };
            List <Status> Statuses = await StatusService.List(StatusFilter);

            TicketTypeFilter TicketTypeFilter = new TicketTypeFilter
            {
                Skip    = 0,
                Take    = int.MaxValue,
                Selects = TicketTypeSelect.ALL
            };
            List <TicketType> TicketTypes = await TicketTypeService.List(TicketTypeFilter);

            List <TicketGroup> TicketGroups = new List <TicketGroup>();

            using (ExcelPackage excelPackage = new ExcelPackage(file.OpenReadStream()))
            {
                ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.FirstOrDefault();
                if (worksheet == null)
                {
                    return(Ok(TicketGroups));
                }
                int StartColumn        = 1;
                int StartRow           = 1;
                int IdColumn           = 0 + StartColumn;
                int NameColumn         = 1 + StartColumn;
                int OrderNumberColumn  = 2 + StartColumn;
                int StatusIdColumn     = 3 + StartColumn;
                int TicketTypeIdColumn = 4 + StartColumn;
                int UsedColumn         = 8 + StartColumn;

                for (int i = StartRow; i <= worksheet.Dimension.End.Row; i++)
                {
                    if (string.IsNullOrEmpty(worksheet.Cells[i + StartRow, StartColumn].Value?.ToString()))
                    {
                        break;
                    }
                    string IdValue           = worksheet.Cells[i + StartRow, IdColumn].Value?.ToString();
                    string NameValue         = worksheet.Cells[i + StartRow, NameColumn].Value?.ToString();
                    string OrderNumberValue  = worksheet.Cells[i + StartRow, OrderNumberColumn].Value?.ToString();
                    string StatusIdValue     = worksheet.Cells[i + StartRow, StatusIdColumn].Value?.ToString();
                    string TicketTypeIdValue = worksheet.Cells[i + StartRow, TicketTypeIdColumn].Value?.ToString();
                    string UsedValue         = worksheet.Cells[i + StartRow, UsedColumn].Value?.ToString();

                    TicketGroup TicketGroup = new TicketGroup();
                    TicketGroup.Name        = NameValue;
                    TicketGroup.OrderNumber = long.TryParse(OrderNumberValue, out long OrderNumber) ? OrderNumber : 0;
                    Status Status = Statuses.Where(x => x.Id.ToString() == StatusIdValue).FirstOrDefault();
                    TicketGroup.StatusId = Status == null ? 0 : Status.Id;
                    TicketGroup.Status   = Status;
                    TicketType TicketType = TicketTypes.Where(x => x.Id.ToString() == TicketTypeIdValue).FirstOrDefault();
                    TicketGroup.TicketTypeId = TicketType == null ? 0 : TicketType.Id;
                    TicketGroup.TicketType   = TicketType;

                    TicketGroups.Add(TicketGroup);
                }
            }
            TicketGroups = await TicketGroupService.Import(TicketGroups);

            if (TicketGroups.All(x => x.IsValidated))
            {
                return(Ok(true));
            }
            else
            {
                List <string> Errors = new List <string>();
                for (int i = 0; i < TicketGroups.Count; i++)
                {
                    TicketGroup TicketGroup = TicketGroups[i];
                    if (!TicketGroup.IsValidated)
                    {
                        string Error = $"Dòng {i + 2} có lỗi:";
                        if (TicketGroup.Errors.ContainsKey(nameof(TicketGroup.Id)))
                        {
                            Error += TicketGroup.Errors[nameof(TicketGroup.Id)];
                        }
                        if (TicketGroup.Errors.ContainsKey(nameof(TicketGroup.Name)))
                        {
                            Error += TicketGroup.Errors[nameof(TicketGroup.Name)];
                        }
                        if (TicketGroup.Errors.ContainsKey(nameof(TicketGroup.OrderNumber)))
                        {
                            Error += TicketGroup.Errors[nameof(TicketGroup.OrderNumber)];
                        }
                        if (TicketGroup.Errors.ContainsKey(nameof(TicketGroup.StatusId)))
                        {
                            Error += TicketGroup.Errors[nameof(TicketGroup.StatusId)];
                        }
                        if (TicketGroup.Errors.ContainsKey(nameof(TicketGroup.TicketTypeId)))
                        {
                            Error += TicketGroup.Errors[nameof(TicketGroup.TicketTypeId)];
                        }
                        if (TicketGroup.Errors.ContainsKey(nameof(TicketGroup.Used)))
                        {
                            Error += TicketGroup.Errors[nameof(TicketGroup.Used)];
                        }
                        Errors.Add(Error);
                    }
                }
                return(BadRequest(Errors));
            }
        }