public async Task <IActionResult> ReadEmployeeExcel() { var file = Request.Form.Files[0]; var rs = new List <EmployeeErrorableModel>(); await FileHelper.scanExcel(file, 6, async (header, row) => { var employee = new EmployeeErrorableModel(); employee.person = new ApiModels.Core.PersonModel(); try { for (var i = 0; i < header.Cells.Count; i++) { await employee.UpdateEmployeeFromCell(header.Cells[i].StringCellValue, row.Cells[i], async(p) => { return(await _coreRep.ListEmployees(filter: p)); }, async(p) => { return(await _coreRep.GetDepartments(filter: p)); }); } employee.person.AutoGenerateDisplayName(); employee.person.AutoGenerateFullName(); } catch (Exception e) { employee.messages.Add(MessageModel.CreateError(e.Message + ". " + e.StackTrace)); } rs.Add(employee); }); return(Ok(new ResponseModel(rs))); }
public async Task <IActionResult> UploadEmployeeExcel(EmployeeCollectionModel model) { var entities = model.employees.Select(u => u.ToEmployee()); var rs = new List <EmployeeErrorableModel>(); foreach (var item in entities) { try { await _coreRep.UpdateOrAddEmployeeByCode(item, await getCurrentUser()); rs.Add(new EmployeeErrorableModel(item)); } catch (Exception e) { var irs = new EmployeeErrorableModel(item); irs.messages.Add(MessageModel.CreateError(e.Message + "" + (e.InnerException == null?"":e.InnerException.Message) + " " + e.StackTrace)); rs.Add(irs); } } return(Ok(new ResponseModel(rs))); }