public HttpResponseMessage getCampaigns(DTOFiterGetCampaignRequst request)
        {
            using (var db = new CRMEntities())
            {
                var filter = request.getFilter();
                filter.fieldFilters.Add(new DTOFieldFilter {
                    fieldName = "deleted", value = 0, op = 2
                });
                var countSql = filter.getCountSQL();
                var rowCount = db.Database.SqlQuery <int>(countSql).First();
                var querySql = filter.getPagingSQL(request.pageNo, request.rowsPerPage);
                var res      = db.campaigns.SqlQuery(querySql).ToList();
                DTOResponsePagingInfo paginginfo = new DTOResponsePagingInfo
                {
                    pageCount     = (int)Math.Ceiling(rowCount * 1.0 / request.rowsPerPage),
                    pageNo        = request.pageNo,
                    rowsPerPage   = request.rowsPerPage,
                    totalRowCount = rowCount
                };

                return(Request.CreateResponse(HttpStatusCode.OK,
                                              new DTOPagedResponse(DTOResponseError.NoError(), res.Where(r => r.deleted == false).Select(r => r.toDTO()).ToList(), paginginfo, querySql)
                                              , "application/json"));
            }
        }
        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
                }
            }
        }
Esempio n. 3
0
        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"));
                }
            }
        }