Ejemplo n.º 1
0
 internal static PredefinedUserModel ConvertToInterviewerModel(predefineduser item)
 {
     return(new PredefinedUserModel()
     {
         Id = item.Id,
         UserType = item.UserType,
         Name = item.Name
     });
 }
        /// <summary>
        /// Checks the predefine user and insert.
        /// </summary>
        /// <param name="userType">Type of the user.</param>
        /// <param name="user">The user.</param>
        private void CheckPredefineUserAndInsert(byte userType, string user)
        {
            predefineduser predefineUser = PredefineUserRepository.FirstOrDefault(p => p.Name.ToLower().Contains(user));

            if (predefineUser == null)
            {
                PredefineUserRepository.Add(new predefineduser()
                {
                    UserType = userType, Name = user
                });
                PredefineUserRepository.Save();
            }
        }
        /// <summary>
        /// The actual Work to be done.
        /// </summary>
        protected override void Execute()
        {
            List <transcription> transcriptions = TranscriptionRepository.GetAll().ToList();

            List <string> codes = transcriptions.Select(s => s.ProjectCode.ToLower()).ToList();

            List <predefineduser> predefinedInterviewers = PredefineUserRepository.GetPredefinedUsers(1);

            List <string> importInterviewerList = new List <string>();

            int duplicateRecordCount = 0, insertedRecordCount = 0;

            foreach (TranscriptionModel item in Request.TranscriptionModels)
            {
                if (!codes.Exists(s => s.Contains(item.ProjectCode.ToLower())))
                {
                    transcription transcription = Util.ConvertToTranscription(item);

                    transcription.TranscriptStatus = true;

                    TranscriptionRepository.Add(transcription);
                    TranscriptionRepository.Save();

                    if (!string.IsNullOrEmpty(item.Interviewer))
                    {
                        string[] splits = item.Interviewer.Split(';');

                        foreach (string str in splits)
                        {
                            if (!importInterviewerList.Contains(str.Trim()))
                            {
                                importInterviewerList.Add(str.Trim());
                            }
                        }
                    }

                    insertedRecordCount++;
                }
                else
                {
                    duplicateRecordCount++;
                }
            }

            List <string> list = predefinedInterviewers.Select(item => item.Name).ToList();

            foreach (string item in importInterviewerList.Except(list))
            {
                predefineduser interviewer = new predefineduser()
                {
                    UserType = 1, Name = item
                };

                PredefineUserRepository.Add(interviewer);
                PredefineUserRepository.Save();
            }

            Response = new ResponseModel()
            {
                ErrorMessage = string.Format(" {0} record(s) were \n successfully imported and \n found" +
                                             " {1} duplicate records.", insertedRecordCount, duplicateRecordCount),
                IsOperationSuccess = true
            };
        }