コード例 #1
0
ファイル: CtrApplications.cs プロジェクト: MiroPakanec/EFlats
        public DataSet UpdateDataSet(DataSet ds, MdlApplication mdlApplicationObj)
        {
            mdlApplicationObj = InitializeScoreQueue(mdlApplicationObj);
            ds.Tables[0].TableName = "Applications";

            //add new application (row) to the dataset
            ds.Tables[0].Rows.Add(CreateNewDataRow(ds, mdlApplicationObj));
            DataTable dt = ds.Tables[0];

            //udate dataset            //sort from highest score
            dt.DefaultView.Sort = "Score desc";
            dt = dt.DefaultView.ToTable();

            //update queue in all rows
            int queue = 1;
            foreach (DataRow row in dt.Rows)
            {
                row["QueueNumber"] = queue;
                queue++;
            }
            if (ds.Tables.Count > 0)
                ds.Tables.Remove("Applications");

            ds.Tables.Add(dt);
            return ds;
        }
コード例 #2
0
ファイル: CtrApplications.cs プロジェクト: MiroPakanec/EFlats
        public DataSet UpdateDataSetToRemove(DataSet ds, MdlApplication mdlApplicationObj)
        {
            DataTable dt = ds.Tables[0];

            foreach (DataRow row in dt.Rows)
            {
                string columnValue = row["StudentEmail"].ToString().Trim();
                if (columnValue.Equals(mdlApplicationObj.StudentEmail))
                {
                    row.Delete();
                }
            }

            //sort from highest score
            dt.DefaultView.Sort = "Score desc";
            dt = dt.DefaultView.ToTable();

            //update queue in all rows
            int queue = 1;
            foreach (DataRow row in dt.Rows)
            {
                row["QueueNumber"] = queue;
                queue++;
            }

            if (ds.Tables.Count > 0)
                ds.Tables.Remove("Applications");

            ds.Tables.Add(dt);
            return ds;
        }
コード例 #3
0
        public DataSet UpdateDataSetToRemove(DataSet ds, MdlApplication mdlApplicationObj)
        {
            DataTable dt = ds.Tables[0];

            foreach (DataRow row in dt.Rows)
            {
                string columnValue = row["StudentEmail"].ToString().Trim();
                if (columnValue.Equals(mdlApplicationObj.StudentEmail))
                {
                    row.Delete();
                }
            }

            //sort from highest score
            dt.DefaultView.Sort = "Score desc";
            dt = dt.DefaultView.ToTable();

            //update queue in all rows
            int queue = 1;

            foreach (DataRow row in dt.Rows)
            {
                row["QueueNumber"] = queue;
                queue++;
            }

            if (ds.Tables.Count > 0)
            {
                ds.Tables.Remove("Applications");
            }

            ds.Tables.Add(dt);
            return(ds);
        }
コード例 #4
0
        public DataSet UpdateDataSet(DataSet ds, MdlApplication mdlApplicationObj)
        {
            mdlApplicationObj      = InitializeScoreQueue(mdlApplicationObj);
            ds.Tables[0].TableName = "Applications";

            //add new application (row) to the dataset
            ds.Tables[0].Rows.Add(CreateNewDataRow(ds, mdlApplicationObj));
            DataTable dt = ds.Tables[0];


            //udate dataset            //sort from highest score
            dt.DefaultView.Sort = "Score desc";
            dt = dt.DefaultView.ToTable();

            //update queue in all rows
            int queue = 1;

            foreach (DataRow row in dt.Rows)
            {
                row["QueueNumber"] = queue;
                queue++;
            }
            if (ds.Tables.Count > 0)
            {
                ds.Tables.Remove("Applications");
            }

            ds.Tables.Add(dt);
            return(ds);
        }
コード例 #5
0
 private MdlApplication InitializeScoreQueue(MdlApplication mdlApplicationObj)
 {
     //update score score = profileScore + dateScpre (appObj.score holds profile score at this point)
     mdlApplicationObj.DateOfCreation = DateTime.Now;
     mdlApplicationObj.Score          = SumScores(CalculateScoreDate(mdlApplicationObj.DateOfCreation), mdlApplicationObj.Score);
     return(mdlApplicationObj);
 }
