From b535f2cf9c9c1497604ee42b40ef3c75e988b7b7 Mon Sep 17 00:00:00 2001 From: saurabhbhatia Date: Mon, 23 Sep 2013 16:18:07 +0800 Subject: [PATCH] Updated Data import and sync code --- app/controllers/admin/import_data_controller.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/import_data_controller.rb b/app/controllers/admin/import_data_controller.rb index 7e3425c9d..b82c14b52 100644 --- a/app/controllers/admin/import_data_controller.rb +++ b/app/controllers/admin/import_data_controller.rb @@ -41,13 +41,19 @@ class Admin::ImportDataController < OrbitBackendController #@teacher.first_name = hash['teacher_en'] @teacher.ntu_seq = hash['ntu_seq'] + @teacher.sid = hash['ntu_seq'] @teacher.role_ids = ["#{@roles.skip(1).first.id}"] @teacher.password = "testpass" @i += 10 - if hash['email'].blank? - @teacher.email = "#{@i}@ntu.edu.tw" + if !hash['email'].blank? + @user = User.where(email: "#{hash['email']}") + if @user.length == 0 + @teacher.email = hash['email'] + elsif @user.length > 0 + @teacher.email = "#{@i}duplicate@ntu.edu.tw" + end else - @teacher.email = hash['email'] + @teacher.email = "#{@i}@ntu.edu.tw" end if hash['teacher_zh_tw'].blank? && hash['teacher_en'].blank? @@ -211,7 +217,7 @@ class Admin::ImportDataController < OrbitBackendController if b[:title].blank? @journal_paper.paper_title = "No Title Present" else - @journal_paper.paper_title = b[:title].first + @journal_paper.paper_title = b[:title] end @journal_paper.note = b[:remarks] @journal_paper.year = b[:year]