public HttpResponseMessage getCampaignInfo(DTOFiterGetCampaignRequst request) { var filter = request.getFilter(); using (var db = new KOCSAMADLSEntities(false)) { if (request.isCategoryFilter()) { return(Request.CreateResponse(HttpStatusCode.OK, db.campaigns.SqlQuery(filter.getFilterSQL()).Select(tt => new { tt.category }).Distinct().OrderBy(t => t.category).ToList(), "application/json")); } else if (request.isSubcategoryFilter()) { return(Request.CreateResponse(HttpStatusCode.OK, db.campaigns.SqlQuery(filter.getFilterSQL()).Select(tt => new { tt.subcategory }).Distinct().OrderBy(t => t.subcategory).ToList(), "application/json")); } else if (request.isCampaignFilter()) { return(Request.CreateResponse(HttpStatusCode.OK, db.campaigns.SqlQuery(filter.getFilterSQL()).Select(tt => new { tt.name, tt.id }).OrderBy(t => t.name).ToList(), "application/json")); } else { var cids = db.campaigns.SqlQuery(filter.getFilterSQL()).Select(s => s.id).ToList(); var pids = db.vcampaignproducts.Where(v => cids.Contains(v.cid)).Select(s => s.pid).ToList(); return(Request.CreateResponse(HttpStatusCode.OK, db.product_service.Where(pp => pids.Contains(pp.productid)).OrderBy(s => s.category).ToList().GroupBy(g => g.category, g => g.toDTO()).Select(g => new { category = g.Key, products = g }) , "application/json")); // return Request.CreateResponse(HttpStatusCode.OK, db.campaigns.SqlQuery(filter.getFilterSQL()).Select(tt => new { tt.name, tt.id }).OrderBy(t => t.name).ToList(), "application/json");//silinecek } } }
public HttpResponseMessage getCampaignInfo(DTOFiterGetCampaignRequst request) { var filter = request.getFilter(); filter.fieldFilters.Add(new DTOFieldFilter { fieldName = "deleted", value = 0, op = 2 }); using (var db = new CRMEntities()) { //var p = db.campaigns.Where(c => c.id == 6080).FirstOrDefault(); //List<int> productids = new List<int>(); //foreach (var item in p.products.Split(',').ToList()) //{ // productids.Add(Convert.ToInt32(item)); //} //var products = db.product_service.Where(pp => productids.Contains(pp.productid)).ToList(); //return Request.CreateResponse(HttpStatusCode.OK, products.Select(s => new {s.productname,s.productid }), "application/json"); if (request.isCategoryFilter()) { return(Request.CreateResponse(HttpStatusCode.OK, db.campaigns.SqlQuery(filter.getFilterSQL()).Select(tt => new { tt.category }).Distinct().OrderBy(t => t.category).ToList(), "application/json")); } else if (request.isSubcategoryFilter()) { return(Request.CreateResponse(HttpStatusCode.OK, db.campaigns.SqlQuery(filter.getFilterSQL()).Select(tt => new { tt.subcategory }).Distinct().OrderBy(t => t.subcategory).ToList(), "application/json")); } else if (request.isCampaignFilter()) { return(Request.CreateResponse(HttpStatusCode.OK, db.campaigns.SqlQuery(filter.getFilterSQL()).Select(tt => new { tt.name, tt.id }).OrderBy(t => t.name).ToList(), "application/json")); } else { var cids = db.campaigns.SqlQuery(filter.getFilterSQL()).Select(s => s.id).ToList(); var pids = db.vcampaignproducts.Where(v => cids.Contains(v.cid)).Select(s => s.pid).ToList(); return(Request.CreateResponse(HttpStatusCode.OK, db.product_service.Where(p => pids.Contains(p.productid)).OrderBy(s => s.category).ToList().GroupBy(g => g.category, g => g.toDTO()).Select(g => new { category = g.Key, products = g }) , "application/json")); } } }