Exemple #1
0
        private List <WorkField> fillWorkFieldList()
        {
            WorkFieldBusiness _WorkFieldBusiness = new WorkFieldBusiness();
            WorkFieldList     _WorkFieldList     = _WorkFieldBusiness.SelectRows(null, null, null);

            return(_WorkFieldList);
        }
Exemple #2
0
        public WorkFieldDTO GetWorkFieldFromDB(int id)
        {
            {
                ICollection <WorkFieldDTO> outputList = default(ICollection <WorkFieldDTO>);
                WorkFieldDTO output = new WorkFieldDTO();

                try
                {
                    WorkFieldBusiness _WorkFieldBusiness = new WorkFieldBusiness();
                    WorkFieldList     _WorkFieldList     = _WorkFieldBusiness.SelectRows(id, null, null);

                    if (_WorkFieldList != null && _WorkFieldList.Count > 0)
                    //outputList = Mapper.MapUserAsOutput();
                    {
                        // 2- Prepare Mapping Objects (Fill Values from DB)
                        Mapper._WorkFieldList = _WorkFieldList;

                        // 3- Perform Mapping to Output
                        outputList = Mapper.MapWorkFieldAsOutput();

                        if (outputList != null && outputList.Count > 0)
                        {
                            output = outputList.FirstOrDefault();
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Log Exception Here
                    throw; //new Exception(ex.Message);
                }

                return(output);
            }
        }
Exemple #3
0
        public ICollection <WorkFieldDTO> GetAllWorkFieldFromDB()
        {
            ICollection <WorkFieldDTO> outputList = default(ICollection <WorkFieldDTO>);

            try
            {
                // 1- Select All work fields From DB
                WorkFieldBusiness _WorkFieldBusiness = new WorkFieldBusiness();
                WorkFieldList     _WorkFieldList     = _WorkFieldBusiness.SelectRows(null, null, null);

                if (_WorkFieldList != null && _WorkFieldList.Count > 0)

                {
                    // 2- Prepare Mapping Objects (Fill Values from DB)
                    Mapper._WorkFieldList = fillWorkFieldList();


                    // 3- Perform Mapping to Output
                    outputList = Mapper.MapWorkFieldAsOutput();
                }
            }
            catch (Exception ex)
            {
                // Log Exception Here
                throw; //new Exception(ex.Message);
            }

            return(outputList);
        }
Exemple #4
0
        public int SaveRows(DbTransaction pTran, WorkFieldList WorkFieldList, bool CreateTransaction)
        {
            int           intRows   = 0;
            DbTransaction objTran   = pTran;
            Exception     exception = null;

            try
            {
                if (pTran == null && CreateTransaction == true)
                {
                    objTran = WorkFieldData.CreateTransaction();
                }
                intRows = WorkFieldData.SaveRows(objTran, WorkFieldList);
                if (pTran == null && objTran != null && CreateTransaction == true)
                {
                    WorkFieldData.CommitTransaction(objTran, true);
                    objTran = null;
                }
            }
            catch (Exception EX)
            {
                exception = EX;
                if (pTran == null && objTran != null && CreateTransaction == true)
                {
                    WorkFieldData.RollbackTransaction(objTran, true);
                    objTran = null;
                }
            }
            finally
            {
            }
            return(intRows);
        }
Exemple #5
0
        public WorkFieldDTO UpdateWorkFieldInDB(WorkFieldDTO workFieldDTO)
        {
            BaseDataAccess _db = new BaseDataAccess();

            using (DbTransaction dbTransaction = _db.CreateTransaction())
            {
                try

                {
                    // 1- Perform Mapping to  Input (for Saving in DB)
                    if (Mapper.MapWorkFieldAsInput(workFieldDTO))
                    {
                        // 2- Select WorkField to be updated
                        WorkFieldBusiness workFieldBusiness = new WorkFieldBusiness();
                        WorkFieldList     workFieldList     = workFieldBusiness.SelectRows(Mapper._WorkField.Id, null, null);

                        if (workFieldList != null && workFieldList.Count > 0)
                        {
                            workFieldList[0].Id     = Mapper._WorkField.Id;
                            workFieldList[0].name   = Mapper._WorkField.name;
                            workFieldList[0].nameAr = Mapper._WorkField.nameAr;


                            // 3- Update WorkField Data by Input Values
                            workFieldBusiness = new WorkFieldBusiness();
                            if (workFieldBusiness.UpdateRow(dbTransaction, workFieldList[0]) > 0)
                            {
                                dbTransaction.Commit();
                            }

                            else
                            {
                                dbTransaction.Rollback();
                                throw new Exception("DataBase Operation Failure");
                            }
                        }
                        else
                        {
                            dbTransaction.Rollback();
                            throw new Exception("WorkField Id Not Found in DB");
                        }
                    }
                    else
                    {
                        throw new ArgumentNullException("workFieldDTO");
                    }
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    throw;
                }
            }

            return(workFieldDTO);
        }
Exemple #6
0
        public WorkFieldList SelectRows(DbTransaction pTran, System.Int32?Id, System.String name, System.String nameAr)
        {
            WorkFieldList WorkFieldList = new WorkFieldList();
            Exception     exception     = null;

            DbParameter[] Parameters = new DbParameter[3];
            Parameters[0] = _getIdParameter(Id, ParameterDirection.Input);
            Parameters[1] = _getnameParameter(name, ParameterDirection.Input);
            Parameters[2] = _getnameArParameter(nameAr, ParameterDirection.Input);

            DbDataReader Dr = ExecuteReader(pTran, "[Lookups].[SelectWorkField]", Parameters);

            try
            {
                if (Dr != null)
                {
                    while (Dr.Read())
                    {
                        WorkField WorkField = new WorkField();
                        if (Dr["Id"] != DBNull.Value)
                        {
                            WorkField.Id = (System.Int32)Dr["Id"];
                        }
                        if (Dr["name"] != DBNull.Value)
                        {
                            WorkField.name = (System.String)Dr["name"];
                        }
                        if (Dr["nameAr"] != DBNull.Value)
                        {
                            WorkField.nameAr = (System.String)Dr["nameAr"];
                        }
                        WorkFieldList.FillRow(WorkField);
                        WorkField = null;
                    }
                }
            }
            catch (Exception Ex)
            {
                exception = Ex;
            }
            finally
            {
                if (Dr != null)
                {
                    if (Dr.IsClosed == false)
                    {
                        Dr.Close();
                    }
                    Dr = null;
                }
            }
            return(WorkFieldList);
        }
Exemple #7
0
        public bool DeleteWorkFieldFromDB(int id)
        {
            bool result = default(bool);

            BaseDataAccess _db = new BaseDataAccess();

            using (DbTransaction dbTransaction = _db.CreateTransaction())
            {
                try
                {
                    // 1- Select WorkField From DB by ID
                    WorkFieldBusiness workFieldBusiness = new WorkFieldBusiness();
                    WorkFieldList     workFieldList     = workFieldBusiness.SelectRows(id, null, null);

                    if (workFieldList != null && workFieldList.Count > 0)
                    {
                        foreach (WorkField workField in workFieldList)
                        {
                            workFieldBusiness = new WorkFieldBusiness();
                            workFieldBusiness.DeleteRow(dbTransaction, workField);
                        }

                        dbTransaction.Commit();
                        result = true;
                    }

                    else
                    {
                        dbTransaction.Rollback();
                        throw new Exception("WorkField Id Not Found in DB");
                    }
                }
                catch (Exception)
                {
                    dbTransaction.Rollback();
                    throw new Exception("DataBase Operation Failure");
                }
            }

            return(result);
        }
Exemple #8
0
        public int SaveRows(DbTransaction pTran, WorkFieldList WorkFieldList)
        {
            int intRows = 0;

            for (int i = 0; i < WorkFieldList.Count; i++)
            {
                switch (WorkFieldList[i].CommonState)
                {
                case CommonState.Added:
                    intRows += InsertRow(pTran, WorkFieldList[i]);
                    break;

                case CommonState.Modified:
                    intRows += UpdateRow(pTran, WorkFieldList[i]);
                    break;

                case CommonState.Deleted:
                    intRows += DeleteRow(pTran, WorkFieldList[i]);
                    break;
                }
            }

            return(intRows);
        }
Exemple #9
0
        public int SaveRows(WorkFieldList WorkFieldList)
        {
            DbTransaction Tran = null;

            return(SaveRows(Tran, WorkFieldList));
        }
Exemple #10
0
 public int SaveRows(DbTransaction pTran, WorkFieldList WorkFieldList)
 {
     return(SaveRows(pTran, WorkFieldList, true));
 }