public questStatus Delete(List <FilterLogId> filterLogIdList) { // Initialize questStatus status = null; DbMgrTransaction trans = null; Mgr mgr = new Mgr(this.UserSession); try { // BEGIN TRANSACTION status = mgr.BeginTransaction("Delete_FilterLogEntries_" + Guid.NewGuid().ToString(), out trans); if (!questStatusDef.IsSuccess(status)) { return(status); } // Delete filterLogId foreach (FilterLogId filterLogId in filterLogIdList) { status = _dbFilterLogsMgr.Delete(trans, filterLogId); if (!questStatusDef.IsSuccess(status)) { mgr.RollbackTransaction(trans); return(status); } } // COMMIT TRANSACTION status = mgr.CommitTransaction(trans); if (!questStatusDef.IsSuccess(status)) { return(status); } } catch (System.Exception ex) { if (trans != null) { mgr.RollbackTransaction(trans); } return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}", this.GetType().Name, MethodBase.GetCurrentMethod().Name, ex.InnerException != null ? ex.InnerException.Message : ex.Message))); } return(new questStatus(Severity.Success)); }
/*================================================================================================================================== * Public Methods *=================================================================================================================================*/ public questStatus Delete(FilterFolderId filterFolderId) { // Initialize questStatus status = null; DbMgrTransaction trans = null; Mgr mgr = new Mgr(this.UserSession); try { // BEGIN TRANSACTION status = mgr.BeginTransaction("DeleteFolder_" + filterFolderId.Id.ToString() + "_" + Guid.NewGuid().ToString(), out trans); if (!questStatusDef.IsSuccess(status)) { return(status); } // Load folder contents FolderId folderId = new FolderId(filterFolderId.Id); List <FilterFolder> filterFolderList = null; FilterFoldersMgr filterFoldersMgr = new FilterFoldersMgr(this.UserSession); status = filterFoldersMgr.Load(folderId, out filterFolderList); if (!questStatusDef.IsSuccess(status)) { mgr.RollbackTransaction(trans); return(status); } // Clear out the folder status = clearFolder(trans, filterFolderList); if (!questStatusDef.IsSuccess(status)) { mgr.RollbackTransaction(trans); return(status); } // Get fitlers in this folder. List <Quest.Functional.MasterPricing.Filter> filterList = null; FiltersMgr filtersMgr = new FiltersMgr(this.UserSession); status = filtersMgr.Read(folderId, out filterList); if (!questStatusDef.IsSuccess(status)) { mgr.RollbackTransaction(trans); return(status); } // Delete filters in this folder foreach (Filter filter in filterList) { FilterId filterId = new FilterId(filter.Id); status = _dbFolderMgr.DeleteFilter(filterId); if (!questStatusDef.IsSuccess(status)) { return(status); } } // Delete the folder. status = _filterFoldersMgr.Delete(trans, filterFolderId); if (!questStatusDef.IsSuccess(status)) { mgr.RollbackTransaction(trans); return(status); } // COMMIT TRANSACTION status = mgr.CommitTransaction(trans); if (!questStatusDef.IsSuccess(status)) { return(status); } } catch (System.Exception ex) { if (trans != null) { mgr.RollbackTransaction(trans); } return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}", this.GetType().Name, MethodBase.GetCurrentMethod().Name, ex.InnerException != null ? ex.InnerException.Message : ex.Message))); } return(new questStatus(Severity.Success)); }
public questStatus Save(UserPrivilegesViewModel userPrivilegesViewModel) { // Initialize questStatus status = null; DbMgrTransaction trans = null; Mgr mgr = new Mgr(this.UserSession); try { // BEGIN TRANSACTION status = mgr.BeginTransaction("FMS", "SaveUserPrivileges_" + userPrivilegesViewModel.Id.ToString() + "_" + Guid.NewGuid().ToString(), out trans); if (!questStatusDef.IsSuccess(status)) { return(status); } // Remove all the user's privileges. UserId userId = new UserId(userPrivilegesViewModel.Id); UserPrivilegesMgr userPrivilegesMgr = new UserPrivilegesMgr(this.UserSession); status = userPrivilegesMgr.Delete(trans, userId); if (!questStatusDef.IsSuccess(status)) { mgr.RollbackTransaction(trans); return(status); } // Save all the privileges the user is assigned. UserPrivilege userPrivilege = new UserPrivilege(); userPrivilege.User.Id = userPrivilegesViewModel.User.Id; foreach (BootstrapTreenodeViewModel userPrivilegeNode in userPrivilegesViewModel.UserPrivileges) { UserPrivilegeId userPrivilegeId = null; userPrivilege.Privilege.Id = userPrivilegeNode.Id; status = userPrivilegesMgr.Create(trans, userPrivilege, out userPrivilegeId); if (!questStatusDef.IsSuccess(status)) { mgr.RollbackTransaction(trans); return(status); } } // COMMIT TRANSACTION status = mgr.CommitTransaction(trans); if (!questStatusDef.IsSuccess(status)) { return(status); } } catch (System.Exception ex) { if (trans != null) { mgr.RollbackTransaction(trans); } return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}", this.GetType().Name, MethodBase.GetCurrentMethod().Name, ex.InnerException != null ? ex.InnerException.Message : ex.Message))); } return(new questStatus(Severity.Success)); }
public questStatus MakeRequired(MakeRequiredViewModel makeRequiredViewModel) { // Initialize questStatus status = null; Mgr mgr = new Mgr(this.UserSession); DbMgrTransaction trans = null; // BEGIN TRANSACTION status = mgr.BeginTransaction("MakeRequired" + Guid.NewGuid().ToString(), out trans); if (!questStatusDef.IsSuccess(status)) { return(status); } // Update every parameter as required or not. StoredProcedureParametersMgr storedProcedureParametersMgr = new StoredProcedureParametersMgr(this.UserSession); foreach (BaseId baseId in makeRequiredViewModel.Items) { // Get the parameter StoredProcedureParameterId storedProcedureParameterId = new StoredProcedureParameterId(baseId.Id); StoredProcedureParameter storedProcedureParameter = null; status = storedProcedureParametersMgr.Read(trans, storedProcedureParameterId, out storedProcedureParameter); if (!questStatusDef.IsSuccess(status)) { mgr.RollbackTransaction(trans); return(status); } // Make sure same stored procedure if (makeRequiredViewModel.StoredProcedureId != storedProcedureParameter.StoredProcedureId) { mgr.RollbackTransaction(trans); return(new questStatus(Severity.Error, "All parameter Id's must be from the same stored procedure!")); } // Set required flag accordingly and update. storedProcedureParameter.bRequired = true; status = storedProcedureParametersMgr.Update(trans, storedProcedureParameter); if (!questStatusDef.IsSuccess(status)) { mgr.RollbackTransaction(trans); return(status); } } // Set all the OTHER parameters to false List <StoredProcedureParameter> storedProcedureParameterList = null; StoredProcedureId storedProcedureId = new StoredProcedureId(makeRequiredViewModel.StoredProcedureId); status = storedProcedureParametersMgr.Read(trans, storedProcedureId, out storedProcedureParameterList); if (!questStatusDef.IsSuccess(status)) { return(status); } foreach (StoredProcedureParameter storedProcedureParameter in storedProcedureParameterList) { BaseId baseId = makeRequiredViewModel.Items.Find(delegate(BaseId _baseId) { return(_baseId.Id == storedProcedureParameter.Id); }); if (baseId == null) { storedProcedureParameter.bRequired = false; status = storedProcedureParametersMgr.Update(trans, storedProcedureParameter); if (!questStatusDef.IsSuccess(status)) { mgr.RollbackTransaction(trans); return(status); } } } // COMMIT TRANSACTION // THIS HAS TO BE COMMITTED HERE TO AVOID DEADLOCKING ON UPDATING THE FILTERS, NEXT. status = mgr.CommitTransaction(trans); if (!questStatusDef.IsSuccess(status)) { return(status); } ////// BEGIN TRANSACTION ////status = mgr.BeginTransaction("MakeRequired_RefreshFilters" + Guid.NewGuid().ToString(), out trans); ////if (!questStatusDef.IsSuccess(status)) ////{ //// return (status); ////} ////// Refresh filters using this sproc. ////List<Quest.Functional.MasterPricing.FilterId> updatedFilterIds = null; ////StoredProceduresMgr storedProceduresMgr = new StoredProceduresMgr(this.UserSession); ////status = storedProceduresMgr.RefreshFilters(storedProcedureId, out updatedFilterIds); ////if (!questStatusDef.IsSuccess(status)) ////{ //// mgr.RollbackTransaction(trans); //// return (status); ////} ////// COMMIT TRANSACTION ////status = mgr.CommitTransaction(trans); ////if (!questStatusDef.IsSuccess(status)) ////{ //// return (status); ////} ////// TODO: REFACTOR TO GET ALL-IN-ONE TRANSACTION ////foreach (FilterId filterId in updatedFilterIds) ////{ //// Quest.Functional.MasterPricing.Filter filterWithSQL = null; //// FilterMgr filterMgr = new FilterMgr(this.UserSession); //// status = filterMgr.GenerateFilterSQL(filterId, out filterWithSQL); //// if (!questStatusDef.IsSuccess(status)) //// { //// return (status); //// } //// // Update filter //// FiltersMgr filtersMgr = new FiltersMgr(this.UserSession); //// status = filtersMgr.Update(filterWithSQL); //// if (!questStatusDef.IsSuccess(status)) //// { //// return (status); //// } ////} return(new questStatus(Severity.Success)); }
/*================================================================================================================================== * Public Methods *=================================================================================================================================*/ public questStatus Save(FilterId filterId, Filter filter) { // Initialize questStatus status = null; Mgr mgr = new Mgr(this.UserSession); DbMgrTransaction trans = null; FiltersMgr filtersMgr = new FiltersMgr(this.UserSession); ColumnsMgr columnMgr = new ColumnsMgr(this.UserSession); try { // Validate filter status = Verify(filterId, filter); if (!questStatusDef.IsSuccess(status)) { return(status); } // BEGIN TRANSACTION status = mgr.BeginTransaction("SaveFilter" + Guid.NewGuid().ToString(), out trans); if (!questStatusDef.IsSuccess(status)) { return(status); } // Save the filter status = Save(trans, filterId, filter); if (!questStatusDef.IsSuccess(status)) { mgr.RollbackTransaction(trans); if (bLogging) { Filter _filter = null; status = filtersMgr.Read(filterId, out _filter); if (!questStatusDef.IsSuccess(status)) { return(status); } FilterLog filterLog = new FilterLog(); filterLog.Database = ""; filterLog.Tableset = "Tableset.Id=" + filter.TablesetId.ToString(); filterLog.Name = _filter.Name; filterLog.Event = "SAVE"; filterLog.Data = status.ToString(); FilterLogId filterLogId = null; _dbFilterLogsMgr.Create(filterLog, out filterLogId); } return(status); } // COMMIT TRANSACTION status = mgr.CommitTransaction(trans); if (!questStatusDef.IsSuccess(status)) { return(status); } // Logging if (bLogging) { Filter _filter = null; status = filtersMgr.Read(filterId, out _filter); if (!questStatusDef.IsSuccess(status)) { return(status); } FilterLog filterLog = new FilterLog(); filterLog.Database = ""; filterLog.Tableset = "Tableset.Id=" + filter.TablesetId.ToString(); filterLog.Name = _filter.Name; filterLog.Event = "SAVE"; filterLog.Data = status.ToString(); FilterLogId filterLogId = null; _dbFilterLogsMgr.Create(filterLog, out filterLogId); } // TODO: REFACTOR TO GET ALL-IN-ONE TRANSACTION // Generate filter SQL Filter filterWithSQL = null; DbFilterMgr dbFilterMgr = new DbFilterMgr(this.UserSession); status = dbFilterMgr.GenerateFilterSQL(filterId, out filterWithSQL); if (!questStatusDef.IsSuccess(status)) { return(status); } // Update filter status = filtersMgr.Update(filterWithSQL); if (!questStatusDef.IsSuccess(status)) { return(status); } } catch (System.Exception ex) { if (trans != null) { mgr.RollbackTransaction(trans); } return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}", this.GetType().Name, MethodBase.GetCurrentMethod().Name, ex.InnerException != null ? ex.InnerException.Message : ex.Message))); } return(new questStatus(Severity.Success)); }