public async Task <IActionResult> GetCompany(int id) { if (id <= 0) { return(BadRequest("Company Id must be positive integer.")); } var result = await _repo.GetCompany(id); if (result == null) { return(NotFound()); } return(Ok(result)); }
public Company GetCompany(int companyId) { return(_companiesRepository.GetCompany(companyId)); }
/// <summary> /// /// </summary> /// <param name="filename"></param> /// <param name="sheetName"></param> /// <returns></returns> public bool SaveTransactionsFromFile(string filename, string sheetName) { try { //Using Npoi instead of the office components ISheet sheet; if (filename.Substring(filename.LastIndexOf('.')).ToLower() == EXCEL_2007_EXTENSION) { XSSFWorkbook workbook; using (var file = new FileStream(filename, FileMode.Open, FileAccess.Read)) { workbook = new XSSFWorkbook(file); } sheet = workbook.GetSheet(sheetName); } else { HSSFWorkbook workbook; using (var file = new FileStream(filename, FileMode.Open, FileAccess.Read)) { workbook = new HSSFWorkbook(file); } sheet = workbook.GetSheet(sheetName); } var transactionsList = new List <dynamic>(); for (int row = 1; row <= sheet.LastRowNum; row++) { if (sheet.GetRow(row) != null) //null is when the row only contains empty cells { var theRow = sheet.GetRow(row); var transaction = new { campana = theRow.GetCell(0).StringCellValue, factura = theRow.GetCell(1).StringCellValue, fecha = theRow.GetCell(2).DateCellValue, monto = theRow.GetCell(3).NumericCellValue, puntos = theRow.GetCell(4).NumericCellValue, comision = theRow.GetCell(5).NumericCellValue, vendedor = theRow.GetCell(6).StringCellValue, }; transactionsList.Add(transaction); } } //string connectionString = // string.Format( // filename.Substring(filename.LastIndexOf('.')).ToLower() == EXCEL_2007_EXTENSION // ? EXCEL_2007_CONNECTION_STRING // : EXCEL_2005_CONNECTION_STRING, filename); //var adapter = new OleDbDataAdapter(string.Format(SELECT_ALL_QUERY, sheetName), connectionString); //var dataSet = new DataSet(); //adapter.Fill(dataSet, DATA_TABLE_NAME); //var reportData = dataSet.Tables[DATA_TABLE_NAME].AsEnumerable(); //var transactionsList = // reportData.Where(y => y.Field<string>("Campaña") != null) // .Select( // x => new // { // campana = x.Field<string>("Campaña"), // factura = x.Field<string>("Factura"), // fecha = x.Field<DateTime>("Fecha"), // monto = x.Field<double>("Monto"), // puntos = x.Field<double>("Puntos"), // comision = x.Field<double>("Comision"), // vendedor = x.Field<string>("Vendedor"), // }). // ToList(); //o por nombre de columna. foreach (var individualTransaction in transactionsList) { int cedNumber = GetCedNumberFromString(individualTransaction.vendedor); var customer = _usersRepository.GetUserByIdentificationNumber(cedNumber); var company = _companiesRepository.GetCompany(individualTransaction.campana); var transaction = new Transaction { Amount = individualTransaction.monto, BillBarCode = individualTransaction.factura, UserId = customer.UserId, Points = (int)individualTransaction.puntos, TransactionDate = Convert.ToDateTime(individualTransaction.fecha), CompanyId = company.CompanyId, CreatetedAt = DateTime.Now, UpdatedAt = DateTime.Now, Comision = individualTransaction.comision, }; if (_transactionsRepository.SaveTransaction(transaction)) { if (!DistributeTransactionCashback(transaction)) { _transactionsRepository.RejectChanges(); } } else { //send error _usersRepository.RejectChanges(); _transactionsRepository.RejectChanges(); return(false); } } _transactionsRepository.SaveChangesMade(); _usersRepository.SaveChangesMade(); return(true); } catch (Exception ex) { //TODO: enviar algun error _usersRepository.RejectChanges(); _transactionsRepository.RejectChanges(); Console.WriteLine(ex.Message); return(false); } }