public ActionResult GetExtends(ExtendSearchDTO req) { int total = 0; var list = ExtendRepository.GetList(out total, req); return(Json(new { rows = list, total = total }, JsonRequestBehavior.AllowGet)); }
public ActionResult GetExtends(ExtendSearchDTO req) { if (req.ListType == 1) { req.offset = (req.offset - 1) * req.limit; } var list = _extendRepository.GetList(out int total, req); return(Json(new { rows = list, total = total, code = 0, msg = "" }, JsonRequestBehavior.AllowGet)); }
public List <ExtendListDTO> GetList(out int total, ExtendSearchDTO req) { var companyId = OperatorProvider.Provider.GetCurrent().CompanyId.ToInt(); using (var db = new SqlSugarClient(Connection)) { int totalCount = 0; string order = string.Empty; List <ExtendListDTO> list = new List <ExtendListDTO>(); var data = db.Sqlable() .From <R_ProjectExtend>("s1") .Join <R_ProjectExtendType>("s2", "s2.IsDelete = 0 and s1.R_ProjectExtendType_Id", "s2.Id", JoinType.Left) .Where(" s1.IsDelete = 0 "); data = data.Where("s1.R_Company_Id=" + companyId); if (req.CyxmKzType > 0) { data = data.Where("s1.CyxmKzType =" + req.CyxmKzType); } if (req.MinPrice > 0) { data = data.Where("s1.Price >=" + req.MinPrice); } if (req.MaxPrice > 0) { data = data.Where("s1.Price <=" + req.MaxPrice); } 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); } } totalCount = data.Count(); data.SelectToPageList <ExtendListDTO>( "s1.*,s2.Id as ExtendTypeId,s2.Name as ExtendType", order, (req.offset / req.limit) + 1, req.limit, null).ForEach(p => { list.Add(new ExtendListDTO() { Id = p.Id, CyxmKzType = Enum.GetName(typeof(CyxmKzType), int.Parse(p.CyxmKzType)), CyxmKzTypeId = int.Parse(p.CyxmKzType), Description = p.Description, Name = p.Name, Price = p.Price, Unit = p.Unit, ExtendTypeId = p.ExtendTypeId, ExtendType = p.ExtendType }); }); total = totalCount; return(list); } }