public ActionResult MakeRequired(MakeRequiredViewModel viewModel) { questStatus status = null; /*---------------------------------------------------------------------------------------------------------------------------------- * Log Operation *---------------------------------------------------------------------------------------------------------------------------------*/ status = LogOperation(); if (!questStatusDef.IsSuccess(status)) { viewModel.questStatus = status; return(Json(viewModel)); } /*---------------------------------------------------------------------------------------------------------------------------------- * Authorize *---------------------------------------------------------------------------------------------------------------------------------*/ status = Authorize(viewModel._ctx); if (!questStatusDef.IsSuccess(status)) { viewModel.questStatus = status; return(Json(viewModel)); } /*---------------------------------------------------------------------------------------------------------------------------------- * Perform operation. *---------------------------------------------------------------------------------------------------------------------------------*/ ParameterListModeler parameterListModeler = new ParameterListModeler(this.Request, this.UserSession); status = parameterListModeler.MakeRequired(viewModel); if (!questStatusDef.IsSuccess(status)) { viewModel.questStatus = status; return(Json(viewModel)); } /*---------------------------------------------------------------------------------------------------------------------------------- * Return result. *---------------------------------------------------------------------------------------------------------------------------------*/ status = new questStatus(Severity.Success, "Parameters successfull made as required."); viewModel.questStatus = status; return(Json(viewModel)); }
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)); }