public async Task <List <FileDetailsDto> > GetFileDetails() { List <FileDetailsDto> fileDetailsDtos = new List <FileDetailsDto>(); var fileDetails = await _context.Files.ToListAsync(); foreach (var data in fileDetails) { FileDetailsDto fileDetailsDto = new FileDetailsDto() { Id = data.Id, FileName = data.Name, IsFinished = data.IsFinished }; Console.WriteLine($"Filename :{data.Name}"); fileDetailsDtos.Add(fileDetailsDto); } return(fileDetailsDtos); }
public async Task <IActionResult> ReadSheets(ImportedSheetDto Model) { var npoiHelper = new NPOIHelper(Model.Path); List <FileDetailsDto> dt = new List <FileDetailsDto> (); foreach (var sheet in Model.Sheets) { var sheetData = npoiHelper.ReadSheet(sheet); //start Read Header var headerIndex = npoiHelper.GetFirstRowIndex(sheet); sheetData = sheetData.ReplaceCoulmnName(SheetHeader.Names, "Name"); int NameIndex = sheetData.Columns.IndexOf("Name"); sheetData = sheetData.ReplaceCoulmnName(SheetHeader.Codes, "Code"); int CodeIndex = sheetData.Columns.IndexOf("Code"); sheetData = sheetData.ReplaceCoulmnName(SheetHeader.Net, "Net"); int NetIndex = sheetData.Columns.IndexOf("Net"); var data = sheetData.DefaultView.ToTable(true, "Net", "Code", "Name"); foreach (DataRow Row in data.Rows) { string EmpName = Row.ItemArray.GetValue(Row.Table.Columns.IndexOf("Name")).ToString(); string code = Row.ItemArray.GetValue(Row.Table.Columns.IndexOf("Code")).ToString(); IEnumerable <Employee> emp; emp = await _uow.EmployeeRepository.Get(x => x.Code == code); string Net = Row.ItemArray.GetValue(Row.Table.Columns.IndexOf("Net")).ToString(); var firstName = emp.FirstOrDefault().KnownAs.Normalize().ToNormalizedString().Split(" "); var firstRowName = EmpName.Normalize().ToNormalizedString().Split(" "); if (!string.IsNullOrEmpty(EmpName) && !string.IsNullOrWhiteSpace(EmpName)) { if (!string.IsNullOrEmpty(code) || !string.IsNullOrWhiteSpace(code)) { string defaultPaymentMethod = ""; if (Model.PaymentType == PaymentTypeConst.ATM) { defaultPaymentMethod = emp.FirstOrDefault().ATMOption; } else if (Model.PaymentType == PaymentTypeConst.Bank) { defaultPaymentMethod = emp.FirstOrDefault().BankOption; } var FileDetailDto = new FileDetailsDto(); dt.Add(new FileDetailsDto() { EmployeeData = new DTOS.EmployeeDataListToReturnDto() { Name = emp.FirstOrDefault().KnownAs, Position = emp.FirstOrDefault().Grade, Id = emp.FirstOrDefault().Id, Collage = emp.FirstOrDefault().Collage, Code = emp.FirstOrDefault().Code.ToString(), HasATM = emp.FirstOrDefault().HasATM, HasBank = emp.FirstOrDefault().HasBank, HasOrder = emp.FirstOrDefault().HasOrder, HasPost = emp.FirstOrDefault().HasPost, ATMOption = emp.FirstOrDefault().ATMOption, BankOption = emp.FirstOrDefault().BankOption }, Net = decimal.Parse(Net), SelectedPaymentMethod = defaultPaymentMethod, //PaymentMethod= EmployeePaymentOptions(emp.FirstOrDefault()), State = FileState.New.ToString(), Warrning = (firstName[0] == firstRowName[0] && firstName[1] == firstRowName[1]) ? null : string.Format(" تأكد من الأسم من فضلك - {0}", EmpName) }); } else { var s = await SuggestEmployee(EmpName.ToNormalizedString(), Model.PaymentType, false); dt.Add(new FileDetailsDto() { EmployeeData = new EmployeeDataListToReturnDto() { Name = EmpName }, Net = decimal.Parse(Net), State = FileState.New.ToString(), SuggestedEmployee = s }); } } } } return(Ok(new { data = dt })); }