using System using System Collections Generic using System Linq using

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Novag.Traiding.Dal.Interfaces;
using AutoMapper;
namespace Traiding.Dal.SubSonicDao.Impl
{
public class JsonDbManager : IJsonDbManager
{
#region static
static JsonDbManager()
{
}
#endregion
#region IJsonDbManager Members
public IList<JsonCompanyModel> FindCompanies(int? pageId, int? countPerPage)
{
List<JsonCompanyModel> result = new List<JsonCompanyModel>();
#region список компаний
SubSonic.SqlQuery query = new SubSonic.Select().From(NtrJsonCompany.Schema.TableName);
if (pageId.HasValue && countPerPage.HasValue)
query.Paged(pageId.Value, countPerPage.Value);
NtrJsonCompanyCollection dbModelCollection = new NtrJsonCompanyCollection();
dbModelCollection.Load(query.ExecuteReader());
foreach (NtrJsonCompany someDbModel in dbModelCollection)
{
JsonCompanyModel newModel = new JsonCompanyModel();
newModel.Id = someDbModel.Id;
#region локализация
NtrJsonCompanyLocalizationCollection colLoc = new NtrJsonCompanyLocalizationCollection();
colLoc.Load(NtrJsonCompanyLocalization.FetchByParameter(NtrJsonCompanyLocalization.Columns.CompanyId, someDbModel.Id));
NtrJsonCompanyLocalization ru = colLoc.First(el => el.LocaleId == 1);
NtrJsonCompanyLocalization en = colLoc.First(el => el.LocaleId == 2);
newModel.Name = String.Format("{0} / {1}",
ru != null ? ru.CompanyName : String.Empty,
en != null ? en.CompanyName : String.Empty);
newModel.INN = ru.CompanyINN;
newModel.KPP = ru.CompanyKPP;
#endregion
result.Add(newModel);
}
#endregion
return result;
}
public IList<JsonCompanyModel> FindCompaniesPageByTradeGroupId(int pageIndex, int countPerPage,
bool needTotalRecordCount, out int totalRecordCount,
QueryPageSettings querySettings, int tradeGroupId)
{
List<JsonCompanyModel> result = new List<JsonCompanyModel>();
CompanyDbManager companyDbManager = new CompanyDbManager();
IList<CompanyModel> dbResult = companyDbManager.FindPageByTradeGroupId(
pageIndex, countPerPage,
needTotalRecordCount,
out totalRecordCount,
querySettings,
tradeGroupId);
foreach (CompanyModel someModel in dbResult)
{
JsonCompanyModel newJsonModel = new JsonCompanyModel();
newJsonModel.Id = someModel.Id;
CompanyLocalizationModel ru = someModel.Locales.First(el => el.LocaleId == 1);
CompanyLocalizationModel en = someModel.Locales.First(el => el.LocaleId == 2);
newJsonModel.Name = String.Format("{0} / {1}",
ru != null ? ru.CompanyName : String.Empty,
en != null ? en.CompanyName : String.Empty);
newJsonModel.INN = ru.CompanyINN;
newJsonModel.KPP = ru.CompanyKPP;
result.Add(newJsonModel);
}
return result;
}
#endregion
#region IJsonDbManager Members
public JsonCompanyModel FindCompanyById(int companyId, QueryPageSettings querySettings)
{
JsonCompanyModel result = null;
CompanyDbManager companyDbManager = new CompanyDbManager();
CompanyModel someModel = companyDbManager.Read(companyId, querySettings);
if (someModel != null)
{
result = new JsonCompanyModel();
result.Id = someModel.Id;
CompanyLocalizationModel ru = someModel.Locales.First(el => el.LocaleId == 1);
CompanyLocalizationModel en = someModel.Locales.First(el => el.LocaleId == 2);
result.Name = String.Format("{0} / {1}",
ru != null ? ru.CompanyName : String.Empty,
en != null ? en.CompanyName : String.Empty);
result.INN = ru.CompanyINN;
result.KPP = ru.CompanyKPP;
}
return result;
}
#endregion
#region IJsonDbManager Members
public IList<JsonGoodModel> FindGoodsByCompanyId(int pageIndex, int countPerPage,
bool needTotalRecordCount, out int totalRecordCount,
QueryPageSettings querySettings, int companyId)
{
List<JsonGoodModel> result = new List<JsonGoodModel>();
GoodDbManager goodManager = new GoodDbManager();
IList<GoodModel> dbResult = goodManager.FindByCompanyId(pageIndex, countPerPage,
needTotalRecordCount,
out totalRecordCount,
querySettings,
companyId);
foreach (GoodModel someModel in dbResult)
{
JsonGoodModel newJsonModel = new JsonGoodModel();
newJsonModel.Id = someModel.Id;
GoodLocalizationModel ru = someModel.Locales.First(el => el.LocaleId == 1);
GoodLocalizationModel en = someModel.Locales.First(el => el.LocaleId == 2);
newJsonModel.Name = String.Format("{0} / {1}",
ru != null ? ru.Marking : String.Empty,
en != null ? en.Marking : String.Empty);
newJsonModel.Measure = String.Format("{0} / {1}",
ru != null ? ru.Measure : String.Empty,
en != null ? en.Measure : String.Empty);
result.Add(newJsonModel);
}
return result;
}
#endregion
}
}