public ActionResult GetExtendTypes(ExtendTypeSearchDTO req) { if (req.ListType == 1) { req.offset = (req.offset - 1) * req.limit; } var list = _extendRepository.GetExtendTypeList(out int total, req); return(Json(new { rows = list, total = total, code = 0, msg = "" }, JsonRequestBehavior.AllowGet)); }
public List <ExtendTypeListDTO> GetExtendTypeList(out int total, ExtendTypeSearchDTO req) { var companyId = OperatorProvider.Provider.GetCurrent().CompanyId.ToInt(); using (var db = new SqlSugarClient(Connection)) { int totalCount = 0; string order = string.Empty; List <ExtendTypeListDTO> list = new List <ExtendTypeListDTO>(); var data = db.Queryable <R_ProjectExtendType>().Where(p => p.IsDelete == false && p.R_Company_Id == companyId); if (!string.IsNullOrWhiteSpace(req.Name)) { data = data.Where(p => p.Name.Contains(req.Name)); } if (!string.IsNullOrEmpty(req.Sort)) { order = string.Format("{0} {1}", req.Sort, req.Order); } else { order = "Id desc"; } totalCount = data.Count(); if (totalCount > 0) { data = data.OrderBy(order).Skip(req.offset).Take(req.limit); data.ToList().ForEach(p => { list.Add(new ExtendTypeListDTO() { Id = p.Id, Name = p.Name, R_Company_Id = p.R_Company_Id }); }); } total = totalCount; return(list); } }