private static void ReadDataFromBase(EmployeesDAL employeesDAL)
        {
            try
            {
                WriteLine($"Количество строк в таблице: {employeesDAL.CountRows}");
                SqlDataReader reader;
                reader = employeesDAL.Select();
                WriteLine("Объект чтения данных --> " + reader.GetType().Name);

                while (reader.Read())
                {
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        Write($"|{reader[i],15}");
                    }
                    WriteLine();
                }
            }
            catch (SqlException ex)
            {
                WriteLine(ex.Message);
            }
            finally
            {
                employeesDAL.CloseConnection();
            }
        }
        public int AddEmployeeAttendance(EmployeeAttendance attendance)
        {
            //Modified by Talha: Jan 26th, 2012 - Added Return variable to ensure data inserted successfully
            int cmd_success;

            cmd_success = new EmployeesDAL().Insert(attendance);
            return(cmd_success);
        }
Example #3
0
        public List <Employee> GetEmployees(int id)
        {
            List <Employee> employees = new EmployeesDAL().GetEmployees(id);

            employees.All(x => { x.AnnualSalary = EmployeeFactory.getEmployeeType(x.contractTypeName).getAnnualSalary(x.hourlySalary, x.monthlySalary); return(true); });

            return(employees);
        }
 public ActionResult Create(EmployeesViewModel model)
 {
     if (EmployeesDAL.Add(model))
     {
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View(model));
     }
 }
