public Hr_EmpDuesVactionTicket SelectAllEmpVactionTicket(string Company_Id, string Branch_Id, decimal Emp_Serial, Guid EmpHdrId)
        {
            StackFrame stackFrame = new StackFrame();
            MethodBase methodBase = stackFrame.GetMethod();

            try
            {
                OpenEntityConnection();


                Hr_EmpDuesVactionTicket objectList = new Hr_EmpDuesVactionTicket();

                var objlist = (from objLinq in objPharmaEntities.Hr_EmpDuesVactionTicket
                               where objLinq.Company_Id == Company_Id && objLinq.Branch_Id == Branch_Id && objLinq.Emp_Serial_No == Emp_Serial && objLinq.EmpHdrId == EmpHdrId

                               select new
                {
                    Branch_Id = objLinq.Branch_Id,
                    Company_Id = objLinq.Company_Id,
                    GradeJob_Id = objLinq.GradeJob_Id,
                    VactionPeriod = objLinq.VactionPeriod,
                    VactionTicketType = objLinq.VactionTicketType,
                    InternationalWorkTicketType = objLinq.InternationalWorkTicketType,
                    LocalWorkTicketType = objLinq.LocalWorkTicketType,
                    WorkingMonthNo = objLinq.WorkingMonthNo,
                    WorkingPeriodType = objLinq.WorkingPeriodType,
                    Emp_Serial_No = objLinq.Emp_Serial_No,
                    EmpHdrId = objLinq.EmpHdrId,
                    CountTicket = objLinq.CountTicket,
                }).FirstOrDefault();
                if (objlist != null)
                {
                    Hr_EmpDuesVactionTicket objEmpVactionTicketDL = new Hr_EmpDuesVactionTicket();

                    objEmpVactionTicketDL.Branch_Id                   = objlist.Branch_Id;
                    objEmpVactionTicketDL.Company_Id                  = objlist.Company_Id;
                    objEmpVactionTicketDL.GradeJob_Id                 = objlist.GradeJob_Id;
                    objEmpVactionTicketDL.VactionPeriod               = objlist.VactionPeriod;
                    objEmpVactionTicketDL.VactionTicketType           = objlist.VactionTicketType;
                    objEmpVactionTicketDL.InternationalWorkTicketType = objlist.InternationalWorkTicketType;
                    objEmpVactionTicketDL.LocalWorkTicketType         = objlist.LocalWorkTicketType;
                    objEmpVactionTicketDL.WorkingMonthNo              = objlist.WorkingMonthNo;
                    objEmpVactionTicketDL.WorkingPeriodType           = objlist.WorkingPeriodType;
                    objEmpVactionTicketDL.Emp_Serial_No               = objlist.Emp_Serial_No;
                    objEmpVactionTicketDL.CountTicket                 = objlist.CountTicket;

                    objEmpVactionTicketDL.EmpHdrId = objlist.EmpHdrId;

                    return(objEmpVactionTicketDL);
                }
                else
                {
                    return(null);
                }



                //Rec_No ,ReferenceNo ,BranchAccount_Id
                //,Company_Id ,Branch_Id ,Emp_Serial_No ,TransDate ,FromDate ,ToDate ,BackDate ,Reason ,InsUser ,InsDate ,Order_Status ,PlaceOfResidence ,DocumentPath ,BranchAccountTypeName ,StatusName
            }
            catch (Exception ex)
            {
                catchEntityvalidation((System.Data.Entity.Validation.DbEntityValidationException)ex, System.Runtime.InteropServices.Marshal.GetExceptionCode().ToString(),
                                      this.UserNameProperty.ToString(), this.GetType().Name.ToString(), methodBase.Name.ToString());
                ex.InnerException.Message.ToString();
                return(null);
            }
            finally
            {
                CloseEntityConnection();
            }
        }
        public bool AddNewRecord(Hr_EmpDuesVactionTicket Obj_Dtls)
        {
            StackFrame stackFrame = new StackFrame();
            MethodBase methodBase = stackFrame.GetMethod();

            var strErrorMessage = string.Empty;
            //  ObjWorkFlow_HdrDL.InsUser = "******";

            // ObjCommTransHeaderDL.InsDate = DateTime.Now.ToString("dd/MM/yyyy");
            bool result = true;

            //using (System.Data.Entity.DbContextTransaction dbTran = objPharmaEntities.Database.BeginTransaction())
            //{
            try
            {
                if (objPharmaEntities.Database.Connection.State == System.Data.ConnectionState.Closed)
                {
                    objPharmaEntities.Database.Connection.Open();
                }


                if (Obj_Dtls != null)
                {
                    Hr_EmpDuesVactionTicket loclDtls = new Hr_EmpDuesVactionTicket
                    {
                        EmpHdrId                    = Obj_Dtls.EmpHdrId,
                        Branch_Id                   = Obj_Dtls.Branch_Id,
                        Company_Id                  = Obj_Dtls.Company_Id,
                        GradeJob_Id                 = Obj_Dtls.GradeJob_Id,
                        Emp_Serial_No               = 0,
                        VactionPeriod               = Obj_Dtls.VactionPeriod,
                        VactionTicketType           = Obj_Dtls.VactionTicketType,
                        InternationalWorkTicketType = Obj_Dtls.InternationalWorkTicketType,
                        LocalWorkTicketType         = Obj_Dtls.LocalWorkTicketType,
                        WorkingMonthNo              = Obj_Dtls.WorkingMonthNo,
                        WorkingPeriodType           = Obj_Dtls.WorkingPeriodType,

                        InsDate = DateTime.Now,
                        InsUser = Obj_Dtls.InsUser
                    };

                    objPharmaEntities.Hr_EmpDuesVactionTicket.Add(loclDtls);
                    //saves all above operations within one transaction
                    // objPharmaEntities.SaveChanges();

                    // dbTran.Commit();
                    // }
                }
                //}


                //commit transaction
                //  dbTran.Commit();
            }
            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);

            //  }
        }
        public bool UpdateNewRecordByContext(Hr_EmpDuesVactionTicket objUpdate, AthelHREntities varContext)
        {
            StackFrame stackFrame = new StackFrame();
            MethodBase methodBase = stackFrame.GetMethod();

            var strErrorMessage = string.Empty;
            //  ObjWorkFlow_HdrDL.InsUser = "******";

            // ObjCommTransHeaderDL.InsDate = DateTime.Now.ToString("dd/MM/yyyy");
            bool result = true;

            //using (System.Data.Entity.DbContextTransaction dbTran = objPharmaEntities.Database.BeginTransaction())
            //{
            try
            {
                //string strBranch_Id = Obj_Dtls.Branch_Id.ToString();
                //string strCompany_Id = Obj_Dtls.Company_Id.ToString();
                //Guid? strEmpHdrId = Obj_Dtls.EmpHdrId;
                //decimal strEmpSerial_No = Obj_Dtls.Emp_Serial_No;

                //if (!String.IsNullOrEmpty(strBranch_Id) && !String.IsNullOrEmpty(strCompany_Id) && strEmpHdrId != null && strEmpSerial_No != null)
                //{
                //    result = DeleteEmpVactionTicket(strBranch_Id, strCompany_Id, strEmpHdrId, strEmpSerial_No, varContext);
                //}



                if (objUpdate != null)
                {
                    Hr_EmpDuesVactionTicket ObjForUpdate = (from objLinq in varContext.Hr_EmpDuesVactionTicket
                                                            where objLinq.Emp_Serial_No == objUpdate.Emp_Serial_No && objLinq.Company_Id == objUpdate.Company_Id && objLinq.Branch_Id == objUpdate.Branch_Id && objLinq.EmpHdrId == objUpdate.EmpHdrId
                                                            select objLinq).FirstOrDefault();


                    if (ObjForUpdate != null)
                    {
                        ObjForUpdate.EmpHdrId = objUpdate.EmpHdrId;

                        ObjForUpdate.Branch_Id                   = objUpdate.Branch_Id;
                        ObjForUpdate.Company_Id                  = objUpdate.Company_Id;
                        ObjForUpdate.GradeJob_Id                 = objUpdate.GradeJob_Id;
                        ObjForUpdate.Emp_Serial_No               = objUpdate.Emp_Serial_No;
                        ObjForUpdate.VactionPeriod               = objUpdate.VactionPeriod;
                        ObjForUpdate.VactionTicketType           = objUpdate.VactionTicketType;
                        ObjForUpdate.InternationalWorkTicketType = objUpdate.InternationalWorkTicketType;
                        ObjForUpdate.LocalWorkTicketType         = objUpdate.LocalWorkTicketType;
                        ObjForUpdate.WorkingMonthNo              = objUpdate.WorkingMonthNo;
                        ObjForUpdate.WorkingPeriodType           = objUpdate.WorkingPeriodType;
                        ObjForUpdate.CountTicket                 = objUpdate.CountTicket;

                        ObjForUpdate.UpdateDate = DateTime.Now;
                        ObjForUpdate.UpdateUser = objUpdate.UpdateUser;
                        result = varContext.SaveChanges() > 0;
                    }
                    else
                    {
                        Hr_EmpDuesVactionTicket loclDtls = new Hr_EmpDuesVactionTicket
                        {
                            EmpHdrId                    = objUpdate.EmpHdrId,
                            Branch_Id                   = objUpdate.Branch_Id,
                            Company_Id                  = objUpdate.Company_Id,
                            GradeJob_Id                 = objUpdate.GradeJob_Id,
                            Emp_Serial_No               = objUpdate.Emp_Serial_No,
                            VactionPeriod               = objUpdate.VactionPeriod,
                            VactionTicketType           = objUpdate.VactionTicketType,
                            InternationalWorkTicketType = objUpdate.InternationalWorkTicketType,
                            LocalWorkTicketType         = objUpdate.LocalWorkTicketType,
                            WorkingMonthNo              = objUpdate.WorkingMonthNo,
                            WorkingPeriodType           = objUpdate.WorkingPeriodType,
                            CountTicket                 = objUpdate.CountTicket,
                            InsDate = DateTime.Now,
                            InsUser = objUpdate.UpdateUser,
                        };

                        varContext.Hr_EmpDuesVactionTicket.Add(loclDtls);
                        result = varContext.SaveChanges() > 0;
                    }
                    //saves all above operations within one transaction
                    // objPharmaEntities.SaveChanges();

                    // dbTran.Commit();
                    // }
                }
            }
            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
            {
                // varContext.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);

            //  }
        }
Пример #4
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);
        }