Beispiel #1
0
        private BulkJobPostSummaryDetailViewModel AddSummary(DataRow row)
        {
            var summary = new BulkJobPostSummaryDetailViewModel();
            var pInfos  = summary.GetType().GetProperties();

            foreach (var pInfo in pInfos)
            {
                pInfo.SetValue(summary, Convert.ToString(row[pInfo.Name]));
            }
            return(summary);
        }
Beispiel #2
0
 private void SaveDetailToAudit(BulkJobPostSummaryDetailViewModel detail, string fileName, int userId)
 {
     try
     {
         var dModel = new BulkJobPostSummaryDetail
         {
             CompanyName  = detail.CompanyName,
             CreatedBy    = userId,
             CTC          = detail.CTC,
             ErrorDetails = detail.ErrorDetails,
             FileName     = fileName,
             //FinancialYear = detail.FinancialYear,
             HiringCriteria = detail.HiringCriteria,
             JobDetails     = detail.JobDetails,
             JobLocation    = detail.CityCode,
             //JobRole1 = detail.JobRole1,
             //JobRole2 = detail.JobRole2,
             //JobRole3 = detail.JobRole3,
             JobTitle    = detail.JobTitleByEmployer,
             JobType     = detail.JobType,
             MaxExp      = detail.MaxExp,
             MinExp      = detail.MinExp,
             ProcessedBy = detail.ProcessedBy,
             ProcessedOn = detail.ProcessedOn,
             //Quarter1 = detail.Quarter1,
             //Quarter2 = detail.Quarter2,
             //Quarter3 = detail.Quarter3,
             //Quarter4 = detail.Quarter4,
             SerialNo    = detail.SequenceNo,
             SPOC        = detail.SPOC,
             SPOCContact = detail.SPOCContact,
             SPOCEmail   = detail.SPOCEmail,
             State       = detail.StateCode,
             Status      = detail.Status,
             Total       = detail.Total
         };
         bjpProcessor.SaveDetailToAudit(dModel);
     }
     catch (Exception ex)
     {
         string errMessage = $"<li>Unable to insert job summary due to:   {ex.Message}.</li>";
         detail.ErrorDetails += errMessage;
     }
 }