コード例 #6
0
ファイル: CtrStudent.cs プロジェクト: Teo27/Eflats
        private MdlApplication GetApplicationObj(string studentEmail, int flatId, int score)
        {
            MdlApplication mdlApplicationObj = new MdlApplication();

            mdlApplicationObj.StudentEmail = studentEmail;
            mdlApplicationObj.FlatId       = flatId;
            mdlApplicationObj.Score        = score;
            return(mdlApplicationObj);
        }
コード例 #7
0
        private DataRow CreateNewDataRow(DataSet ds, MdlApplication mdlApplicationObj)
        {
            DataRow currentApplication = ds.Tables[0].NewRow();

            currentApplication["StudentEmail"]   = mdlApplicationObj.StudentEmail;
            currentApplication["FlatId"]         = mdlApplicationObj.FlatId;
            currentApplication["DateOfCreation"] = mdlApplicationObj.DateOfCreation;
            currentApplication["Score"]          = mdlApplicationObj.Score;
            currentApplication["QueueNumber"]    = -1;
            return(currentApplication);
        }
コード例 #8
0
ファイル: DbApplications.cs プロジェクト: Teo27/Eflats
 private MdlApplication UpdateModelObj(DataSet ds, MdlApplication mdlApplicationObj)
 {
     foreach (DataRow row in ds.Tables[0].Rows)
     {
         if (row["StudentEmail"].Equals(mdlApplicationObj.StudentEmail))
         {
             mdlApplicationObj.Score       = (int)row["Score"];
             mdlApplicationObj.QueueNumber = (int)row["QueueNumber"];
         }
     }
     return(mdlApplicationObj);
 }
コード例 #9
0
ファイル: CtrUpdate.cs プロジェクト: HappyBox/EFlats
        private static MdlApplication CalculateInsertScore(MdlApplication element)
        {
            ServerDatabase.DbUpdate dbUpdateObject = new ServerDatabase.DbUpdate();
            //return bool, pass calculated score and ID
            int dateScore = CtrApplications.CalculateScoreDate(Convert.ToDateTime(element.DateOfCreation));
            int profileScore = CtrStudent.GetScore(element.StudentId);
            element.Score = CtrApplications.SumScores(dateScore, profileScore);

            if (!dbUpdateObject.UpdateApplicationScore(element.Id, element.Score))
                Console.WriteLine("Error while updating Application score. ID: " + element.Id + " Thread: " + Thread.CurrentThread.ManagedThreadId.ToString() + "\n Time: " + DateTime.Now);

            return element;
        }
コード例 #10
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();
                    }
                }
            }
        }
コード例 #11
0
        public void AddToWishListExistingApplicaation()
        {
            CtrStudent ctrStudentObj = new CtrStudent();
            MdlStudent mdlStudentObj = StudentTests.GenerateStudentObj();

            CtrGetData ctrGetDataObj = new CtrGetData();
            DataSet    ds            = ctrGetDataObj.GetAllFlats();

            MdlApplication mdlApplicationObj = new MdlApplication();
            string         studentEmail      = "*****@*****.**";
            int            flatId            = (int)ds.Tables[0].Rows[0]["Id"];
            int            score             = 100;

            bool actual   = ctrStudentObj.AddToWishlist(studentEmail, flatId, score);
            bool expected = false;

            Assert.AreEqual(expected, actual);
        }
コード例 #12
0
ファイル: WishListTests.cs プロジェクト: MiroPakanec/EFlats
        public void AddToWishListExistingApplicaation()
        {
            CtrStudent ctrStudentObj = new CtrStudent();
            MdlStudent mdlStudentObj = StudentTests.GenerateStudentObj();

            CtrGetData ctrGetDataObj = new CtrGetData();
            DataSet ds = ctrGetDataObj.GetAllFlats();

            MdlApplication mdlApplicationObj = new MdlApplication();
            string studentEmail = "*****@*****.**";
            int flatId = (int)ds.Tables[0].Rows[0]["Id"];
            int score = 100;

            bool actual = ctrStudentObj.AddToWishlist(studentEmail, flatId, score);
            bool expected = false;

            Assert.AreEqual(expected, actual);
        }
コード例 #13
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;
        }
