public SigmaResultType AddCWA(TypeCWA objCWA) { TypeUserInfo userinfo = AuthMgr.GetUserInfo(); TransactionScope scope = null; SigmaResultType result = new SigmaResultType(); // Get connection string string connStr = ConnStrHelper.getDbConnString(); List<SqlParameter> paramList = new List<SqlParameter>(); paramList.Add(new SqlParameter("@ProjectId", Utilities.ToInt32(userinfo.CurrentProjectId.ToString().Trim()))); paramList.Add(new SqlParameter("@Name", objCWA.Name.Trim())); paramList.Add(new SqlParameter("@Area", objCWA.Area)); paramList.Add(new SqlParameter("@Description", objCWA.Description.Trim())); paramList.Add(new SqlParameter("@CreatedBy", userinfo.SigmaUserId.Trim())); SqlParameter outParam = new SqlParameter("@NewId", SqlDbType.Int); outParam.Direction = ParameterDirection.Output; paramList.Add(outParam); using (scope = new TransactionScope(TransactionScopeOption.Required)) { result.AffectedRow = SqlHelper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, "usp_AddCWA", paramList.ToArray()); result.IsSuccessful = true; result.ScalarValue = (int)outParam.Value; scope.Complete(); } return result; }
public SigmaResultType AddCWA(TypeCWA objCWA) { SigmaResultType result = new SigmaResultType(); try { CWAMgr cWAMgr = new CWAMgr(); result = cWAMgr.AddCWAInfo(objCWA); return result; } catch (Exception ex) { // Log Exception ExceptionHelper.logException(ex); result.IsSuccessful = false; result.ErrorMessage = ex.Message; return result; } }
public SigmaResultType AddCWAInfo(TypeCWA objCWA) { TransactionScope scope = null; SigmaResultType result = new SigmaResultType(); SigmaResultType resultTypeCWA = new SigmaResultType(); bool isCWP = true; if (objCWA.CWP.Count > 0) { var count = objCWA.CWP.Where(p => p.SigmaOperation == "C" && (p.CwpName.Trim() == "" || p.DisciplineCode.Trim() == "" || p.Description.Trim() == "")).Count(); if (count > 0) isCWP = false; } if (!(string.IsNullOrEmpty(objCWA.Name)) && !(string.IsNullOrEmpty(objCWA.Description)) && isCWP ) { using (scope = new TransactionScope(TransactionScopeOption.RequiresNew)) { if (objCWA.SigmaOperation == SigmaOperation.INSERT) { resultTypeCWA = AddCWA(objCWA); objCWA.CWP.ForEach(item => item.CwaId = resultTypeCWA.ScalarValue); } else if (objCWA.SigmaOperation == SigmaOperation.UPDATE) { resultTypeCWA = UpdateCWA(objCWA); objCWA.CWP.ForEach(item => item.CwaId = objCWA.CwaId); } if (resultTypeCWA.IsSuccessful && objCWA.CWP.Count > 0) { foreach (var item in objCWA.CWP) { switch (item.SigmaOperation) { case SigmaOperation.INSERT: AddCWP(item); break; case SigmaOperation.UPDATE: UpdateCWP(item); break; case SigmaOperation.DELETE: RemoveCWP(item); break; } } } result.AffectedRow = resultTypeCWA.AffectedRow; result.ScalarValue = resultTypeCWA.ScalarValue; result.IsSuccessful = true; scope.Complete(); } } else { result.AffectedRow = -1; result.ErrorCode = "GlobalSetting0001"; result.ErrorMessage = "Validation"; result.IsSuccessful = false; } return result; }
public SigmaResultType UpdateCWA(TypeCWA objCWA) { TypeUserInfo userinfo = AuthMgr.GetUserInfo(); TransactionScope scope = null; SigmaResultType result = new SigmaResultType(); // Get connection string string connStr = ConnStrHelper.getDbConnString(); // Compose parameters SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@CwaId", Utilities.ToInt32(objCWA.CwaId.ToString().Trim())), new SqlParameter("@ProjectId", Utilities.ToInt32(userinfo.CurrentProjectId.ToString().Trim())), new SqlParameter("@Name", objCWA.Name.Trim()), new SqlParameter("@Area", objCWA.Area), new SqlParameter("@Description", objCWA.Description.Trim()), new SqlParameter("@UpdatedBy", userinfo.SigmaUserId.Trim()) }; using (scope = new TransactionScope(TransactionScopeOption.Required)) { result.AffectedRow = SqlHelper.ExecuteNonQuery(connStr, "usp_UpdateCWA", parameters); result.IsSuccessful = true; scope.Complete(); } return result; }
public SigmaResultType RemoveCWA(TypeCWA objCWA) { SigmaResultType result = new SigmaResultType(); TransactionScope scope = null; // Get connection string string connStr = ConnStrHelper.getDbConnString(); // Compose parameters SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@CwaId", Utilities.ToInt32(objCWA.CwaId.ToString().Trim())) }; using (scope = new TransactionScope(TransactionScopeOption.Required)) { result.AffectedRow = SqlHelper.ExecuteNonQuery(connStr, "usp_RemoveCWA", parameters); result.IsSuccessful = true; scope.Complete(); } return result; }