Exemplo n.º 1
0
        private async Task <int> MigrateDropDownSubCategories()
        {
            List <DropDownSubCategory>    records    = sqlDataContext.DropDownSubCategories.ToList();
            DropDownSubCategoryRepository repository = new DropDownSubCategoryRepository();
            int recCount = 0;

            try
            {
                // delete all existing records from Postgres Database
                postgressDataContext.DropDownSubCategories.RemoveRange(postgressDataContext.DropDownSubCategories);
                await postgressDataContext.SaveChangesAsync();

                // Migrage SQL Server data into Postgress database
                foreach (DropDownSubCategory rec in records)
                {
                    postgressDataContext.DropDownSubCategories.Add(rec);
                }
                await postgressDataContext.SaveChangesAsync();

                //await UpdateDropDownSubCategories();
                recCount = records.Count;
            }
            catch (Exception exp)
            {
                MessageBox.Show($"Error while migrating Sub-Categories. The error is {Environment.NewLine}Main Exception: {exp.Message}{Environment.NewLine}Inner Exception: {exp.InnerException?.Message}");
            }
            return(recCount);
        }
Exemplo n.º 2
0
        private void UploadButton_Click(object sender, EventArgs e)
        {
            if (empDataTable == null || (empDataTable != null && empDataTable.Rows.Count == 0))
            {
                MessageBox.Show("No data to upload");
                return;
            }

            try
            {
                EmployeeRepository            repository            = new EmployeeRepository();
                DropDownSubCategoryRepository subCategoryRepository = new DropDownSubCategoryRepository();
                PracticeRepository            practiceRepo          = new PracticeRepository();
                SubPracticeRepository         subPracticeRepo       = new SubPracticeRepository();

                foreach (DataRow row in empDataTable.Rows)
                {
                    try
                    {
                        if (repository.IsDuplicateEmployeeID(row["EmpID"].ToString().Trim()))
                        {
                            row["UploadStatus"]  = "Failed";
                            row["StatusMessage"] = "Duplicate Employee ID";
                            continue;
                        }

                        if (repository.IsDuplicateName(row["FirstName"].ToString().Trim(), row["LastName"].ToString().Trim()))
                        {
                            row["UploadStatus"]  = "Failed";
                            row["StatusMessage"] = "Duplicate Employee Name";
                            continue;
                        }

                        DropDownSubCategoryDto buType = subCategoryRepository.GetByName(row["BU"].ToString(), (int)CategoryType.BusinessUnit);

                        string empID   = row["EmpID"].ToString();
                        string empType = "Permanent";
                        if (empID.StartsWith("CE"))
                        {
                            empType = "Contractor";
                        }
                        else if (empID.StartsWith("CI"))
                        {
                            empType = "Internship";
                        }
                        else if (empID.StartsWith("YTJ"))
                        {
                            empType = "Yet to Join";
                        }
                        DropDownSubCategoryDto employmentType = subCategoryRepository.GetByName(empType, (int)CategoryType.EmploymentType);
                        PracticeDto            practiceDto    = practiceRepo.GetByNameOrDefault(row["POD"].ToString());
                        SubPracticeDto         subPracticeDto = subPracticeRepo.GetByName(row["Competency"].ToString(), practiceDto.PracticeID);
                        EmployeeDto            entry          = new EmployeeDto
                        {
                            BusinessUnitID   = buType.SubCategoryID,
                            DateOfJoin       = DateTime.Parse(row["DoJ"].ToString()),
                            EmployeeID       = empID,
                            EmploymentTypeID = employmentType.SubCategoryID,
                            FirstName        = row["FirstName"].ToString(),
                            LastName         = row["LastName"].ToString(),
                            PracticeID       = practiceDto.PracticeID,
                            PrimarySkills    = row["PrimarySkills"].ToString(),
                            SecondarySkills  = row["SecondarySkills"].ToString(),
                            SubPracticeID    = subPracticeDto.SubPracticeID,
                        };

                        if (string.IsNullOrWhiteSpace(row["LWD"].ToString()) == false)
                        {
                            entry.LastWorkingDay = DateTime.Parse(row["LWD"].ToString());
                        }

                        repository.Add(entry);
                        row["UploadStatus"]  = "Successfully Uploaded";
                        row["StatusMessage"] = "";
                    }
                    catch (Exception exp)
                    {
                        row["UploadStatus"]  = "Failed";
                        row["StatusMessage"] = exp.Message;
                    }
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
        }