コード例 #14
0
ファイル: DbApplications.cs プロジェクト: Teo27/Eflats
        public bool UpdateApplications(DataSet ds, MdlApplication mdlApplicationObj)
        {
            var option = new TransactionOptions();

            option.IsolationLevel = System.Transactions.IsolationLevel.Serializable;
            option.Timeout        = TimeSpan.FromSeconds(30);
            using (var scope = new TransactionScope(TransactionScopeOption.Required, option))
            {
                try
                {
                    if (!RemoveApplications(mdlApplicationObj))
                    {
                        return(false);
                    }

                    using (SqlConnection conn = new SqlConnection(DbConnection.connectionString))
                    {
                        ds.Tables[0].TableName = "Applications";
                        SqlDataAdapter da = new SqlDataAdapter("spGetApplications", conn);
                        da.SelectCommand.CommandType = CommandType.StoredProcedure;
                        da.SelectCommand.Parameters.AddWithValue("@StudentEmail", mdlApplicationObj.StudentEmail);
                        da.SelectCommand.Parameters.AddWithValue("@FlatId", mdlApplicationObj.FlatId);

                        SqlCommandBuilder builder = new SqlCommandBuilder(da);
                        int updates = da.Update(ds, "Applications");

                        scope.Complete();
                        return(true);
                    }
                }
                catch (Exception e)
                {
                    Transaction.Current.Rollback();
                    return(false);
                }
                finally
                {
                    if (scope != null)
                    {
                        ((IDisposable)scope).Dispose();
                    }
                }
            }
        }
