Created
February 25, 2013 20:08
-
-
Save thePunderWoman/5032810 to your computer and use it in GitHub Desktop.
Integrated GetLatestPartsJson
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parts = (from p in db.Parts | |
join ci in db.CartIntegrations on p.partID equals ci.partID | |
join cu in db.Customers on ci.custID equals cu.customerID | |
join c in db.Classes on p.classID equals c.classID into ClassTemp | |
from c in ClassTemp.DefaultIfEmpty() | |
where p.featured == true && statuslist.Contains(p.status) && cu.customerID.Equals(customerID) && ci.custPartID > 0 | |
orderby p.dateModified descending | |
select new APIPart { | |
partID = p.partID, | |
custPartID = ci.custPartID, | |
status = p.status, | |
dateModified = Convert.ToDateTime(p.dateModified).ToString(), | |
dateAdded = Convert.ToDateTime(p.dateAdded).ToString(), | |
shortDesc = "CURT " + p.shortDesc + " #" + p.partID.ToString(), | |
oldPartNumber = p.oldPartNumber, | |
listPrice = GetCustomerPrice(customerID, p.partID), | |
pClass = (c != null) ? c.class1 : "", | |
priceCode = p.priceCode, | |
relatedCount = db.RelatedParts.Where(x => x.partID == p.partID).Select(x => new { relatedID = x.relatedID }).Count(), | |
attributes = (from pa in db.PartAttributes | |
where pa.partID.Equals(p.partID) | |
orderby pa.sort | |
select new APIAttribute { key = pa.field, value = pa.value }).ToList<APIAttribute>(), | |
content = (from co in p.ContentBridges | |
orderby co.contentID | |
select new APIAttribute { key = co.Content.ContentType.type, value = co.Content.text }).OrderBy(x => x.key).ToList<APIAttribute>(), | |
videos = (from pv in p.PartVideos | |
orderby pv.vTypeID | |
select new APIVideo { videoID = pv.pVideoID, youTubeVideoID = pv.video, isPrimary = pv.isPrimary, typeID = pv.vTypeID, type = pv.videoType.name, typeicon = pv.videoType.icon }).ToList<APIVideo>(), | |
packages = (from pp in p.PartPackages | |
select new APIPackage { height = pp.height, length = pp.length, width = pp.width, weight = pp.weight, quantity = pp.quantity, dimensionUnit = pp.dimensionUnit.code, dimensionUnitLabel = pp.dimensionUnit.name, weightUnit = pp.weightUnit.code, weightUnitLabel = pp.weightUnit.name, packageUnit = pp.packageUnit.code, packageUnitLabel = pp.packageUnit.name }).ToList<APIPackage>(), | |
pricing = (from pr in db.Prices | |
where pr.partID.Equals(p.partID) | |
select new APIAttribute { key = pr.priceType, value = pr.price1.ToString() }).OrderBy(x => x.key).ToList<APIAttribute>(), | |
reviews = (from r in db.Reviews | |
where r.partID.Equals(p.partID) && ((customerID > 0) ? (r.cust_id.Equals(1) || r.cust_id.Equals(customerID)) : r.cust_id > 0) && r.active.Equals(true) && r.approved.Equals(true) | |
orderby r.createdDate descending | |
select new APIReview { reviewID = r.reviewID, partID = (r.partID != null) ? (int)r.partID : 0, rating = r.rating, subject = r.subject, review_text = r.review_text, email = r.email, name = r.name, createdDate = String.Format("{0:MM/dd/yyyy hh:mm tt}", r.createdDate) }).Take(10).ToList<APIReview>(), | |
averageReview = (from r in db.Reviews | |
where r.partID.Equals(p.partID) && r.active.Equals(true) && r.approved.Equals(true) | |
select (double?)r.rating).Average() ?? 0.0, | |
images = (from pi in db.PartImages | |
where pi.partID.Equals(p.partID) | |
select new APIImage { | |
imageID = pi.imageID, | |
sort = pi.sort, | |
path = pi.path, | |
height = pi.height, | |
width = pi.width, | |
size = db.PartImageSizes.Where(x => x.sizeID.Equals(pi.sizeID)).Select(x => x.size).FirstOrDefault<string>(), | |
partID = pi.partID | |
}).OrderBy(x => x.sort).ToList<APIImage>() | |
}).Distinct().Take(count).ToList<APIPart>(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment