1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Text;
5:
6: using SQLAzureBCSDemo.Stores;
7:
8: namespace SQLAzureBCSDemo.Stores
9: {
10: public partial class StoreService
11: {
12: public static IEnumerable<Store> ReadStores()
13: {
14: using (SQLAzureStoresDataContext ctx =
15: new SQLAzureStoresDataContext(
16: "Server=tcp:<Server>.database.windows.net;Database=<BD>;User ID=<User>;Password=<Password>;Trusted_Connection=False;Encrypt=True;"))
17: {
18:
19: var qStores = from s in ctx.StoreInformations
20: select new{
21: SID=s.StoreID,
22: STitle=s.Title,
23: SName=s.StoreName,
24: SAddress=s.StoreAddress,
25: SPhone=s.StorePhone,
26: SLatitude=s.Latitude,
27: SLongitude=s.Longitude,
28: SHours=s.Hours
29: };
30:
31: List<Store> cStores = new List<Store>();
32: foreach (var qs in qStores)
33: {
34: Store cStore = new Store();
35: cStore.StoreID = qs.SID;
36: cStore.StoreTitle = qs.STitle;
37: cStore.StoreName = qs.SName;
38: cStore.StoreAddress = qs.SAddress;
39: cStore.StorePhone = qs.SPhone;
40: cStore.StoreLatitude = qs.SLatitude;
41: cStore.StoreLongitude = qs.SLongitude;
42: cStore.StoreHours = qs.SHours;
43: cStores.Add(cStore);
44: }
45: return cStores;
46: }
47: }
48:
49: public static Store ReadStore(int id)
50: {
51: using (SQLAzureStoresDataContext ctx =
52: new SQLAzureStoresDataContext(
53: "Server=tcp:<Server>.database.windows.net;Database=<BD>;User ID=<User>;Password=<Password>;Trusted_Connection=False;Encrypt=True;"))
54: {
55:
56: var qStores = from s in ctx.StoreInformations
57: where s.StoreID == id
58: select new
59: {
60: SID = s.StoreID,
61: STitle = s.Title,
62: SName = s.StoreName,
63: SAddress = s.StoreAddress,
64: SPhone = s.StorePhone,
65: SLatitude = s.Latitude,
66: SLongitude = s.Longitude,
67: SHours = s.Hours
68: };
69:
70:
71: Store cStore = new Store();
72: cStore.StoreID = qStores.First().SID;
73: cStore.StoreTitle = qStores.First().STitle;
74: cStore.StoreName = qStores.First().SName;
75: cStore.StoreAddress = qStores.First().SAddress;
76: cStore.StorePhone = qStores.First().SPhone;
77: cStore.StoreLatitude = qStores.First().SLatitude;
78: cStore.StoreLongitude = qStores.First().SLongitude;
79: cStore.StoreHours = qStores.First().SHours;
80: return cStore;
81: }
82: }
83: }
84: }