コード例 #15
0
ファイル: DbApplications.cs プロジェクト: Teo27/Eflats
 private bool RemoveApplications(MdlApplication mdlApplicationObj)
 {
     try
     {
         using (SqlConnection conn = new SqlConnection(DbConnection.connectionString))
         {
             SqlCommand cmd = new SqlCommand("spRemoveBufferedApplications", conn);
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.AddWithValue("@FlatId", mdlApplicationObj.FlatId);
             conn.Open();
             cmd.ExecuteNonQuery();
             return(true);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("An Error has accured. remove from Wishlist Terminated. Err:" + e);
         return(false);
     }
 }
コード例 #16
0
ファイル: DbApplications.cs プロジェクト: MiroPakanec/EFlats
 private MdlApplication UpdateModelObj(DataSet ds, MdlApplication mdlApplicationObj)
 {
     foreach (DataRow row in ds.Tables[0].Rows)
     {
         if (row["StudentEmail"].Equals(mdlApplicationObj.StudentEmail))
         {
             mdlApplicationObj.Score = (int)row["Score"];
             mdlApplicationObj.QueueNumber = (int)row["QueueNumber"];
         }
     }
     return mdlApplicationObj;
 }
コード例 #17
0
ファイル: DbApplications.cs プロジェクト: MiroPakanec/EFlats
 private bool RemoveApplications(MdlApplication mdlApplicationObj)
 {
     try
     {
         using (SqlConnection conn = new SqlConnection(DbConnection.connectionString))
         {
             SqlCommand cmd = new SqlCommand("spRemoveBufferedApplications", conn);
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.AddWithValue("@FlatId", mdlApplicationObj.FlatId);
             conn.Open();
             cmd.ExecuteNonQuery();
             return true;
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("An Error has accured. remove from Wishlist Terminated. Err:" + e);
         return false;
     }
 }
コード例 #18
0
ファイル: DbApplications.cs プロジェクト: MiroPakanec/EFlats
        public bool UpdateApplications(DataSet ds, MdlApplication mdlApplicationObj)
        {
            var option = new TransactionOptions();
            option.IsolationLevel = System.Transactions.IsolationLevel.Serializable;
            option.Timeout = TimeSpan.FromSeconds(30);
            using (var scope = new TransactionScope(TransactionScopeOption.Required, option))
            {
                try
                {
                    if (!RemoveApplications(mdlApplicationObj))
                        return false;

                    using (SqlConnection conn = new SqlConnection(DbConnection.connectionString))
                    {
                        ds.Tables[0].TableName = "Applications";
                        SqlDataAdapter da = new SqlDataAdapter("spGetApplications", conn);
                        da.SelectCommand.CommandType = CommandType.StoredProcedure;
                        da.SelectCommand.Parameters.AddWithValue("@StudentEmail", mdlApplicationObj.StudentEmail);
                        da.SelectCommand.Parameters.AddWithValue("@FlatId", mdlApplicationObj.FlatId);

                        SqlCommandBuilder builder = new SqlCommandBuilder(da);
                        int updates = da.Update(ds, "Applications");

                        scope.Complete();
                        return true;
                    }
                }
                catch (Exception e)
                {
                    Transaction.Current.Rollback();
                    return false;
                }
                finally
                {
                    if (scope != null)
                        ((IDisposable)scope).Dispose();
                }
            }
        }
コード例 #19
0
ファイル: CtrStudent.cs プロジェクト: MiroPakanec/EFlats
 private MdlApplication GetApplicationObj(string studentEmail, int flatId, int score)
 {
     MdlApplication mdlApplicationObj = new MdlApplication();
     mdlApplicationObj.StudentEmail = studentEmail;
     mdlApplicationObj.FlatId = flatId;
     mdlApplicationObj.Score = score;
     return mdlApplicationObj;
 }
コード例 #20
0
ファイル: CtrUpdate.cs プロジェクト: HappyBox/EFlats
 private static bool FlatIdPredicate(MdlApplication element)
 {
     return true;
 }
コード例 #21
0
ファイル: DbUpdate.cs プロジェクト: HappyBox/EFlats
        public List<MdlApplication> UpdateScore()
        {
            try
            {

                MdlApplication mdlApplicationObj;

                //create appropriate array
                List<MdlApplication> applicationList = new List<MdlApplication>();
                string query = "select * from Applications";
                Console.WriteLine("Thread " + Thread.CurrentThread.ManagedThreadId.ToString() + " Executed query: \n     " + query);

                using (var connection = new SqlConnection(DbConnection.connectionString))
                using (var command = new SqlCommand(query, connection))
                {
                    connection.Open();
                    using (var sqlReader = command.ExecuteReader())
                    {
                        while (sqlReader.Read())
                        {
                            mdlApplicationObj = new MdlApplication();
                            //while reads initialize and populate list
                            mdlApplicationObj.Id = Convert.ToInt32(sqlReader.GetValue(0));
                            mdlApplicationObj.StudentId = Convert.ToInt32(sqlReader.GetValue(1));
                            mdlApplicationObj.FlatId = Convert.ToInt32(sqlReader.GetValue(2));
                            mdlApplicationObj.DateOfCreation = Convert.ToDateTime(sqlReader.GetValue(3));
                            mdlApplicationObj.Score = Convert.ToInt32(sqlReader.GetValue(4));
                            mdlApplicationObj.QueueNumber = Convert.ToInt32(sqlReader.GetValue(5));

                            Console.WriteLine("Adding to row list... ");
                            applicationList.Add(mdlApplicationObj);

                        }
                    }
                }
                return applicationList;
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception catched: " + e + " Thread: " + Thread.CurrentThread.ManagedThreadId.ToString() + " Time: " + DateTime.Now);
                return null;
            }
        }
コード例 #22
0
ファイル: CtrApplications.cs プロジェクト: MiroPakanec/EFlats
 private DataRow CreateNewDataRow(DataSet ds, MdlApplication mdlApplicationObj)
 {
     DataRow currentApplication = ds.Tables[0].NewRow();
     currentApplication["StudentEmail"] = mdlApplicationObj.StudentEmail;
     currentApplication["FlatId"] = mdlApplicationObj.FlatId;
     currentApplication["DateOfCreation"] = mdlApplicationObj.DateOfCreation;
     currentApplication["Score"] = mdlApplicationObj.Score;
     currentApplication["QueueNumber"] = -1;
     return currentApplication;
 }
コード例 #23
0
ファイル: CtrApplications.cs プロジェクト: MiroPakanec/EFlats
 private MdlApplication InitializeScoreQueue(MdlApplication mdlApplicationObj)
 {
     //update score score = profileScore + dateScpre (appObj.score holds profile score at this point)
     mdlApplicationObj.DateOfCreation = DateTime.Now;
     mdlApplicationObj.Score = SumScores(CalculateScoreDate(mdlApplicationObj.DateOfCreation), mdlApplicationObj.Score);
     return mdlApplicationObj;
 }