public static void Addvehicle(this tbl_vehicle vehicle, VehicleViewModel vehicleVm) { vehicle.tenant_id = vehicleVm.tenant_id; vehicle.project_id = vehicleVm.project_id; vehicle.subcontractor_id = vehicleVm.subcontractor_id; vehicle.vehicle_reg_no = vehicleVm.vehicle_reg_no; vehicle.vehicle_type = vehicleVm.vehicle_type; vehicle.pollution_clearance = vehicleVm.pollution_clearance; vehicle.pollution_validdate = vehicleVm.pollution_validdate; vehicle.pollution_filename = vehicleVm.pollution_filename; vehicle.pollutionimage_filetype = vehicleVm.pollutionimage_filetype; vehicle.pollutionimage = vehicleVm.pollutionimage; vehicle.insurence_clearance = vehicleVm.insurence_clearance; vehicle.insurence_validdate = vehicleVm.insurence_validdate; vehicle.insurence_filename = vehicleVm.insurence_filename; vehicle.insurenceimage_filetype = vehicleVm.insurenceimage_filetype; vehicle.insurenceimage = vehicleVm.insurenceimage; vehicle.fitness_clearance = vehicleVm.fitness_clearance; vehicle.fitness_validdate = vehicleVm.fitness_validdate; vehicle.fitness_filename = vehicleVm.fitness_filename; vehicle.fitnessimage_filetype = vehicleVm.fitnessimage_filetype; vehicle.fitnessimage = vehicleVm.fitnessimage; vehicle.driver_name = vehicleVm.driver_name; vehicle.driver_contact_no = vehicleVm.driver_contact_no; // vehicle.working_status = vehicle.working_status; vehicle.driver_aadharnumber = vehicleVm.driver_aadharnumber; vehicle.driver_filename = vehicleVm.driver_filename; vehicle.driver_photo = vehicleVm.driver_photo; vehicle.driver_photo_file_type = vehicleVm.driver_photo_file_type; vehicle.driver_lic_no = vehicleVm.driver_lic_no; vehicle.driver_lic_validdate = vehicleVm.driver_lic_validdate; vehicle.driver_lic_filename = vehicleVm.driver_lic_filename; vehicle.driverlicimage_filetype = vehicleVm.driverlicimage_filetype; vehicle.driverlicimage = vehicleVm.driverlicimage; vehicle.current_street = vehicleVm.current_street; vehicle.current_country = vehicleVm.current_country; vehicle.current_state = vehicleVm.current_state; vehicle.current_city = vehicleVm.current_city; vehicle.current_zip = vehicleVm.current_zip; vehicle.permanent_street = vehicleVm.permanent_street; vehicle.permanent_country = vehicleVm.permanent_country; vehicle.permanent_state = vehicleVm.permanent_state; vehicle.permanent_city = vehicleVm.permanent_city; vehicle.permanent_zip = vehicleVm.permanent_zip; vehicle.contact_person_name = vehicleVm.contact_person_name; vehicle.contact_person_relationship_id = vehicleVm.contact_person_relationship_id; vehicle.contact_person_street = vehicleVm.contact_person_street; vehicle.contact_person_country = vehicleVm.contact_person_country; vehicle.contact_person_state = vehicleVm.contact_person_state; vehicle.contact_person_city = vehicleVm.contact_person_city; vehicle.contact_person_zip = vehicleVm.contact_person_zip; vehicle.contact_person_contact_number = vehicleVm.contact_person_contact_number; vehicle.created_date = DateTime.Now; vehicle.created_by = vehicleVm.created_by; vehicle.modified_date = DateTime.Now; vehicle.modified_by = vehicleVm.modified_by; }
public HttpResponseMessage Savevehicle(HttpRequestMessage request, VehicleViewModel vehicle) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { //start of saving to master emp table var codeFormat = _settingsRepository.GetAll().Where(t => t.tenant_id == vehicle.tenant_id).FirstOrDefault(); var exsistingEmployees = _EmployeeRepository.GetAll().Where(e => e.tenant_id == vehicle.tenant_id); tbl_employee newEmployeeMaster = new tbl_employee(); int empCount = exsistingEmployees.Count(); if (empCount <= 0) { newEmployeeMaster.emp_code = codeFormat.emp_code; newEmployeeMaster.code_seperation = codeFormat.code_seperation; newEmployeeMaster.emp_num = codeFormat.emp_num; } else { var lastERec = _EmployeeRepository.GetAll().Where(e => e.tenant_id == vehicle.tenant_id).OrderByDescending(e => e.id).First(); //var lastERec = _EmployeeRepository.GetSingle(empCount); newEmployeeMaster.emp_code = lastERec.emp_code; newEmployeeMaster.code_seperation = lastERec.code_seperation; newEmployeeMaster.emp_num = lastERec.emp_num + 1; } newEmployeeMaster.tenant_id = vehicle.tenant_id; newEmployeeMaster.project_id = vehicle.project_id; newEmployeeMaster.Designation = "Driver"; newEmployeeMaster.emp_name = vehicle.driver_name; newEmployeeMaster.date_created = DateTime.Now; newEmployeeMaster.CreatedBy = "Admin"; _EmployeeRepository.Add(newEmployeeMaster); //_unitOfWork.Commit(); //end of saving to master emp table tbl_vehicle newProject = new tbl_vehicle(); newProject.master_emp_id = _EmployeeRepository.GetAll().Count() + 1; newProject.created_date = DateTime.Now; newProject.created_by = GlobalVars.gvUserID; newProject.modified_date = DateTime.Now; newProject.modified_by = GlobalVars.gvUserID; newProject.Addvehicle(vehicle); _vehicleRepository.Add(newProject); _unitOfWork.Commit(); response = request.CreateResponse <VehicleViewModel>(HttpStatusCode.Created, vehicle); } return response; })); }