public bool UploadFile(UserViewModel user, List <IFormFile> files)
        {
            string roleName = user.RoleName;
            //var status = true;
            string mappingFilePath =
                Path.Combine(environment.WebRootPath, "DataMappings", "PlacedCandidate", "PlacedCandidateMapping.xml");
            DataTable dt = XmlProcessor.XmlToTable(mappingFilePath);

            if (null != dt)
            {
                foreach (var file in files)
                {
                    DataTable dTable = null;
                    NPOIManager.ReadFile(file, dt, out dTable, true, roleName);
                    if (null != dTable && dTable.Rows.Count > 1)
                    {
                        //string[] additionalColumns = new string[] { "CreatedDate", "CreatedBy" };
                        //ExtendTable(additionalColumns, ref dTable, user.UserId, true);
                        //PlacedCandidateModel placeduser = null;
                        int header = -1;
                        foreach (DataRow row in dTable.Rows)
                        {
                            header++;
                            if (header == 0)
                            {
                                continue;
                            }
                            PlacedCandidateModel placeduser = new PlacedCandidateModel()
                            {
                                AverageofNoOfMonthsofPlacement = row["AverageofNoOfMonthsofPlacement"] as string ?? "",
                                AvgofNoofdaysbetweennDOCDOP    = row["AvgofNoofdaysbetweennDOCDOP"] as string ?? "",
                                CandidateEmail             = row["CandidateEmail"] as string ?? "",
                                CandidateID                = row["CandidateID"] as string ?? "",
                                CandidateName              = row["CandidateName"] as string ?? "",
                                Castecategory              = row["Castecategory"] as string ?? "",
                                CertificateDate            = row["CertificateDate"] as string ?? "",
                                Certified                  = row["Certified"] as string ?? "",
                                CountofPartnerID           = row["CountofPartnerID"] as string ?? "",
                                CountofSCTrainingCentreID  = row["CountofSCTrainingCentreID"] as string ?? "",
                                EducationAttained          = row["EducationAttained"] as string ?? "",
                                EmployerspocEmail          = row["EmployerspocEmail"] as string ?? "",
                                EmployerspocMobile         = row["EmployerspocMobile"] as string ?? "",
                                EmployerSpocName           = row["EmployerSpocName"] as string ?? "",
                                EmployerType               = row["EmployerType"] as string ?? "",
                                FirstEmploymentCreatedDate = row["FirstEmploymentCreatedDate"] as string ?? "",
                                FromDate                = row["FromDate"] as string ?? "",
                                FYWise                  = row["FYWise"] as string ?? "",
                                Gender                  = row["Gender"] as string ?? "",
                                Jobrole                 = row["Jobrole"] as string ?? "",
                                OrganisationDistrict    = row["OrganisationDistrict"] as string ?? "",
                                OrganisationState       = row["OrganisationState"] as string ?? "",
                                OrganizationAddress     = row["OrganizationAddress"] as string ?? "",
                                OrganizationName        = row["OrganizationName"] as string ?? "",
                                PartnerName             = row["PartnerName"] as string ?? "",
                                PartnerSPOCEmail        = row["PartnerSPOCEmail"] as string ?? "",
                                PartnerSPOCMobile       = row["PartnerSPOCMobile"] as string ?? "",
                                PartnerSPOCName         = row["PartnerSPOCName"] as string ?? "",
                                SectorName              = row["SectorName"] as string ?? "",
                                SelfEmployedDistrict    = row["SelfEmployedDistrict"] as string ?? "",
                                SelfEmployedState       = row["SelfEmployedState"] as string ?? "",
                                SumofCandidateContactNo = row["AverageofNoOfMonthsofPlacement"] as string ?? "",
                                SumofSalleryPerMonth    = row["SumofSalleryPerMonth"] as string ?? "",
                                SumofTCSPOCMobile       = row["SumofTCSPOCMobile"] as string ?? "",
                                TCDistrict              = row["TCDistrict"] as string ?? "",
                                TCSPOCEmail             = row["TCSPOCEmail"] as string ?? "",
                                TCSPOCName              = row["TCSPOCName"] as string ?? "",
                                TCState                 = row["TCState"] as string ?? "",
                                ToDate                  = row["ToDate"] as string ?? "",
                                TrainingCentreName      = row["TrainingCentreName"] as string ?? "",
                                TrainingType            = row["TrainingType"] as string ?? "",
                            };
                            try
                            {
                                _placedCandidateRepository.UploadFileData(placeduser, user.UserId);
                            }
                            catch (Exception ex)
                            {
                                continue;
                            }
                        }
                    }
                }
            }
            return(true);
        }
        public IEnumerable <BulkUploadSummaryViewModel <BulkJobSeekerUploadSummaryViewModel> > RegisterJobSeekers(UserViewModel user, IList <IFormFile> files)
        {
            string roleName        = user.RoleName;
            string mappingFilePath =
                Path.Combine(environment.WebRootPath, "DataMappings", "BulkJobSeekerMappings", "JobSeekerMapping.xml");
            DataTable dt = XmlProcessor.XmlToTable(mappingFilePath);

            if (null != dt)
            {
                var summary = new List <BulkUploadSummaryViewModel <BulkJobSeekerUploadSummaryViewModel> >();
                foreach (var file in files)
                {
                    var fileSummary = new BulkUploadSummaryViewModel <BulkJobSeekerUploadSummaryViewModel>
                    {
                        FileName = file.FileName,
                        Summary  = new List <BulkJobSeekerUploadSummaryViewModel>()
                    };
                    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);

                        UserModel jsDetail = null;
                        int       rIndex   = -1;
                        foreach (DataRow row in dTable.Rows)
                        {
                            rIndex++;
                            if (rIndex == 0)
                            {
                                fileSummary.Summary.Add(AddSummary(row));
                                continue;
                            }

                            try
                            {
                                row[additionalColumns[0]] = user.FullName;
                                row[additionalColumns[1]] = DateTime.Now;
                                ResolveJobSeekerDetail(out jsDetail, row, additionalColumns);
                                foreach (DataColumn col in dTable.Columns)
                                {
                                    //  Check if any required field is empty
                                    switch (col.ColumnName)
                                    {
                                    case "CandidateId":
                                    case "FirstName":
                                    case "LastName":
                                    case "Email":
                                        if (string.IsNullOrEmpty(Convert.ToString(row[col.ColumnName])))
                                        {
                                            row[additionalColumns[2]]  = "Failed";
                                            row[additionalColumns[3]] += $"<li>{dTable.Rows[0][col.ColumnName]} is mandatory</li>";
                                        }
                                        break;
                                    }

                                    //  Validate User Info
                                    switch (col.ColumnName)
                                    {
                                    //  User already exist or not
                                    case "Email":
                                        if (authProcessor.CheckIfUserExists(Convert.ToString(row[col.ColumnName])))
                                        {
                                            row[additionalColumns[2]]  = "Failed";
                                            row[additionalColumns[3]] += "<li>Candidate is already registered in Placement Portal</li>";
                                        }
                                        else
                                        {
                                            jsDetail.IsActive      = false;
                                            jsDetail.ActivationKey = RandomGenerator.GetRandom(20);
                                            jsDetail.Password      = RandomGenerator.GetRandom();
                                        }
                                        break;

                                    //  Candidate Id already exist or not
                                    case "CandidateId":
                                        if (authProcessor.CheckCandidateIdExist(Convert.ToString(row[col.ColumnName])))
                                        {
                                            row[additionalColumns[2]]  = "Failed";
                                            row[additionalColumns[3]] += "<li>Candidate Id already exist in our system.</li>";
                                        }
                                        else
                                        {
                                            try
                                            {
                                                DataRow r = authProcessor.CandidateResult(Convert.ToString(row[col.ColumnName]));
                                                if (null != r)
                                                {
                                                    jsDetail.GetType().GetProperty("BatchNumber").SetValue(jsDetail, r["BatchNumber"]);
                                                }
                                            }
                                            catch (DataNotFound ex)
                                            {
                                                row[additionalColumns[2]]  = "Failed";
                                                row[additionalColumns[3]] += $"<li>{ex.Message}</li>";
                                            }
                                        }
                                        break;

                                    default:
                                        break;
                                    }
                                }
                                if ("Failed" != Convert.ToString(row[additionalColumns[2]]))
                                {
                                    jsDetail.CreatedBy = Convert.ToInt32(user.UserId);
                                    jsDetail.RoleId    = 2;
                                    int userId = authProcessor.RegisterUser(jsDetail);
                                    if (userId > 0)
                                    {
                                        try
                                        {
                                            jsDetail.UserId = userId;
                                            SendActivationMail(jsDetail);
                                        }
                                        catch (Exception ex)
                                        {
                                            row[additionalColumns[2]]  = "Failed";
                                            row[additionalColumns[3]] += "<li>Unable to send email verification link to user, Please contact your tech deck.</li>";
                                        }
                                        row[additionalColumns[2]] = "Success";
                                    }
                                    else
                                    {
                                        row[additionalColumns[2]]  = "Failed";
                                        row[additionalColumns[3]] += "<li>Unable to register this user, Please contact your tech deck.</li>";
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                row[additionalColumns[2]]  = "Failed";
                                row[additionalColumns[3]] += $"<li>{ex.Message}</li>";
                            }

                            fileSummary.Summary.Add(AddSummary(row));
                        }
                    }
                    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}", "JobSeekerMapping.xml file is not in proper format to convert in data table."));
            }
        }
Ejemplo n.º 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."));
            }
        }