private (PkudatYomanShura[] shuras, bool isBalanced) GeneratePkudatYoman(GeneralBillingSummary dbSummary, DateTime dateOfRegistration, SupplierEntity supplier = null) { string dateOfRegistrationString = dateOfRegistration.ToString("yyyyMMdd"); string DateOfValueString = dbSummary.DateOfValue.ToString("yyyyMMdd"); if (dbSummary != null) { supplier = supplier == null ? new SuppliersService(context).GetSuppliersByCustomer(new CustomerEntity { Id = dbSummary.CustomerId }).FirstOrDefault(x => x.Id == dbSummary.SupplierId && x.IsEnable):supplier; var budgetsContracts = new BudgetContractService(context).GetRelationshipBySupplier(supplier); var contracts = new ContractsService(context).GetBySupplier(supplier).Result; var banks = new BankAccountsService(context).GetBySupplier(supplier); switch (Convert.ToInt32(dbSummary.SupplierId)) { case (int)Enums.Suppliers.Bezek: return(createPkudaForBezek(dbSummary, dateOfRegistrationString, supplier, DateOfValueString, budgetsContracts, contracts, banks).Result); case (int)Enums.Suppliers.Electricity: return(createPkudaForElectricity(dbSummary, dateOfRegistrationString, supplier, DateOfValueString, budgetsContracts, contracts, banks).Result); default: return(createPkudaForPrivateSupplier(dbSummary, dateOfRegistrationString, supplier, DateOfValueString, budgetsContracts, contracts, banks).Result); } } return(null, false); }
public async Task <bool> AddRelationshipByFile(FileEntity fileEntity) { var pck = new ExcelPackage(); pck.Load(fileEntity.File.OpenReadStream()); try { SupplierEntity supplier = new SupplierEntity { Id = fileEntity.SupplierId, CustomerId = fileEntity.CustomerId }; var result = await Task.Run(() => { var excel = pck.Workbook.Worksheets.First(); var budgets = new BudgetsService(context).GetBySupplier(supplier); var contracts = new ContractsService(context).GetBySupplier(supplier).Result; var relationship = new BudgetContractService(context).GetRelationshipBySupplier(supplier); for (int rowNum = 2; rowNum <= excel.Dimension.End.Row; rowNum++) { if (!string.IsNullOrEmpty(excel.Cells[rowNum, 1].Text)) { handleRelationShipsExcel(excel, rowNum, contracts, budgets, relationship, supplier); } else { break; } } return(true); }); pck.Dispose(); await context.SaveChangesAsync(); return(result); } catch (Exception e) { pck.Dispose(); throw e; } }