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(); } } } }
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(); } } }
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; }
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; }
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(); } } }