public async Task CreateFromExcel(List <CreateOrEditEmployeeVacationDto> input) { try { using (var uom = UnitOfWorkManager.Begin()) { foreach (var item in input) { var leaveId = _leaveTypeRepository.FirstOrDefault(x => x.Code == item.LeaveCode).Id; var userId = _userManager.Users.FirstOrDefault(x => x.Code == item.EmpCode).Id; var itemToAdd = new CreateOrEditEmployeeVacationDto(); itemToAdd.Description = item.Description; itemToAdd.FromDate = item.FromDate; itemToAdd.ToDate = item.ToDate; item.LeaveTypeId = leaveId; item.UserId = userId; var employeeVacation = ObjectMapper.Map <EmployeeVacation>(item); await _employeeVacationRepository.InsertAsync(employeeVacation); } uom.Complete(); } } catch (Exception ex) { throw new UserFriendlyException("failed"); } }
protected virtual async Task Create(CreateOrEditEmployeeVacationDto input) { var employeeVacation = ObjectMapper.Map <EmployeeVacation>(input); await _employeeVacationRepository.InsertAsync(employeeVacation); }
public async Task CreateOrEdit(CreateOrEditEmployeeVacationDto input) { if (input.Id == null) { await Create(input); } else { await Update(input); } }
protected virtual async Task Update(CreateOrEditEmployeeVacationDto input) { var employeeVacation = await _employeeVacationRepository.FirstOrDefaultAsync((int)input.Id); ObjectMapper.Map(input, employeeVacation); }