Beispiel #3
0
        public IEnumerable <BulkUploadSummaryViewModel <BulkJobPostSummaryDetailViewModel> > UploadJobs(UserViewModel user, IList <IFormFile> files)
        {
            string roleName        = user.RoleName;
            string mappingFilePath =
                Path.Combine(environment.WebRootPath, "DataMappings", "BulkJobPostMappings", "JobPostMapping.xml");
            DataTable dt = XmlProcessor.XmlToTable(mappingFilePath);

            if (null != dt)
            {
                var summary = new List <BulkUploadSummaryViewModel <BulkJobPostSummaryDetailViewModel> >();
                foreach (var file in files)
                {
                    var fileSummary = new BulkUploadSummaryViewModel <BulkJobPostSummaryDetailViewModel>
                    {
                        FileName = file.FileName,
                        Summary  = new List <BulkJobPostSummaryDetailViewModel>()
                    };
                    DataTable dTable = null;
                    NPOIManager.ReadFile(file, dt, out dTable, true, roleName);
                    if (null != dTable && dTable.Rows.Count > 1)
                    {
                        string[] additionalColumns = new string[] { "ProcessedBy", "ProcessedOn", "Status", "ErrorDetails" };
                        //  If at the time of file read we pass true for first row as header then here also we need to pass the same.
                        ExtendTable(additionalColumns, ref dTable, user.UserId, true);

                        //  In Case of multiple cities in Job Location Column we need to divide them in multiple rows as below.
                        SimpliFyTableDataForMultipleCitiesForSingleJob(dTable);
                        JobPostModel jDetail = null;
                        int          rIndex  = -1;
                        foreach (DataRow row in dTable.Rows)
                        {
                            rIndex++;
                            if (rIndex == 0)
                            {
                                fileSummary.Summary.Add(AddSummary(row));
                                continue;
                            }
                            BulkJobPostSummaryDetailViewModel sData = null;
                            row[additionalColumns[0]] = user.FullName;
                            row[additionalColumns[1]] = DateTime.Now;

                            //  Checking if user authorized to post jobs.
                            if (!IsAllowToPostJob(user, row))
                            {
                                row[additionalColumns[2]]  = "Failed";
                                row[additionalColumns[3]] += $"<li>You are not allowed to post this job - Enter company name used while registration.</li>";
                                sData = AddSummary(row);
                                fileSummary.Summary.Add(sData);
                                SaveDetailToAudit(sData, fileSummary.FileName, user.UserId);
                                continue;
                            }
                            try
                            {
                                //Saving JobTitleByEmployer as JobTitle
                                GetJobTitle(row, additionalColumns);

                                ManageJobType(row, additionalColumns);

                                //  Checking if at least one quarter must have a value
                                //ValidateQuarters(row, additionalColumns);

                                //Validate SPOC Contact
                                ValidateSpocContact(row, additionalColumns);

                                // Validate Job Expiry Dates
                                ValidateJobExpiryDates(row, additionalColumns);

                                //   All external validations should be done before this method.
                                ResolveJobData(out jDetail, row, additionalColumns);

                                //  Validate model if some thing needs for default value.
                                ValidateJobModel(ref jDetail);

                                foreach (DataColumn col in dTable.Columns)
                                {
                                    //  Check if any required field is empty
                                    switch (col.ColumnName)
                                    {
                                    case "CompanyName":
                                    case "StateCode":
                                    case "CityCode":
                                    case "JobTitleByEmployer":
                                    case "JobTitleId":
                                    case "SPOC":
                                    case "SPOCEmail":
                                    case "SPOCContact":
                                    //case "CTC":
                                    case "HiringCriteria":
                                    //case "Quarter1":
                                    //case "Quarter2":
                                    //case "Quarter3":
                                    //case "Quarter4":
                                    case "JobType":
                                    case "PositionStartDate":
                                    case "PositionEndDate":
                                        if (string.IsNullOrEmpty(Convert.ToString(row[col.ColumnName])))
                                        {
                                            switch (col.ColumnName)
                                            {
                                            case "JobTitleId":
                                                row[additionalColumns[2]]  = "Failed";
                                                row[additionalColumns[3]] += $"<li>At least one job Title is mandatory</li>";
                                                break;

                                            default:
                                                row[additionalColumns[2]]  = "Failed";
                                                row[additionalColumns[3]] += $"<li>{dTable.Rows[0][col.ColumnName]} is mandatory</li>";
                                                break;
                                            }
                                        }
                                        break;

                                    default:
                                        break;
                                    }
                                    //  Check if master information available in our system or not.
                                    DataTable t = null;
                                    switch (col.ColumnName)
                                    {
                                    //case "FinancialYear":
                                    //    int year = Convert.ToInt32(row[col.ColumnName]);
                                    //    if (year <= 0)
                                    //    {
                                    //        jDetail.GetType().GetProperty(col.ColumnName).SetValue(jDetail, DateTime.Now.Year);
                                    //    }
                                    //    break;
                                    case "StateCode":
                                        string state = Convert.ToString(row[col.ColumnName]);
                                        t =
                                            bjpProcessor.GetIdFromValue(state, col.ColumnName);
                                        if (null != t && t.Rows.Count > 0)
                                        {
                                            jDetail.GetType().GetProperty(col.ColumnName).SetValue(jDetail, t.Rows[0]["Id"]);
                                        }
                                        else
                                        {
                                            //var sModel = new StateModel
                                            //{
                                            //    CountryCode = jDetail.CountryCode,
                                            //    State = state,
                                            //    StateCode = string.Empty
                                            //};
                                            //bjpProcessor.InsertState(ref sModel);
                                            //if (!string.IsNullOrWhiteSpace(sModel.StateCode))
                                            //{
                                            //    jDetail.GetType().GetProperty(col.ColumnName).SetValue(jDetail, sModel.StateCode);
                                            //}
                                            //else
                                            //{
                                            row[additionalColumns[2]]  = "Failed";
                                            row[additionalColumns[3]] += "<li>State Not Found In Our Record</li>";
                                            //}
                                            InformToAdmin(row[col.ColumnName], col.ColumnName, user.Email, user.FullName);
                                        }

                                        break;

                                    case "CityCode":
                                        string city = Convert.ToString(row[col.ColumnName]);
                                        t =
                                            bjpProcessor.GetIdFromValue(city, col.ColumnName);
                                        if (null != t && t.Rows.Count > 0)
                                        {
                                            jDetail.GetType().GetProperty(col.ColumnName).SetValue(jDetail, t.Rows[0]["Id"]);
                                        }
                                        else
                                        {
                                            //var cModel = new CityModel
                                            //{
                                            //    City = city,
                                            //    CityCode = string.Empty,
                                            //    StateCode = jDetail.StateCode
                                            //};
                                            //bjpProcessor.InsertCity(ref cModel);
                                            //if (!string.IsNullOrWhiteSpace(cModel.CityCode))
                                            //{
                                            //    jDetail.GetType().GetProperty(col.ColumnName).SetValue(jDetail, cModel.CityCode);
                                            //}
                                            //else
                                            //{
                                            row[additionalColumns[2]]  = "Failed";
                                            row[additionalColumns[3]] += "<li>City Not Found In Our Record</li>";
                                            //}
                                            InformToAdmin(row[col.ColumnName], col.ColumnName, user.Email, user.FullName);
                                        }
                                        break;

                                    case "SPOCEmail":
                                        string email = Convert.ToString(row[col.ColumnName]);
                                        if (!string.IsNullOrWhiteSpace(email) && email != Constants.NotAvailalbe)
                                        {
                                            if (!emailHandler.IsValidEmail(email))
                                            {
                                                row[additionalColumns[2]]  = "Failed";
                                                row[additionalColumns[3]] += $"<li>SPOC email is not in valid format, please use {Constants.NotAvailalbe} if SPOC email is not available.</li>";
                                            }
                                        }
                                        break;

                                    case "CompanyName":
                                        string companyName = Convert.ToString(row[col.ColumnName]);
                                        if (!authProcessor.CheckIfEmployerExists(companyName, true))
                                        {
                                            string mailId = companyName.ToLower().Replace(" ", "_");
                                            var    u      = new UserModel
                                            {
                                                CompanyName = companyName,
                                                Email       = mailId,
                                                Password    = RandomGenerator.GetRandom(),
                                                RoleId      = 3,
                                                ProfilePic  = string.Empty
                                            };
                                            bool isRegister = authProcessor.RegisterEmployer(u, true);
                                        }
                                        t =
                                            bjpProcessor.GetIdFromValue(companyName, col.ColumnName);
                                        if (null != t && t.Rows.Count > 0)
                                        {
                                            jDetail.Userid = Convert.ToInt32(t.Rows[0]["Id"]);
                                        }
                                        else
                                        {
                                            row[additionalColumns[2]]  = "Failed";
                                            row[additionalColumns[3]] += "<li>User Not Found In Our Record</li>";
                                        }
                                        break;

                                    default:
                                        break;
                                    }
                                }

                                if ("Failed" != Convert.ToString(row[additionalColumns[2]]))
                                {
                                    jDetail.IsFromBulkUpload = true;
                                    jDetail.CreatedBy        = Convert.ToString(user.UserId);
                                    var date = DateTime.Now;
                                    jDetail.FinancialYear = date.Year;
                                    //ValidateJobModel(ref jDetail);
                                    if (jobPostProcessor.AddJobPostData(jDetail))
                                    {
                                        row[additionalColumns[2]] = "Success";
                                    }
                                    else
                                    {
                                        row[additionalColumns[2]] = "Failed";
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                row[additionalColumns[2]]  = "Failed";
                                row[additionalColumns[3]] += $"<li>{ex.Message}</li>";
                            }
                            sData = AddSummary(row);
                            fileSummary.Summary.Add(sData);
                            SaveDetailToAudit(sData, fileSummary.FileName, user.UserId);
                        }
                    }
                    else
                    {
                        throw new DataNotFound(
                                  string.Format("{0}", "Data not found in file to import."));
                    }
                    summary.Add(fileSummary);
                }
                return(summary);
            }
            else
            {
                throw new XmlFileMapperException(
                          string.Format("{0}", "JobPostMapping.xml file is not in proper format to convert in data table."));
            }
        }