public IAsyncResult BeginGetCatalog(CatalogItemFilter filter, Identification identification, AsyncCallback callback, object state) { logger.Log(LogLevel.Trace, AppLib.GetCaller(logger)); if (AppLib.VerifyToken(identification.Token) <= 0) { throw new FaultException<ServiceFault>(new ServiceFault("Invalid Authentication", "Authorization"), new FaultReason("Unauthorized")); } var task = Task<SmartCollection<CatalogItem>>.Factory.StartNew(process => DoGetCatalog(filter, identification), state); return task.ContinueWith(res => callback(task)); }
public SmartCollection<CatalogItem> GetCatalog(CatalogItemFilter filter, Identification identification) { try { SmartCollection<CatalogItem> resultList = new SmartCollection<CatalogItem>(); using (DbConnection = new MsSqlPersistence(DbConnectionSettings)) { if (DbConnection.IsConnected()) { using (DbCommand) { DbCommand.CommandType = CommandType.StoredProcedure; DbCommand.CommandText = "uspGetCatalog"; DbCommand.Parameters.Clear(); DbCommand.Parameters.Add("@AnalyteIds", System.Data.SqlDbType.NVarChar, 4000).Value = filter.Analytes.Count > 0 ? string.Join<string>(",", filter.Analytes.Select(x => x.AnalyteId.ToString())) : SqlString.Null; DbCommand.Parameters.Add("@ClientSelectableYN", SqlDbType.Bit).Value = true; DbCommand.Parameters.Add("@SearchString", SqlDbType.NVarChar, 255).Value = filter.SearchString ?? filter.SearchString; DbCommand.Parameters.Add("@FilterAsRawMaterial", SqlDbType.Bit).Value = filter.FilterAsRawMaterial ?? filter.FilterAsRawMaterial; DbCommand.Parameters.Add("@FilterAsCompound", SqlDbType.Bit).Value = filter.FilterAsCompound ?? filter.FilterAsCompound; DataTable catalogDT = DbConnection.ExecuteQuery(DbCommand); foreach (DataRow row in catalogDT.Rows) { CatalogItem catalogItem = new CatalogItem(); if (row["CatalogID"] != DBNull.Value) catalogItem.CatalogId = (int)row["CatalogID"]; catalogItem.Active = row["Active"] != DBNull.Value ? (bool)row["Active"] : false; if (row["TestID"] != DBNull.Value) catalogItem.TestId = (int)row["TestID"]; if (row["AnalyteID"] != DBNull.Value) catalogItem.AnalyteId = (int)row["AnalyteID"]; if (row["MethodID"] != DBNull.Value) catalogItem.MethodId = (int)row["MethodID"]; if (row["MethodNumberID"] != DBNull.Value) catalogItem.MethodNumberId = (int)row["MethodNumberID"]; if (row["AnalystID"] != DBNull.Value) catalogItem.AnalystId = (int)row["AnalystID"]; if (row["DepartmentID"] != DBNull.Value) catalogItem.DepartmentId = (int)row["DepartmentID"]; catalogItem.OutsourcedYN = row["OutsourcedYN"] != DBNull.Value ? (bool)row["OutsourcedYN"] : false; catalogItem.ClientSelectableYN = row["ClientSelectableYN"] != DBNull.Value ? (bool)row["ClientSelectableYN"] : false; catalogItem.BasePrice = row["BasePrice"] != DBNull.Value ? (decimal)row["BasePrice"] : 0; if (row["LowSpec"] != DBNull.Value) catalogItem.LowSpec = Convert.ToDecimal(row["LowSpec"]); if (row["HighSpec"] != DBNull.Value) catalogItem.HighSpec = Convert.ToDecimal(row["HighSpec"]); catalogItem.CalculatePercentageExpectedYN = row["CalculatePercentageExpectedYN"] != DBNull.Value ? (bool)row["CalculatePercentageExpectedYN"] : false; catalogItem.OtherSpec = row["OtherSpec"] != DBNull.Value ? row["OtherSpec"].ToString() : null; catalogItem.TestMinutes = row["TestMinutes"] != DBNull.Value ? (short?)row["TestMinutes"] : 0; catalogItem.EquipmentMinutes = row["EquipmentMinutes"] != DBNull.Value ? (short?)row["EquipmentMinutes"] : 0; catalogItem.AccountingCode = row["AccountingCode"] != DBNull.Value ? row["AccountingCode"].ToString() : null; catalogItem.Instructions = row["Instructions"] != DBNull.Value ? row["Instructions"].ToString() : null; if (catalogItem.AnalyteId != null && catalogItem.AnalyteId != -1) catalogItem.Analyte = new Analyte() { AnalyteId = catalogItem.AnalyteId, AnalyteName = row["AnalyteName"].ToString(), ControlledYN = Convert.ToBoolean(row["ControlledYN"]), AntibioticYN = Convert.ToBoolean(row["AntibioticYN"]), Active = true }; //else result.Analyte = new AnalyteItem() { AnalyteId = result.AnalyteId, AnalyteName = "Any Analyte", ControlledYN = false, AntibioticYN = false, Active = true }; if (catalogItem.MethodId != null && catalogItem.MethodId != -1) catalogItem.Method = new Method() { MethodId = catalogItem.MethodId, MethodName = row["MethodName"].ToString(), Active = true }; //else result.Method = new Method() { MethodId = result.MethodId, MethodName = "Any Method", Active = true }; if (catalogItem.MethodNumberId != null && catalogItem.MethodNumberId != -1) catalogItem.MethodNumber = new MethodNumber() { MethodNumberId = catalogItem.MethodNumberId, MethodNumberName = row["MethodNumberName"].ToString(), Active = true }; //else result.MethodNumber = new MethodNumber() { MethodNumberId = result.MethodNumberId, MethodNumberName = "Any Method #", Active = true }; if (catalogItem.AnalystId != null && catalogItem.AnalystId != -1) catalogItem.Analyst = new User() { UserId = catalogItem.AnalystId, FirstName = row["FirstName"].ToString(), LastName = row["LastName"].ToString() }; if (catalogItem.DepartmentId != null && catalogItem.DepartmentId != -1) catalogItem.Department = new Department() { DepartmentId = catalogItem.DepartmentId, DepartmentName = row["DepartmentName"].ToString() }; if (catalogItem.TestId != null && catalogItem.TestId != -1) catalogItem.Test = new Test() { TestId = catalogItem.TestId, TestName = row["TestName"].ToString(), FilterAsRawMaterial = row["FilterAsRawMaterial"] != DBNull.Value ? (bool)row["FilterAsRawMaterial"] : false, FilterAsCompound = row["FilterAsCompound"] != DBNull.Value ? (bool)row["FilterAsCompound"] : false }; catalogItem.RequirementYN = row["RequirementYN"] != DBNull.Value ? (bool)row["RequirementYN"] : false; catalogItem.RequirementDescription = row["RequirementDescription"] != DBNull.Value ? row["RequirementDescription"].ToString() : null; catalogItem.DiscountAllowedYN = row["DiscountAllowedYN"] != DBNull.Value ? (bool)row["DiscountAllowedYN"] : false; catalogItem.SelectionOrder = row["SelectionOrder"] != DBNull.Value ? Convert.ToInt32(row["SelectionOrder"]) : new Int32(); catalogItem.CreatedBy = row["CreatedBy"] != DBNull.Value ? Convert.ToInt32(row["CreatedBy"]) : new Int32(); catalogItem.CreatedUser = row["CreatedUser"] != DBNull.Value ? row["CreatedUser"].ToString() : null; catalogItem.CreatedDate = row["CreatedDate"] != DBNull.Value ? (DateTime)row["CreatedDate"] : (DateTime)SqlDateTime.Null; catalogItem.ModifiedBy = row["ModifiedBy"] != DBNull.Value ? Convert.ToInt32(row["ModifiedBy"]) : new Int32(); catalogItem.ModifiedUser = row["ModifiedUser"] != DBNull.Value ? row["ModifiedUser"].ToString() : null; catalogItem.ModifiedDate = row["ModifiedDate"] != DBNull.Value ? (DateTime)row["ModifiedDate"] : (DateTime)SqlDateTime.Null; catalogItem.CatalogItemPriorities = this.GetCatalogItemPriorityRestrictions(ref dbConnection, ref dbCommand, (int)catalogItem.CatalogId, identification); resultList.Add(catalogItem); } catalogDT = null; } }else { throw new Exception("Unable to Connect"); } } return resultList; }catch { throw; } }
public SmartCollection<CatalogItem> DoGetCatalog(CatalogItemFilter filter, Identification identification) { logger.Log(LogLevel.Trace, AppLib.GetCaller(logger)); using (CatalogDAO dao = new CatalogDAO()) { return dao.GetCatalog(filter, identification); } }