public ActionResult GetDiscounts(DiscountSearchDTO req) { int total = 0; var list = DiscountRepository.GetList(out total, req); return(Json(new { rows = list, total = total }, JsonRequestBehavior.AllowGet)); }
public List <DiscountDTO> GetList(out int total, DiscountSearchDTO req) { var companyId = OperatorProvider.Provider.GetCurrent().CompanyId.ToInt(); using (var db = new SqlSugarClient(Connection)) { string order = "s1.Id desc"; var data = db.Sqlable() .From <R_Discount>("s1") .Join <R_Restaurant>("s2", "s2.IsDelete = 0 and s1.R_Restaurant_Id", "s2.Id", JoinType.Left) .Join <R_Market>("s3", "s3.IsDelete = 0 and s1.R_Market_Id", "s3.Id", JoinType.Left) .Join <R_Area>("s4", " s4.IsDelete = 0 and s1.R_Area_Id", "s4.Id", JoinType.Left) .Where(" s1.IsDelete = 0 "); data = data.Where("s1.R_Company_Id=" + companyId); if (!string.IsNullOrEmpty(req.Name)) { data = data.Where("s1.Name like '%" + req.Name + "%'"); } if (req.Restaurant > 0) { data = data.Where("s2.Id=" + req.Restaurant); } if (!string.IsNullOrEmpty(req.StartDate)) { data = data.Where("s1.StartDate>='" + req.StartDate + "'"); } if (!string.IsNullOrEmpty(req.EndDate)) { data = data.Where("s1.EndDate<='" + req.EndDate + "'"); } if (!string.IsNullOrEmpty(req.Sort)) { if (req.Sort.Equals("id", StringComparison.OrdinalIgnoreCase)) { order = "s1.Id desc"; } else { order = string.Format("{0} {1}", req.Sort, req.Order); } } total = data.Count(); List <DiscountDTO> list = data.SelectToPageList <DiscountDTO>( @"s1.Id,s1.Name,s3.Name as Market,s2.Name as Restaurant, s4.Name as Area,s1.IsEnable,s1.StartDate,s1.EndDate", order, (req.offset / req.limit) + 1, req.limit, null); return(list); } }
public ActionResult GetDiscounts(DiscountSearchDTO req) { if (req.ListType == 1) { req.offset = (req.offset - 1) * req.limit; } var list = _discountRepository.GetList(out int total, req); return(Json(new { rows = list, total = total, code = 0, msg = "" }, JsonRequestBehavior.AllowGet)); }