public static View.ClientLocationViewCollection GetClientLocationViewByClientName(string clientName) { YellowstonePathology.Business.View.ClientLocationViewCollection result = new View.ClientLocationViewCollection(); YellowstonePathology.Business.Mongo.Server server = new Business.Mongo.TestServer(YellowstonePathology.Business.Mongo.MongoTestServer.LISDatabaseName); MongoCollection collection = server.Database.GetCollection <BsonDocument>("Client"); MongoCursor cursor = collection.FindAs <BsonDocument>(Query.Matches("ClientName", BsonRegularExpression.Create("^" + clientName + ".*", "i"))); foreach (BsonDocument bsonDocument in cursor) { BsonArray locations = bsonDocument.GetValue("ClientLocationCollection").AsBsonArray; foreach (BsonDocument location in locations) { YellowstonePathology.Business.View.ClientLocationView clientLocationView = new View.ClientLocationView(bsonDocument.GetValue("ClientId").AsInt32, location.GetValue("ClientLocationId").AsInt32, Mongo.ValueHelper.GetStringValue(bsonDocument.GetValue("ClientName")), Mongo.ValueHelper.GetStringValue(location.GetValue("Location"))); result.Add(clientLocationView); } } return(result); }
public static View.ClientLocationViewCollection GetClientLocationViewByClientName(string clientName) { YellowstonePathology.Business.View.ClientLocationViewCollection result = new View.ClientLocationViewCollection(); YellowstonePathology.Business.Mongo.Server server = new Business.Mongo.TestServer(YellowstonePathology.Business.Mongo.MongoTestServer.LISDatabaseName); MongoCollection collection = server.Database.GetCollection<BsonDocument>("Client"); MongoCursor cursor = collection.FindAs<BsonDocument>(Query.Matches("ClientName", BsonRegularExpression.Create("^" + clientName + ".*", "i"))); foreach (BsonDocument bsonDocument in cursor) { BsonArray locations = bsonDocument.GetValue("ClientLocationCollection").AsBsonArray; foreach (BsonDocument location in locations) { YellowstonePathology.Business.View.ClientLocationView clientLocationView = new View.ClientLocationView(bsonDocument.GetValue("ClientId").AsInt32, location.GetValue("ClientLocationId").AsInt32, Mongo.ValueHelper.GetStringValue(bsonDocument.GetValue("ClientName")), Mongo.ValueHelper.GetStringValue(location.GetValue("Location"))); result.Add(clientLocationView); } } return result; }
/*private static View.ClientPhysicianView BuildClientPhysicianView(XElement sourceElement) { View.ClientPhysicianView result = new View.ClientPhysicianView(); XElement clientElement = sourceElement.Element("Client"); YellowstonePathology.Business.Persistence.XmlPropertyWriter xmlPropertyWriter = new Persistence.XmlPropertyWriter(clientElement, result); xmlPropertyWriter.Write(); XElement physiciansElement = clientElement.Element("Physicians"); if (physiciansElement != null) { List<XElement> physicianElements = physiciansElement.Elements("Physician").ToList<XElement>(); foreach (XElement physicianElement in physicianElements) { Domain.Physician physician = new Domain.Physician(); YellowstonePathology.Business.Persistence.XmlPropertyWriter xmlPropertyWriter1 = new Persistence.XmlPropertyWriter(physicianElement, physician); xmlPropertyWriter1.Write(); result.Physicians.Add(physician); } } return result; }*/ /*private static YellowstonePathology.Business.Client.Model.ClientCollection BuildClientCollection(XElement sourceElement) { YellowstonePathology.Business.Client.Model.ClientCollection clientCollection = new YellowstonePathology.Business.Client.Model.ClientCollection(); if (sourceElement != null) { foreach (XElement clientElement in sourceElement.Elements("Client")) { ClientBuilder builder = new ClientBuilder(); builder.Build(clientElement); YellowstonePathology.Business.Client.Model.Client client = builder.Client; clientCollection.Add(client); } } return clientCollection; }*/ /*private static View.PhysicianClientView BuildPhysicianClientView(SqlCommand cmd) { View.PhysicianClientView result = new View.PhysicianClientView(); using (SqlConnection cn = new SqlConnection(Properties.Settings.Default.ProductionConnectionString)) { cn.Open(); cmd.Connection = cn; using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { YellowstonePathology.Business.Persistence.SqlDataReaderPropertyWriter sqlDataReaderPropertyWriter = new Persistence.SqlDataReaderPropertyWriter(result, dr); sqlDataReaderPropertyWriter.WriteProperties(); } dr.NextResult(); while (dr.Read()) { YellowstonePathology.Business.Client.Model.Client client = new YellowstonePathology.Business.Client.Model.Client(); YellowstonePathology.Business.Persistence.SqlDataReaderPropertyWriter sqlDataReaderPropertyWriter = new Persistence.SqlDataReaderPropertyWriter(client, dr); sqlDataReaderPropertyWriter.WriteProperties(); result.Clients.Add(client); } } } return result; }*/ public static View.ClientLocationViewCollection GetClientLocationViewByClientName(string clientName) { #if MONGO return PhysicianClientGatewayMongo.GetClientLocationViewByClientName(clientName); #else /*SqlCommand cmd = new SqlCommand(); cmd.CommandText = "select c.ClientId, c.ClientName, cl.ClientLocationId, cl.Location from tblClientLocation cl join tblClient c on cl.ClientId = c.ClientId where c.ClientName like @ClientName + '%' Order By 2, 4 " + "for xml path('ClientLocationView'), type, root('ClientLocationViewCollection')"; cmd.CommandType = CommandType.Text; cmd.Parameters.Add("@ClientName", SqlDbType.VarChar).Value = clientName; View.ClientLocationViewCollection results = Persistence.SqlCommandHelper.ExecuteCollectionCommand<View.ClientLocationViewCollection>(cmd); if (results == null) { results = new View.ClientLocationViewCollection(); } return results;*/ SqlCommand cmd = new SqlCommand(); cmd.CommandText = "select c.ClientId, c.ClientName, cl.ClientLocationId, cl.Location from tblClientLocation cl join tblClient c on cl.ClientId = c.ClientId where c.ClientName like @ClientName + '%' Order By 2, 4"; cmd.CommandType = CommandType.Text; cmd.Parameters.Add("@ClientName", SqlDbType.VarChar).Value = clientName; View.ClientLocationViewCollection result = new View.ClientLocationViewCollection(); using (SqlConnection cn = new SqlConnection(YellowstonePathology.Business.BaseData.SqlConnectionString)) { cn.Open(); cmd.Connection = cn; using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { View.ClientLocationView clientLocationView = new View.ClientLocationView(); YellowstonePathology.Business.Persistence.SqlDataReaderPropertyWriter sqlDataReaderPropertyWriter = new Persistence.SqlDataReaderPropertyWriter(clientLocationView, dr); sqlDataReaderPropertyWriter.WriteProperties(); result.Add(clientLocationView); } } } return result; #endif }