var firstArea = new int[] { 1, 860, 20, 2468 };
//直辖市列表(根据区域一级ProvinceName分组)
var points = from info in model.MediaPointList
where firstArea.Contains(info.ProvinceId)
group info by info.ProvinceId into g
orderby g.Count() descending
select new
{
Cid = g.Key,
Count = g.Count(),
g
};
//非直辖市(地级市)列表(根据区域二级CityName分组)
var points2 = from info in model.MediaPointList
where !firstArea.Contains(info.ProvinceId)
group info by info.CityId into g
orderby g.Count() descending
select new
{
Cid = g.Key,
Count = g.Count(),
g
};
var points3 = points.Union(points2);//合并直辖市与一般地级市

==========================================================

#region 价格属性Json对象
if (model.MediaPriceList != null && model.MediaPriceList.Count > 0)
{
if (model.MediaPriceList.FirstOrDefault().Id != 0)
{
StringBuilder sbAttr = new StringBuilder();
var attributeValues = from item in model.MediaPriceList
orderby item.Id
group item by item.Id into priceGroup
orderby priceGroup.Key
select priceGroup;

var attributes = from item in model.MediaPriceList
orderby item.Id
group item by item.PriceId into priceGroup
orderby priceGroup.Key
select priceGroup;

sbAttr.Append("{\"AttrValueList\":[");
foreach (var item in attributeValues)
{
var _defaut = item.FirstOrDefault();
sbAttr.Append("{\"AttrName\": "); sbAttr.Append("\"" + _defaut.Name + "\""); sbAttr.Append(",");
sbAttr.Append("\"AttrValue\":[");
var temp = item.Select(i => i.AttributeValue).Distinct();
List<string> values = temp.ToList();

foreach (string value in values)
{
sbAttr.Append("{\"AttrId\": "); sbAttr.Append(_defaut.Id); sbAttr.Append(",");
sbAttr.Append("\"Value\": "); sbAttr.Append("\"" + value + "\""); sbAttr.Append(",");
sbAttr.Append("\"Unit\": "); sbAttr.Append("\"" + _defaut.UnitName + "\""); sbAttr.Append(",");

string _self = string.Empty;
var queryResult = model.MediaPriceList.Where(m => m.Id == _defaut.Id && m.AttributeValue == value).ToList();
foreach (var s in queryResult)
{
_self += "," + s.MediaPriceValueId;
}
if (!string.IsNullOrEmpty(_self))
{
_self = _self + ",";
}
sbAttr.Append("\"_selfIds\": "); sbAttr.Append("\"" + _self + "\""); sbAttr.Append(",");

string _gl = string.Empty;
var priceIds = model.MediaPriceList.Where(m => m.Id == _defaut.Id && m.AttributeValue == value).ToList().Select(s => s.PriceId).Distinct();
var queryResult2 = from p in model.MediaPriceList
where (priceIds).Contains(p.PriceId) && p.Id != _defaut.Id
select p;

foreach (var s in queryResult2)
{
_gl +=s.MediaPriceValueId + ",";
}
if (!string.IsNullOrEmpty(_gl))
{
_gl = _gl.TrimEnd(',');
}

sbAttr.Append("\"_glIds\": "); sbAttr.Append("\"" + _gl + "\"");

sbAttr.Append("},");
}
sbAttr.Remove(sbAttr.Length - 1, 1);
sbAttr.Append("]},");
}
sbAttr.Remove(sbAttr.Length - 1, 1);
sbAttr.Append("],");


sbAttr.Append("\"MediaPrice\":[");
foreach (var item in attributes)
{
var _FirstAttribute = item.FirstOrDefault();
//int _price = Convert.ToInt32(_FirstAttribute.CardPrice);
//string cardPrice = _price >= 10000 ? (_price / 10000).ToString() : _price.ToString();
decimal _price = _FirstAttribute.CardPrice += 0.0001m;
double _p1 = Convert.ToDouble(_price);
if (_price > 10000) _p1 = _p1 / 10000;
double _p2 = _p1 % 0.01;
string cardPrice = (_p1 - _p2).ToString();

string priceUnit = _price >= 10000 ? ("万元" + _FirstAttribute.PriceName) : ("元" + _FirstAttribute.PriceName);
sbAttr.Append("{\"AttrValuIds\": ");
string str = string.Empty;
foreach (var item2 in item)
{
str += "_" + item2.AttributeValue;
}
sbAttr.Append("\"" + str + "\"");
sbAttr.Append(",");
sbAttr.Append("\"Price\":\"" + cardPrice);
sbAttr.Append("\",\"PriceUnit\":\"" + priceUnit);
sbAttr.Append("\"},");
}
sbAttr.Remove(sbAttr.Length - 1, 1);
sbAttr.Append("]}");
ViewBag.AttrJson = sbAttr.ToString();
}
}
#endregion

posted on 2013-03-11 15:00  老班长  阅读(311)  评论(0编辑  收藏  举报