Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
        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();
                }
            }
        }
Ejemplo n.º 3
0
        public static bool UpdateQueueSingleFlat(int flatId)
        {
            var option = new TransactionOptions();
            option.IsolationLevel = System.Transactions.IsolationLevel.Serializable;
            option.Timeout = TimeSpan.FromSeconds(30);
            using (var scope = new TransactionScope(TransactionScopeOption.Required, option))
            {
                try
                {
                    DbApplications dbApplicationsObj = new DbApplications();
                    DataSet ds = dbApplicationsObj.GetApplicationsByFlat(flatId);
                    if (ds.Tables[0].Rows.Count == 0)
                        return false;

                    DataTable dt = ds.Tables[0];
                    dt.DefaultView.Sort = "Score Desc";
                    dt = dt.DefaultView.ToTable();
                    int queue = 1;

                    foreach (DataRow dr in dt.Rows)
                    {
                        dr["QueueNumber"] = queue;
                        Console.WriteLine("FID: " + dr["FlatId"].ToString().Trim() + " Score: " + dr["Score"] + " QN: " + dr["QueueNumber"].ToString().Trim());
                        queue++;
                    }

                    ds.Tables.Remove("Applications");
                    ds.Tables.Add(dt);

                    foreach(DataRow row in ds.Tables[0].Rows)
                    {
                        Console.WriteLine("Iterating sorted DataSet...");
                        Console.WriteLine("Flat ID: " + Convert.ToInt32(row["FlatId"]));
                        Console.WriteLine("Score: " + Convert.ToInt32(row["Score"]));
                        Console.WriteLine("Queue: " + Convert.ToInt32(row["QueueNumber"]));

                        if (!dbApplicationsObj.UpdateApplicationsByFlat(row))
                        {
                            Console.WriteLine("ROLLBACK");
                            Transaction.Current.Rollback();
                        }
                    }

                    Console.WriteLine("Flat updated!");
                    scope.Complete();
                    return true;
                }
                catch (Exception e)
                {
                    Console.WriteLine("Unable to update flat - ERROR!");
                    Console.WriteLine(e);
                    Transaction.Current.Rollback();
                    return false;
                }
                finally
                {
                    if (scope != null)
                        ((IDisposable)scope).Dispose();
                }
            }
        }