public async Task <List <Dashboard_TicketStatusDTO> > SingleListTicketStatus([FromBody] Dashboard_TicketStatusFilterDTO Dashboard_TicketStatusFilterDTO) { if (!ModelState.IsValid) { throw new BindException(ModelState); } TicketStatusFilter TicketStatusFilter = new TicketStatusFilter(); TicketStatusFilter.Skip = 0; TicketStatusFilter.Take = 20; TicketStatusFilter.OrderBy = TicketStatusOrder.Id; TicketStatusFilter.OrderType = OrderType.ASC; TicketStatusFilter.Selects = TicketStatusSelect.ALL; TicketStatusFilter.Id = Dashboard_TicketStatusFilterDTO.Id; TicketStatusFilter.Name = Dashboard_TicketStatusFilterDTO.Name; TicketStatusFilter.OrderNumber = Dashboard_TicketStatusFilterDTO.OrderNumber; TicketStatusFilter.ColorCode = Dashboard_TicketStatusFilterDTO.ColorCode; TicketStatusFilter.StatusId = Dashboard_TicketStatusFilterDTO.StatusId; List <TicketStatus> TicketStatuses = await TicketStatusService.List(TicketStatusFilter); List <Dashboard_TicketStatusDTO> Dashboard_TicketStatusDTOs = TicketStatuses .Select(x => new Dashboard_TicketStatusDTO(x)).ToList(); return(Dashboard_TicketStatusDTOs); }
public async Task <ActionResult <List <TicketStatus_TicketStatusDTO> > > List([FromBody] TicketStatus_TicketStatusFilterDTO TicketStatus_TicketStatusFilterDTO) { if (!ModelState.IsValid) { throw new BindException(ModelState); } TicketStatusFilter TicketStatusFilter = ConvertFilterDTOToFilterEntity(TicketStatus_TicketStatusFilterDTO); TicketStatusFilter = TicketStatusService.ToFilter(TicketStatusFilter); List <TicketStatus> TicketStatuses = await TicketStatusService.List(TicketStatusFilter); List <TicketStatus_TicketStatusDTO> TicketStatus_TicketStatusDTOs = TicketStatuses .Select(c => new TicketStatus_TicketStatusDTO(c)).ToList(); return(TicketStatus_TicketStatusDTOs); }
public async Task <ActionResult> Import(IFormFile file) { if (!ModelState.IsValid) { throw new BindException(ModelState); } TicketFilter TicketFilter = new TicketFilter { Skip = 0, Take = int.MaxValue, Selects = TicketSelect.ALL }; List <Ticket> Tickets = await TicketService.List(TicketFilter); TicketStatusFilter TicketStatusFilter = new TicketStatusFilter { Skip = 0, Take = int.MaxValue, Selects = TicketStatusSelect.ALL }; List <TicketStatus> TicketStatuses = await TicketStatusService.List(TicketStatusFilter); AppUserFilter UserFilter = new AppUserFilter { Skip = 0, Take = int.MaxValue, Selects = AppUserSelect.ALL }; List <AppUser> Users = await AppUserService.List(UserFilter); List <TicketOfUser> TicketOfUsers = new List <TicketOfUser>(); using (ExcelPackage excelPackage = new ExcelPackage(file.OpenReadStream())) { ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.FirstOrDefault(); if (worksheet == null) { return(Ok(TicketOfUsers)); } int StartColumn = 1; int StartRow = 1; int IdColumn = 0 + StartColumn; int NotesColumn = 1 + StartColumn; int UserIdColumn = 2 + StartColumn; int TicketIdColumn = 3 + StartColumn; int TicketStatusIdColumn = 4 + 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 NotesValue = worksheet.Cells[i + StartRow, NotesColumn].Value?.ToString(); string UserIdValue = worksheet.Cells[i + StartRow, UserIdColumn].Value?.ToString(); string TicketIdValue = worksheet.Cells[i + StartRow, TicketIdColumn].Value?.ToString(); string TicketStatusIdValue = worksheet.Cells[i + StartRow, TicketStatusIdColumn].Value?.ToString(); TicketOfUser TicketOfUser = new TicketOfUser(); TicketOfUser.Notes = NotesValue; Ticket Ticket = Tickets.Where(x => x.Id.ToString() == TicketIdValue).FirstOrDefault(); TicketOfUser.TicketId = Ticket == null ? 0 : Ticket.Id; TicketOfUser.Ticket = Ticket; TicketStatus TicketStatus = TicketStatuses.Where(x => x.Id.ToString() == TicketStatusIdValue).FirstOrDefault(); TicketOfUser.TicketStatusId = TicketStatus == null ? 0 : TicketStatus.Id; TicketOfUser.TicketStatus = TicketStatus; AppUser User = Users.Where(x => x.Id.ToString() == UserIdValue).FirstOrDefault(); TicketOfUser.UserId = User == null ? 0 : User.Id; TicketOfUser.User = User; TicketOfUsers.Add(TicketOfUser); } } TicketOfUsers = await TicketOfUserService.Import(TicketOfUsers); if (TicketOfUsers.All(x => x.IsValidated)) { return(Ok(true)); } else { List <string> Errors = new List <string>(); for (int i = 0; i < TicketOfUsers.Count; i++) { TicketOfUser TicketOfUser = TicketOfUsers[i]; if (!TicketOfUser.IsValidated) { string Error = $"Dòng {i + 2} có lỗi:"; if (TicketOfUser.Errors.ContainsKey(nameof(TicketOfUser.Id))) { Error += TicketOfUser.Errors[nameof(TicketOfUser.Id)]; } if (TicketOfUser.Errors.ContainsKey(nameof(TicketOfUser.Notes))) { Error += TicketOfUser.Errors[nameof(TicketOfUser.Notes)]; } if (TicketOfUser.Errors.ContainsKey(nameof(TicketOfUser.UserId))) { Error += TicketOfUser.Errors[nameof(TicketOfUser.UserId)]; } if (TicketOfUser.Errors.ContainsKey(nameof(TicketOfUser.TicketId))) { Error += TicketOfUser.Errors[nameof(TicketOfUser.TicketId)]; } if (TicketOfUser.Errors.ContainsKey(nameof(TicketOfUser.TicketStatusId))) { Error += TicketOfUser.Errors[nameof(TicketOfUser.TicketStatusId)]; } Errors.Add(Error); } } return(BadRequest(Errors)); } }