Ejemplo n.º 1
0
        public List <HYLAN_TASKDC> Insert(List <HYLAN_TASKDC> hylanTaskDCList)
        {
            int          insertedCount = 0;
            DBConnection objConnection = new DBConnection();
            HYLAN_TASKDA HYLAN_TASKDA  = null;

            try
            {
                objConnection.Open(true);
                foreach (HYLAN_TASKDC hylanTaskDC in hylanTaskDCList)
                {
                    HYLAN_TASKDA = HylanTaskDAFactory.Create(hylanTaskDC.TASK_TITLE_ID);
                    if (String.IsNullOrEmpty(hylanTaskDC.REQUIRED))
                    {
                        hylanTaskDC.REQUIRED = "N";
                    }
                    List <HYLAN_TASKDC> tempList = new List <HYLAN_TASKDC>();
                    tempList.Add(hylanTaskDC);
                    try
                    {
                        if (HYLAN_TASKDA.Insert(objConnection, tempList) > 0)
                        {
                            insertedCount++;
                        }
                        else
                        {
                            hylanTaskDC.POST_MESSAGEDC.Type    = "ERROR";
                            hylanTaskDC.POST_MESSAGEDC.Message = "NOT_ADDED";
                        }
                    }
                    catch (Exception exception)
                    {
                        hylanTaskDC.POST_MESSAGEDC.Type       = "EXCEPTION";
                        hylanTaskDC.POST_MESSAGEDC.Message    = exception.Message;
                        hylanTaskDC.POST_MESSAGEDC.StackTrace = exception.StackTrace;
                    }
                }
                if (insertedCount == hylanTaskDCList.Count)
                {
                    objConnection.Commit();
                }
                else
                {
                    objConnection.Rollback();
                }
            }
            catch (Exception ex)
            {
                objConnection.Rollback();
                throw ex;
            }
            finally
            {
                objConnection.Close();
            }
            return(hylanTaskDCList);
        }
Ejemplo n.º 2
0
        public List <List <HYLAN_TASKDC> > InsertUpdateTasks(List <List <HYLAN_TASKDC> > postData)
        {
            int insertedCount = 0;
            int updatedCount  = 0;
            List <HYLAN_TASKDC> insertList = new List <HYLAN_TASKDC>();
            List <HYLAN_TASKDC> updateList = new List <HYLAN_TASKDC>();

            if (postData != null && postData.Count == 2)
            {
                insertList = postData[0];
                updateList = postData[1];
            }
            DBConnection objConnection = new DBConnection();
            HYLAN_TASKDA HYLAN_TASKDA  = null;

            try
            {
                objConnection.Open(true);

                #region Insert
                foreach (HYLAN_TASKDC hylanTaskDC in insertList)
                {
                    HYLAN_TASKDA = HylanTaskDAFactory.Create(hylanTaskDC.TASK_TITLE_ID);
                    if (String.IsNullOrEmpty(hylanTaskDC.REQUIRED))
                    {
                        hylanTaskDC.REQUIRED = "N";
                    }
                    List <HYLAN_TASKDC> tempList = new List <HYLAN_TASKDC>();
                    tempList.Add(hylanTaskDC);
                    try
                    {
                        if (HYLAN_TASKDA.Insert(objConnection, tempList) > 0)
                        {
                            insertedCount++;
                        }
                        else
                        {
                            hylanTaskDC.POST_MESSAGEDC.Type    = "ERROR";
                            hylanTaskDC.POST_MESSAGEDC.Message = "NOT_ADDED";
                        }
                    }
                    catch (Exception exception)
                    {
                        if (exception.Message.Contains("UNIQUE KEY"))
                        {
                            hylanTaskDC.POST_MESSAGEDC.Type    = "CONCURRENCY_ERROR";
                            hylanTaskDC.POST_MESSAGEDC.Message = "CONCURRENCY_ERROR";
                        }
                        else
                        {
                            hylanTaskDC.POST_MESSAGEDC.Type       = "EXCEPTION";
                            hylanTaskDC.POST_MESSAGEDC.Message    = exception.Message;
                            hylanTaskDC.POST_MESSAGEDC.StackTrace = exception.StackTrace;
                        }
                    }
                }
                #endregion

                #region Update
                foreach (HYLAN_TASKDC hylanTaskDC in updateList)
                {
                    HYLAN_TASKDA = HylanTaskDAFactory.Create(hylanTaskDC.TASK_TITLE_ID);
                    if (String.IsNullOrEmpty(hylanTaskDC.REQUIRED))
                    {
                        hylanTaskDC.REQUIRED = "N";
                    }
                    List <HYLAN_TASKDC> tempList = new List <HYLAN_TASKDC>();
                    tempList.Add(hylanTaskDC);
                    try
                    {
                        if (HYLAN_TASKDA.Update(objConnection, tempList) > 0)
                        {
                            updatedCount++;
                        }
                        else
                        {
                            hylanTaskDC.POST_MESSAGEDC.Type    = "ERROR";
                            hylanTaskDC.POST_MESSAGEDC.Message = "NOT_UPDATED";
                        }
                    }
                    catch (Exception exception)
                    {
                        hylanTaskDC.POST_MESSAGEDC.Type = "CONCURRENCY_ERROR";
                        if (exception.Message.Contains("CONCURRENCY_ERROR"))
                        {
                            hylanTaskDC.POST_MESSAGEDC.Message = "CONCURRENCY_ERROR";
                        }
                        else
                        {
                            hylanTaskDC.POST_MESSAGEDC.Type       = "EXCEPTION";
                            hylanTaskDC.POST_MESSAGEDC.Message    = exception.Message;
                            hylanTaskDC.POST_MESSAGEDC.StackTrace = exception.StackTrace;
                        }
                    }
                }
                #endregion

                if (insertedCount == insertList.Count && updatedCount == updateList.Count)
                {
                    objConnection.Commit();
                }
                else
                {
                    objConnection.Rollback();
                }
            }
            catch (Exception ex)
            {
                objConnection.Rollback();
                throw ex;
            }
            finally
            {
                objConnection.Close();
            }
            return(postData);
        }