コード例 #1
0
ファイル: CtrStudent.cs プロジェクト: Teo27/Eflats
        public bool RemoveFromWishlist(string studentEmail, int flatId)
        {
            MdlApplication  mdlApplicationObj = GetApplicationObj(studentEmail, flatId, 0);
            DbApplications  dbApplicationsObj = new DbApplications();
            CtrApplications ctrApplicationObj = new CtrApplications();

            var option = new TransactionOptions();

            option.IsolationLevel = System.Transactions.IsolationLevel.Serializable;
            option.Timeout        = TimeSpan.FromSeconds(30);
            using (var scope = new TransactionScope(TransactionScopeOption.Required, option))
            {
                try
                {
                    //Get current Application table for specific flat
                    DataSet ds = dbApplicationsObj.GetApplicationsDataSetRomove(mdlApplicationObj.StudentEmail, mdlApplicationObj.FlatId);
                    if (ds.Tables.Count == 0)
                    {
                        return(false);
                    }
                    //Update dataset - add current application and order queue
                    ds = ctrApplicationObj.UpdateDataSetToRemove(ds, mdlApplicationObj);
                    //update dataset
                    bool result = dbApplicationsObj.UpdateApplications(ds, mdlApplicationObj);
                    if (result)
                    {
                        scope.Complete();
                    }
                    else
                    {
                        scope.Dispose();
                    }

                    return(result);
                }
                catch
                {
                    Transaction.Current.Rollback();
                    return(false);
                }
                finally
                {
                    if (scope != null)
                    {
                        ((IDisposable)scope).Dispose();
                    }
                }
            }
        }
コード例 #2
0
ファイル: CtrUpdate.cs プロジェクト: Teo27/Eflats
        private static void UpdateScores(DataSet ds)
        {
            var option = new TransactionOptions();

            option.IsolationLevel = System.Transactions.IsolationLevel.Serializable;
            option.Timeout        = TimeSpan.FromSeconds(30);
            using (var scope = new TransactionScope(TransactionScopeOption.Required, option))
            {
                try
                {
                    Parallel.ForEach(ds.Tables[0].AsEnumerable(), drow =>
                    {
                        CtrStudent ctrStudentObj = new CtrStudent();
                        string studentEmail      = drow["StudentEmail"].ToString().Trim();
                        int profileScore         = ctrStudentObj.GetStudentData(studentEmail).Score;
                        int dateScore            = CtrApplications.CalculateScoreDate(Convert.ToDateTime(drow["DateOfCreation"]));

                        drow["Score"] = CtrApplications.SumScores(profileScore, dateScore);
                    });

                    //update table
                    if (DbApplications.UpdateAllApplicationScores(ds))
                    {
                        Console.WriteLine("Update Successful");
                    }
                    else
                    {
                        Console.WriteLine("Update Failed");
                        Transaction.Current.Rollback();
                    }
                    Console.WriteLine("Update score transactions complete.");
                    scope.Complete();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Update score transactions rolled back.");
                    Console.WriteLine("Error: " + e);
                    Transaction.Current.Rollback();
                }
                finally
                {
                    if (scope != null)
                    {
                        ((IDisposable)scope).Dispose();
                    }
                    Thread.CurrentThread.Abort();
                }
            }
        }
コード例 #3
0
ファイル: CtrStudent.cs プロジェクト: MiroPakanec/EFlats
 public bool AddToWishlist(string studentEmail, int flatId, int score)
 {
     MdlApplication mdlApplicationObj = GetApplicationObj(studentEmail, flatId, score);
     DbApplications dbApplicationsObj = new DbApplications();
     CtrApplications ctrApplicationObj = new CtrApplications();
     //Get current Application table for specific flat
     DataSet ds = dbApplicationsObj.GetApplicationsDataSet(mdlApplicationObj.StudentEmail, mdlApplicationObj.FlatId);
     if (ds.Tables.Count == 0)
         return false;
     //Update dataset - add current application and order queue
     ds = ctrApplicationObj.UpdateDataSet(ds, mdlApplicationObj);
     //update dataset
     return dbApplicationsObj.UpdateApplications(ds, mdlApplicationObj);
     //return false;
 }
コード例 #4
0
ファイル: CtrStudent.cs プロジェクト: Teo27/Eflats
        public bool AddToWishlist(string studentEmail, int flatId, int score)
        {
            MdlApplication  mdlApplicationObj = GetApplicationObj(studentEmail, flatId, score);
            DbApplications  dbApplicationsObj = new DbApplications();
            CtrApplications ctrApplicationObj = new CtrApplications();
            //Get current Application table for specific flat
            DataSet ds = dbApplicationsObj.GetApplicationsDataSet(mdlApplicationObj.StudentEmail, mdlApplicationObj.FlatId);

            if (ds.Tables.Count == 0)
            {
                return(false);
            }
            //Update dataset - add current application and order queue
            ds = ctrApplicationObj.UpdateDataSet(ds, mdlApplicationObj);
            //update dataset
            return(dbApplicationsObj.UpdateApplications(ds, mdlApplicationObj));
            //return false;
        }
コード例 #5
0
ファイル: CtrStudent.cs プロジェクト: MiroPakanec/EFlats
        public bool RemoveFromWishlist(string studentEmail, int flatId)
        {
            MdlApplication mdlApplicationObj = GetApplicationObj(studentEmail, flatId, 0);
            DbApplications dbApplicationsObj = new DbApplications();
            CtrApplications ctrApplicationObj = new CtrApplications();

            var option = new TransactionOptions();
            option.IsolationLevel = System.Transactions.IsolationLevel.Serializable;
            option.Timeout = TimeSpan.FromSeconds(30);
            using (var scope = new TransactionScope(TransactionScopeOption.Required, option))
            {
                try
                {
                    //Get current Application table for specific flat
                    DataSet ds = dbApplicationsObj.GetApplicationsDataSetRomove(mdlApplicationObj.StudentEmail, mdlApplicationObj.FlatId);
                    if (ds.Tables.Count == 0)
                        return false;
                    //Update dataset - add current application and order queue
                    ds = ctrApplicationObj.UpdateDataSetToRemove(ds, mdlApplicationObj);
                    //update dataset
                    bool result = dbApplicationsObj.UpdateApplications(ds, mdlApplicationObj);
                    if (result)
                        scope.Complete();
                    else
                        scope.Dispose();

                    return result;

                }
                catch
                {
                    Transaction.Current.Rollback();
                    return false;
                }
                finally
                {
                    if (scope != null)
                        ((IDisposable)scope).Dispose();
                }
            }
        }