Example #5
0
 public virtual int Add()
 {
     try
     {
         EmployeesDAL employeeDal = new EmployeesDAL();
         Employees    employee    = new Employees()
         {
             EmployeeIDNo              = this.EmployeeIDNo,
             FirstNameAr               = this.FirstNameAr,
             MiddleNameAr              = this.MiddleNameAr,
             GrandFatherNameAr         = this.GrandFatherNameAr,
             FifthNameAr               = this.FifthNameAr,
             LastNameAr                = this.LastNameAr,
             FirstNameEn               = this.FirstNameEn,
             MiddleNameEn              = this.MiddleNameEn,
             GrandFatherNameEn         = this.GrandFatherNameEn,
             FifthNameEn               = this.FifthNameEn,
             LastNameEn                = this.LastNameEn,
             EmployeeBirthDate         = (DateTime)this.EmployeeBirthDate.Value.Date,
             EmployeeBirthPlace        = this.EmployeeBirthPlace,
             EmployeeMobileNo          = this.EmployeeMobileNo,
             EmployeePassportNo        = this.EmployeePassportNo,
             EmployeeEMail             = this.EmployeeEMail,
             EmployeeIDIssueDate       = this.EmployeeIDIssueDate != null ? (DateTime)this.EmployeeIDIssueDate.Value.Date : (DateTime?)null,
             EmployeePassportSource    = this.EmployeePassportSource,
             EmployeePassportIssueDate = this.EmployeePassportIssueDate != null ? (DateTime)this.EmployeePassportIssueDate.Value.Date : (DateTime?)null,
             EmployeePassportEndDate   = this.EmployeePassportEndDate != null ? (DateTime)this.EmployeePassportEndDate.Value.Date : (DateTime?)null,
             EmployeeIDExpiryDate      = this.EmployeeIDExpiryDate,
             EmployeeIDCopyNo          = this.EmployeeIDCopyNo,
             EmployeeIDIssuePlace      = this.EmployeeIDIssuePlace,
             DependentCount            = this.DependentCount,
             MaritalStatusID           = this.MaritalStatus.MaritalStatusID,
             GenderID      = this.Gender.GenderID,
             NationalityID = this.Nationality.CountryID,
             CreatedDate   = DateTime.Now,
             CreatedBy     = this.LoginIdentity.EmployeeCodeID,
         };
         employeeDal.Insert(employee);
         return(this.EmployeeID);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #6
0
        public virtual List <EmployeesBLL> GetEmployees()
        {
            try
            {
                List <Employees>    EmployeesList    = new EmployeesDAL().GetEmployees();
                List <EmployeesBLL> EmployeesBLLList = new List <EmployeesBLL>();
                foreach (var item in EmployeesList)
                {
                    EmployeesBLLList.Add(new EmployeesBLL().MapEmployee(item));
                }

                return(EmployeesBLLList.ToList());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #7
0
        public virtual EmployeesBLL GetByEmployeeID(int EmployeeID)
        {
            try
            {
                EmployeesBLL EmployeeBLL = null;
                Employees    Employee    = new EmployeesDAL().GetByEmployeeID(EmployeeID);
                if (Employee != null)
                {
                    EmployeeBLL = this.MapEmployee(Employee);
                }

                return(EmployeeBLL);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #8
0
        public async Task <ResultPT> InsertAsync(EmployeesDTO objEmployeesDTO)
        {
            try
            {
                objResultPT = new ResultPT();
                using (EmployeesDAL objEmployeesDAL = new EmployeesDAL())
                {
                    objResultPT.ReturnObject = await objEmployeesDAL.InsertAsync(objEmployeesDTO);

                    if (Convert.ToInt32(objResultPT.ReturnObject) == 2)
                    {
                        objResultPT.ResultMsg         = string.Format(Messages.ObjectExist, "Employees");
                        objResultPT.TransactionStatus = Enums.ResultStatus.Warning;
                    }
                    else if (Convert.ToInt32(objResultPT.ReturnObject) > 0)
                    {
                        objResultPT.ResultMsg         = Messages.Success;
                        objResultPT.TransactionStatus = Enums.ResultStatus.Success;
                    }
                    else if (Convert.ToInt32(objResultPT.ReturnObject) == 0)
                    {
                        objResultPT.ResultMsg         = Messages.NoDataFound;
                        objResultPT.TransactionStatus = Enums.ResultStatus.Information;
                    }
                    else
                    {
                        objResultPT.ResultMsg         = Messages.Error;
                        objResultPT.TransactionStatus = Enums.ResultStatus.Failure;
                    }
                }
                return(objResultPT);
            }
            catch (Exception Ex)
            {
                ////log error message into database.
                await this.LogErrorAsync(ErrorLog.ApplicationName.BAL, System.Reflection.MethodBase.GetCurrentMethod().Name, Ex.Message, Ex.StackTrace);

                objResultPT.TransactionStatus = Enums.ResultStatus.Failure;
                objResultPT.ResultMsg         = Ex.Message;
            }

            return(objResultPT);
        }
Example #9
0
 public EmployeesBLL GetByEmployeeNameAr(string EmployeeNameAr)
 {
     try
     {
         Employees Employee = new EmployeesDAL().GetByEmployeeNameAr(EmployeeNameAr);
         if (Employee != null)
         {
             EmployeesBLL EmployeeBLL = MapEmployee(Employee);
             EmployeeBLL.EmployeePicture = EmployeeBLL.GetEmployeePicture();
             return(EmployeeBLL);
         }
         else
         {
             return(null);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #10
0
 public virtual EmployeesBLL GetByEmployeeIDWithEmpPic(int EmployeeID)
 {
     try
     {
         Employees Employee = new EmployeesDAL().GetByEmployeeID(EmployeeID);
         if (Employee != null)
         {
             EmployeesBLL EmployeeBLL = MapEmployee(Employee);
             EmployeeBLL.EmployeePicture = EmployeeBLL.GetEmployeePicture();
             return(EmployeeBLL);
         }
         else
         {
             return(null);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #11
0
        public async Task <ResultPT> GetAllAsync( )
        {
            try
            {
                objResultPT = new ResultPT();
                using (EmployeesDAL objEmployeesDAL = new EmployeesDAL())
                {
                    objResultPT.ReturnObject = await objEmployeesDAL.GetAllAsync();
                }
                throw new Exception("Error Test");
                return(objResultPT);
            }
            catch (Exception Ex)
            {
                ////log error message into database.
                await this.LogErrorAsync(ErrorLog.ApplicationName.BAL, System.Reflection.MethodBase.GetCurrentMethod().Name, Ex.Message, Ex.StackTrace);

                objResultPT.TransactionStatus = Enums.ResultStatus.Failure;
                objResultPT.ResultMsg         = Ex.Message;
            }

            return(objResultPT);
        }
Example #12
0
////    public async Task<ResultPT> DeleteAllAsync()
////    {
////		try
////        {
////			objResultPT = new ResultPT();
////			using (EmployeesDAL objEmployeesDAL = new EmployeesDAL())
////            {
////                 objResultPT.ReturnObject = objEmployeesDAL.DeleteAll();
////                objResultPT.TransactionStatus = Enums.ResultStatus.Success;
////                objResultPT.ResultMsg = "success";
////            }
////			return objResultPT;
////		}
////        catch (Exception Ex)
////        {
////            ////log error message into database.
////            await this.LogError(ErrorLog.application.BAL, System.Reflection.MethodBase.GetCurrentMethod().Name, Ex.Message, Ex.StackTrace);
////            objResultPT.TransactionStatus = Enums.ResultStatus.Failure;
////            objResultPT.ResultMsg = Ex.Message;
////        }
////		 return objResultPT;
////    }

        public async Task <ResultPT> GetByIDAsync(long ID)
        {
            try
            {
                objResultPT = new ResultPT();
                using (EmployeesDAL objEmployeesDAL = new EmployeesDAL())
                {
                    DataSet dset = await objEmployeesDAL.GetByIDAsync(ID);

                    if (dset.Tables.Count > 0 && dset.Tables[0].Rows.Count > 0)
                    {
                        DataTable dt = dset.Tables[0];
                        objResultPT.ReturnObject      = CommonFunctions.FillProperties <EmployeesDTO>(dt.Rows[0]);
                        objResultPT.ResultMsg         = Messages.Success;
                        objResultPT.TransactionStatus = Enums.ResultStatus.Success;
                    }
                    else
                    {
                        objResultPT.ReturnObject      = "";
                        objResultPT.ResultMsg         = Messages.NoDataFound;
                        objResultPT.TransactionStatus = Enums.ResultStatus.NodData;
                    }
                }
                return(objResultPT);
            }
            catch (Exception Ex)
            {
                ////log error message into database.
                await this.LogErrorAsync(ErrorLog.ApplicationName.BAL, System.Reflection.MethodBase.GetCurrentMethod().Name, Ex.Message, Ex.StackTrace);

                objResultPT.TransactionStatus = Enums.ResultStatus.Failure;
                objResultPT.ResultMsg         = Ex.Message;
            }

            return(objResultPT);
        }
Example #13
0
 public static void Delete(EmployeesDTO employeesTypes)
 {
     EmployeesDAL.Delete(EmployeesCast.ToDAL(employeesTypes));
 }
 // GET: Employees
 public ActionResult Index()
 {
     return(View(EmployeesDAL.GetAll()));
 }
Example #15
0
 public static EmployeesDTO login(string username, string password)
 {
     return(EmployeesCast.ToDTO(EmployeesDAL.Login(username, password)));
 }
 public Employees_Business_Manager()
 {
     _employeesDAL = new EmployeesDAL();
 }
Example #17
0
 public static void Update(EmployeesDTO employeesTypes)
 {
     EmployeesDAL.Update(EmployeesCast.ToDAL(employeesTypes));
 }
Example #18
0
 public static List <EmployeesDTO> GetAll()
 {
     return(EmployeesCast.ListToDTO(EmployeesDAL.GetAll()));
 }
        static void Main(string[] args)
        {
            //string connectionString =
            //    @"  Data Source=(localdb)\MSSQLLocalDB;
            //        Initial Catalog=DataEmployees_22_08_2019;
            //        Integrated Security=True;
            //        Connect Timeout=30;
            //        Encrypt=False;
            //        TrustServerCertificate=False;
            //        ApplicationIntent=ReadWrite;
            //        MultiSubnetFailover=False";

            string connectionString =
                @"  Data Source=andrey-kotelnik\sqlexpress;
                    Initial Catalog=EmployeesDataMSSQL;
                    Integrated Security=True";


            ConnectionString.Text = connectionString;
            EmployeesDAL   employeesDAL   = new EmployeesDAL();
            DepartmentsDAL departmentsDAL = new DepartmentsDAL();


            try
            {
                ReadDataFromBase(employeesDAL);
                employeesDAL.OpenConnection();
                //SqlDataAdapter dataAdapter = employeesDAL.GetDataAdapter();
                ////SqlParameter[] parameters = new SqlParameter[cmdTest.Parameters.Count];
                ////cmdTest.Parameters.CopyTo(parameters, 0);
                ////cmdTest.Parameters.Remove(parameters[0]);
                ////parameters[0].Value = 58;
                ////cmdTest.Parameters.Add(parameters[0]);

                ////cmdTest.ExecuteNonQuery();
                ////employeesDAL.CloseConnection();
                //DataTable table = new DataTable();
                //dataAdapter.Fill(table);
                //DataRow rowUpd = table.Rows[0];
                //var res = rowUpd.ItemArray.GetValue(1);
                //var f = rowUpd.ItemArray.IsReadOnly;
                //rowUpd.ItemArray[1] = "ИИИИИИИИ";
                //var arr = rowUpd.ItemArray;
                //arr[1] = "Иваныч2";
                //rowUpd.ItemArray = arr;
                //res = rowUpd.ItemArray.GetValue(1);

                //DataRow row = table.NewRow();
                //row[1] = "Andr2";
                //row[2] = "Andr2";
                //row[3] = 35;
                //table.Rows.Add(row);

                //table.AcceptChanges();
                //WriteLine($"The number of rows successfully updated: {dataAdapter.Update(table)}");


                //////employeesDAL.OpenConnection();
                var empList = Employee.GetEmployees();

                foreach (var item in empList)
                {
                    employeesDAL.Insert(item.Name, item.Surname, item.Age, item.DepID);
                }


                //WriteLine($"Номер вставленной строки: {employeesDAL.Insert("Й", "Й", 10, null)}");
                WriteLine($"Количество строк в таблице: {employeesDAL.CountRows}");
                //employeesDAL.Delete(25);
                //employeesDAL.Update(8, "8", "8", 8, 1);
                SqlDataReader reader;
                reader = employeesDAL.Select();
                WriteLine("Объект чтения данных --> " + reader.GetType().Name);

                while (reader.Read())
                {
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        Write($"|{reader[i],15}");
                    }
                    WriteLine();
                }
            }
            catch (SqlException ex)
            {
                WriteLine(ex.Message);
            }
            finally
            {
                employeesDAL.CloseConnection();
            }

            //try
            //{
            //    departmentsDAL.OpenConnection();
            //    WriteLine($"Номер вставленной строки: {departmentsDAL.Insert("qwerty")}");
            //    WriteLine($"Количество строк в таблице: {departmentsDAL.CountRows}");
            //    departmentsDAL.Delete(3);
            //    departmentsDAL.Update(1, "FFFFFF");
            //    SqlDataReader reader;
            //    reader = departmentsDAL.Select();
            //    WriteLine("Объект чтения данных --> " + reader.GetType().Name);

            //    while (reader.Read())
            //    {
            //        for (int i = 0; i < reader.FieldCount; i++)
            //        {
            //            Write($"|{reader[i],15}");
            //        }
            //        WriteLine();
            //    }

            //}
            //catch (SqlException ex)
            //{

            //    WriteLine(ex.Message);
            //}
            //finally
            //{
            //    departmentsDAL.CloseConnection();
            //}

            //SqlDataAdapter dataAdapterEmp = employeesDAL.GetDataAdapter();
            //DataTable dataEmp = new DataTable("Employees");


            //SqlDataAdapter dataAdapterDep = departmentsDAL.GetDataAdapter();
            //DataTable dataDep = new DataTable("Departments");

            //try
            //{
            //    dataAdapterEmp.Fill(dataEmp);
            //}
            //catch (SqlException ex)
            //{

            //    WriteLine(ex.Message);
            //}
            //try
            //{
            //    dataAdapterDep.Fill(dataDep);
            //}
            //catch (SqlException ex)
            //{

            //    WriteLine(ex.Message);
            //}

            //WriteLine($"Столбцы в Emp: { dataEmp.Columns.Count}");
            //WriteLine($"Столбцы в Dep: { dataDep.Columns.Count}");
        }
Example #20
0
        public virtual int AddHiringNewEmployee(EmployeesBLL EmployeesBLL, EmployeesCodesBLL EmployeesCodesBLL, EmployeesCareersHistoryBLL EmployeesCareersHistoryBLL, EmployeesQualificationsBLL EmployeesQualificationsBLL, ContractorsBasicSalariesBLL ContractorsBasicSalariesBLL, List <EmployeesAllowancesBLL> EmployeesAllowancesBLLLst)
        {
            try
            {
                EmployeesDAL employeeDal = new EmployeesDAL();
                Employees    employee    = new Employees()
                {
                    EmployeeIDNo              = this.EmployeeIDNo,
                    FirstNameAr               = this.FirstNameAr,
                    MiddleNameAr              = this.MiddleNameAr,
                    GrandFatherNameAr         = this.GrandFatherNameAr,
                    FifthNameAr               = this.FifthNameAr,
                    LastNameAr                = this.LastNameAr,
                    FirstNameEn               = this.FirstNameEn,
                    MiddleNameEn              = this.MiddleNameEn,
                    GrandFatherNameEn         = this.GrandFatherNameEn,
                    FifthNameEn               = this.FifthNameEn,
                    LastNameEn                = this.LastNameEn,
                    EmployeeBirthDate         = (DateTime)this.EmployeeBirthDate.Value.Date,
                    EmployeeBirthPlace        = this.EmployeeBirthPlace,
                    EmployeeMobileNo          = this.EmployeeMobileNo,
                    EmployeePassportNo        = this.EmployeePassportNo,
                    EmployeeEMail             = this.EmployeeEMail,
                    EmployeeIDIssueDate       = this.EmployeeIDIssueDate != null ? (DateTime)this.EmployeeIDIssueDate.Value.Date : (DateTime?)null,
                    EmployeePassportSource    = this.EmployeePassportSource,
                    EmployeePassportIssueDate = this.EmployeePassportIssueDate != null ? (DateTime)this.EmployeePassportIssueDate.Value.Date : (DateTime?)null,
                    EmployeePassportEndDate   = this.EmployeePassportEndDate != null ? (DateTime)this.EmployeePassportEndDate.Value.Date : (DateTime?)null,
                    EmployeeIDExpiryDate      = this.EmployeeIDExpiryDate,
                    EmployeeIDCopyNo          = this.EmployeeIDCopyNo,
                    EmployeeIDIssuePlace      = this.EmployeeIDIssuePlace,
                    DependentCount            = this.DependentCount,
                    MaritalStatusID           = this.MaritalStatus.MaritalStatusID,
                    GenderID      = this.Gender.GenderID,
                    NationalityID = this.Nationality.CountryID,
                    CreatedDate   = DateTime.Now,
                    CreatedBy     = this.LoginIdentity.EmployeeCodeID,
                };
                EmployeesCodes employeesCode = new EmployeesCodes()
                {
                    EmployeeCodeNo = EmployeesCodesBLL.EmployeeCodeNo,
                    EmployeeTypeID = EmployeesCodesBLL.EmployeeType.EmployeeTypeID,
                    IsActive       = true,
                    CreatedDate    = DateTime.Now,
                    CreatedBy      = this.LoginIdentity.EmployeeCodeID
                };

                EmployeesCareersHistory employeeCareerHistory = new EmployeesCareersHistory()
                {
                    CareerHistoryTypeID  = EmployeesCareersHistoryBLL.CareerHistoryType.CareerHistoryTypeID,
                    CareerDegreeID       = EmployeesCareersHistoryBLL.CareerDegree.CareerDegreeID,
                    OrganizationJobID    = EmployeesCareersHistoryBLL.OrganizationJob.OrganizationJobID,
                    JoinDate             = EmployeesCareersHistoryBLL.JoinDate.Date,
                    TransactionStartDate = EmployeesCareersHistoryBLL.JoinDate.Date,
                    IsActive             = true,
                    CreatedBy            = this.LoginIdentity.EmployeeCodeID,
                    CreatedDate          = DateTime.Now
                };
                EmployeesQualifications employeeQualification = new EmployeesQualifications();
                employeeQualification.QualificationDegreeID   = EmployeesQualificationsBLL.QualificationDegree.QualificationDegreeID;
                employeeQualification.QualificationID         = EmployeesQualificationsBLL.Qualification.QualificationID;
                employeeQualification.GeneralSpecializationID = EmployeesQualificationsBLL.GeneralSpecialization.GeneralSpecializationID;
                employeeQualification.ExactSpecializationID   = EmployeesQualificationsBLL.ExactSpecialization.ExactSpecializationID == 0 ? (int?)null : EmployeesQualificationsBLL.ExactSpecialization.ExactSpecializationID;
                employeeQualification.UniSchName          = EmployeesQualificationsBLL.UniSchName;
                employeeQualification.Department          = EmployeesQualificationsBLL.Department;
                employeeQualification.FullGPA             = EmployeesQualificationsBLL.FullGPA;
                employeeQualification.GPA                 = EmployeesQualificationsBLL.GPA;
                employeeQualification.StudyPlace          = EmployeesQualificationsBLL.StudyPlace;
                employeeQualification.GraduationDate      = EmployeesQualificationsBLL.GraduationDate;
                employeeQualification.GraduationYear      = EmployeesQualificationsBLL.GraduationYear;
                employeeQualification.Percentage          = EmployeesQualificationsBLL.Percentage;
                employeeQualification.QualificationTypeID = EmployeesQualificationsBLL.QualificationType.QualificationTypeID == 0 ? (int?)null : EmployeesQualificationsBLL.QualificationType.QualificationTypeID;
                employeeQualification.CreatedDate         = DateTime.Now;
                employeeQualification.CreatedBy           = this.LoginIdentity.EmployeeCodeID;

                ContractorsBasicSalaries contractorBasicSalary = new ContractorsBasicSalaries();
                contractorBasicSalary.BasicSalary        = ContractorsBasicSalariesBLL.BasicSalary;
                contractorBasicSalary.TransfareAllowance = ContractorsBasicSalariesBLL.TransfareAllowance;
                contractorBasicSalary.CreatedDate        = DateTime.Now;
                contractorBasicSalary.CreatedBy          = this.LoginIdentity.EmployeeCodeID;

                List <EmployeesAllowances> employeesAllowancesList = new List <EmployeesAllowances>();
                foreach (var EmployeeAllowanceBLL in EmployeesAllowancesBLLLst)
                {
                    employeesAllowancesList.Add(new EmployeesAllowances()
                    {
                        AllowanceID        = EmployeeAllowanceBLL.Allowance.AllowanceID,
                        AllowanceStartDate = EmployeeAllowanceBLL.AllowanceStartDate,
                        IsActive           = EmployeeAllowanceBLL.IsActive,
                        CreatedBy          = this.LoginIdentity.EmployeeCodeID,
                        CreatedDate        = DateTime.Now
                    });
                }


                employee.EmployeesCodes = new List <EmployeesCodes>();
                employee.EmployeesCodes.Add(employeesCode);
                employeesCode.EmployeesCareersHistory = new List <EmployeesCareersHistory>();
                employeesCode.EmployeesCareersHistory.Add(employeeCareerHistory);
                employeesCode.EmployeesQualifications = new List <EmployeesQualifications>();
                employeesCode.EmployeesQualifications.Add(employeeQualification);
                #region check if the new employee is contractor then add financial advantages to him
                OrganizationsJobsBLL OrganizationsJobsBLL = new OrganizationsJobsBLL().GetByOrganizationJobID(employeeCareerHistory.OrganizationJobID);
                if (OrganizationsJobsBLL.Rank.RankCategory.RankCategoryID == (int)RanksCategoriesEnum.ContractualExpats || OrganizationsJobsBLL.Rank.RankCategory.RankCategoryID == (int)RanksCategoriesEnum.ContractualSaudis)
                {
                    employeesCode.ContractorsBasicSalaries = new List <ContractorsBasicSalaries>();
                    employeesCode.ContractorsBasicSalaries.Add(contractorBasicSalary);
                    employeeCareerHistory.EmployeesAllowances = employeesAllowancesList;
                }
                #endregion
                employeeDal.Insert(employee);
                return(this.EmployeeID);
            }
            catch
            {
                throw;
            }
        }
Example #21
0
        public bool DeleteEmployeeData(Hr_Employees objUpdate, List <Hr_EmpDues> ListDtlsEmpDus, Hr_EmpDuesVactionTicket Obj_DtlsVaction)
        {
            StackFrame stackFrame      = new StackFrame();
            MethodBase methodBase      = stackFrame.GetMethod();
            bool       result          = false;
            var        strErrorMessage = string.Empty;

            try
            {
                //int resultUpdateEmployee = 0;
                Guid?   varEmpHdrId;
                decimal varEmpSerialNo;
                string  varBranchId, varCompanyId;
                varEmpHdrId    = ListDtlsEmpDus[0].EmpHdrId;
                varEmpSerialNo = ListDtlsEmpDus[0].Emp_Serial_No;
                varBranchId    = ListDtlsEmpDus[0].Branch_Id;
                varCompanyId   = ListDtlsEmpDus[0].Company_Id;

                using (AthelHREntities varcontext = new AthelHREntities())
                {
                    using (var dbContextTransaction = varcontext.Database.BeginTransaction())
                    {
                        try
                        {
                            if (varcontext.Database.Connection.State == System.Data.ConnectionState.Closed)
                            {
                                varcontext.Database.Connection.Open();
                            }

                            //OpenEntityConnection();

                            EmpDuesDAL objEmpGrade = new EmpDuesDAL();

                            result = objEmpGrade.DeleteEmpDuesHireItemByContext(varBranchId, varCompanyId, varEmpHdrId, varEmpSerialNo, varcontext);

                            if (result)
                            {
                                //EmpSpousesDAL objSpouses = new EmpSpousesDAL();

                                //result = objSpouses.DeleteEmpSpousesByContext(varBranchId, varCompanyId, varEmpHdrId, varEmpSerialNo, varcontext);
                                //if (result)
                                //{

                                EmpDuesVactionTicketDAL objEmpVaction = new EmpDuesVactionTicketDAL();
                                Obj_DtlsVaction.EmpHdrId   = varEmpHdrId;
                                Obj_DtlsVaction.UpdateUser = UserNameProperty;

                                result = objEmpVaction.DeleteEmpVactionTicketByContext(varBranchId, varCompanyId, varEmpHdrId, varEmpSerialNo, varcontext);

                                if (result)
                                {
                                    EmployeesDAL objEmp = new EmployeesDAL();
                                    objUpdate.EmpHdrId   = varEmpHdrId;
                                    objUpdate.DeleteUser = UserNameProperty;
                                    result = objEmp.DeleteTaskByContext(objUpdate, varcontext);

                                    //result = (resultInsertEmployee > 0);
                                    varcontext.SaveChanges();
                                    dbContextTransaction.Commit();
                                }
                            }
                            //}


                            else
                            {
                                dbContextTransaction.Rollback();
                                result = false;
                            }
                        }
                        catch (DbEntityValidationException ex)
                        {
                            var errorMessages = ex.EntityValidationErrors
                                                .SelectMany(x => x.ValidationErrors)
                                                .Select(x => x.ErrorMessage);

                            // Join the list to a single string.
                            var fullErrorMessage = string.Join("; ", errorMessages);

                            // Combine the original exception message with the new one.
                            var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);
                            strErrorMessage = fullErrorMessage;
                            // Throw a new DbEntityValidationException with the improved exception message.
                            throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                            //((System.Data.Entity.Validation.DbEntityValidationException)$exception).EntityValidationErrors.First().ValidationErrors.First().ErrorMessage
                            //   dbTran.Rollback();
                            dbContextTransaction.Rollback();
                            result = false;
                        }
                        //--- End Try Of Using
                        catch (Exception ex)
                        {
                            dbContextTransaction.Rollback(); //Required according to MSDN article
                            throw;                           //Not in MSDN article, but recommended so the exception still bubbles up
                        }
                        finally
                        {
                            varcontext.Database.Connection.Close();
                            dbContextTransaction.Dispose();
                        }

                        //--- End catch
                    }
                    //--- End Using
                }
            }

            //--- End Try


            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);
                strErrorMessage = fullErrorMessage;
                // Throw a new DbEntityValidationException with the improved exception message.
                throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                //((System.Data.Entity.Validation.DbEntityValidationException)$exception).EntityValidationErrors.First().ValidationErrors.First().ErrorMessage
                //   dbTran.Rollback();
                result = false;
            }
            catch (Exception ex)
            {
                //Rollback transaction if exception occurs
                //  dbTran.Rollback();
                result = false;
            }

            finally
            {
                objPharmaEntities.Database.Connection.Close();
                //  dbTran.Dispose();

                if (!string.IsNullOrEmpty(strErrorMessage))
                {
                    SaveErrorLog(System.Runtime.InteropServices.Marshal.GetExceptionCode().ToString(), strErrorMessage, this.UserNameProperty.ToString(), this.GetType().Name.ToString(), methodBase.Name.ToString());
                }
            }

            return(result);
        }
Example #22
0
 public static EmployeesDTO GetById(int id)
 {
     return(EmployeesCast.ToDTO(EmployeesDAL.GetById(id)));
 }
Example #23
0
        public void TestName1(string user_name, string password)
        {
            EmployeesDAL e = new EmployeesDAL();

            Assert.NotNull(e.GetEmployeeByUserPassword(user_name, password));
        }
Example #24
0
 public static void Add(EmployeesDTO employeesTypes)
 {
     EmployeesDAL.Add(EmployeesCast.ToDAL(employeesTypes));
 }