public EpafDto GetEpafById(long?epafId) { var data = _epafService.GetEpafById(epafId); return(Mapper.Map <EpafDto>(data)); }
public TraCrfDto AssignCrfFromEpaf(long epafId, Login CurrentUser) { var epafData = _epafService.GetEpafById(epafId); if (epafData != null) { var existingData = _CrfService.GetByEpafId(epafId); if (existingData != null) { throw new Exception("Epaf Already asigned."); } TraCrfDto item = new TraCrfDto(); var employeeData = _employeeService.GetEmployeeById(epafData.EMPLOYEE_ID); var fleetData = _fleetService.GetFleetByParam(new FleetParamInput() { EmployeeId = employeeData.EMPLOYEE_ID, VehicleType = "BENEFIT" }).FirstOrDefault(); var fleetDo = Mapper.Map <FleetDto>(fleetData); var employeeDto = Mapper.Map <EmployeeDto>(employeeData); employeeDto.EmployeeVehicle = fleetDo; item = Mapper.Map <TraCrfDto>(epafData); if (CurrentUser.UserRole == Enums.UserRole.HR) { item.VEHICLE_TYPE = "BENEFIT"; item.COST_CENTER = employeeDto.COST_CENTER; } else if (CurrentUser.UserRole == Enums.UserRole.Fleet) { item.VEHICLE_TYPE = "WTC"; } if (employeeData == null) { throw new Exception(string.Format("Employee Data {0} not found.", epafData.EMPLOYEE_ID)); } item.LOCATION_CITY = employeeData.CITY; item.LOCATION_OFFICE = employeeData.BASETOWN; item.CREATED_BY = CurrentUser.USER_ID; item.CREATED_DATE = DateTime.Now; item.DOCUMENT_STATUS = (int)Enums.DocumentStatus.AssignedForUser; item.IS_ACTIVE = true; var vehicleData = _fleetService.GetFleetByParam(new FleetParamInput() { EmployeeId = epafData.EMPLOYEE_ID, VehicleType = item.VEHICLE_TYPE, }).FirstOrDefault(); if (vehicleData != null) { var vendorData = _vendorService.GetVendor().FirstOrDefault(x => x.SHORT_NAME == vehicleData.VENDOR_NAME); item.POLICE_NUMBER = vehicleData.POLICE_NUMBER; item.MANUFACTURER = vehicleData.MANUFACTURER; item.MODEL = vehicleData.MODEL; item.SERIES = vehicleData.SERIES; item.Body = vehicleData.BODY_TYPE; item.VENDOR_NAME = vendorData != null ? vendorData.SHORT_NAME : null; item.VENDOR_ID = vendorData != null ? vendorData.MST_VENDOR_ID : (int?)null; item.START_PERIOD = vehicleData.START_CONTRACT; item.END_PERIOD = vehicleData.END_CONTRACT; item.VEHICLE_TYPE = vehicleData.VEHICLE_TYPE; item.VEHICLE_USAGE = vehicleData.VEHICLE_USAGE; item.MST_FLEET_ID = vehicleData.MST_FLEET_ID; item.WITHD_CITY = vehicleData.CITY; item.WITHD_ADDRESS = vehicleData.ADDRESS; } else { throw new Exception("Vehicle for this employee not found on FMS."); } item.DELIV_CITY = epafData.CITY; item.DELIV_ADDRESS = epafData.BASE_TOWN; var returnData = this.SaveCrf(item, CurrentUser); AddWorkflowHistory(returnData, CurrentUser, Enums.ActionType.Submit, null); return(returnData); } else { throw new Exception("Please select Epaf document first."); } }