public ActionResult GetCategorys(CategorySearchDTO req) { int total = 0; var list = CategoryRepository.GetList(out total, req); return(Json(new { rows = list, total = total }, JsonRequestBehavior.AllowGet)); }
public List <CategoryListDTO> GetList(out int total, CategorySearchDTO req) { var companyId = OperatorProvider.Provider.GetCurrent().CompanyId.ToInt(); using (var db = new SqlSugarClient(Connection)) { int totalCount = 0; string order = "s1.Id desc"; List <CategoryListDTO> list = new List <CategoryListDTO>(); 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); } } var data = db.Queryable <R_Category>() .JoinTable <R_Category>((s1, s2) => s1.PId == s2.Id && s2.IsDelete == false && s1.R_Company_Id == companyId) .Select("s1.*,s2.Name as Pname") .Where(" s1.IsDelete = 0 "); //.OrderBy(order).ToDataTable(); if (req.Pid > 0) { data = data.Where("s1.Pid=" + req.Pid); } var _data = data.OrderBy(order).ToDataTable(); if (data != null && _data.Rows.Count > 0) { totalCount = _data.Rows.Count; var rows = _data.Rows.Cast <DataRow>(); var curRows = rows.Skip(req.offset).Take(req.limit).ToArray(); foreach (DataRow item in curRows) { list.Add(new CategoryListDTO() { Id = Convert.ToInt32(item["id"]), Name = item["Name"].ToString(), Description = item["Description"].ToString(), DiscountRate = Convert.ToDecimal(item["DiscountRate"]), Pid = Convert.ToInt32(item["Pid"]), Pname = item["Pname"].ToString(), IsDiscount = Convert.ToBoolean(item["IsDiscount"]) }); } } total = totalCount; return(list); } }
public async Task <List <CategoryDTO> > SearchAsync(CategorySearchDTO categorySearchDTO) { Preconditions.NotNull(categorySearchDTO, nameof(categorySearchDTO)); var categories = await _categoryRepository.GetAllWithReferences(); if (!string.IsNullOrWhiteSpace(categorySearchDTO.Name)) { categories = categories.Where(c => c.Name.Contains(categorySearchDTO.Name, StringComparison.OrdinalIgnoreCase)); } categories = categorySearchDTO.SortOrder == SortOrder.Descending ? OrderByDescending(categories, categorySearchDTO.CategoryOrderBy) : OrderByAscending(categories, categorySearchDTO.CategoryOrderBy); return(_mapper.Map <List <CategoryDTO> >(categories.ToList())); }
public ActionResult GetCategorys(CategorySearchDTO req) { if (req.ListType == 1) { req.offset = (req.offset - 1) * req.limit; } var list = _categoryRepository.GetList(out int total, req); return(NewtonSoftJson(new { rows = list, total = total, code = 0, msg = "" }, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult <List <CategoryDTO> > > Search([FromQuery] CategorySearchDTO categorySearchDTO) { return(await _categorySearchService.SearchAsync(categorySearchDTO)); }
public async Task <List <CategoryDTO> > SearchAsync(CategorySearchDTO categorySearchDTO) { return(await _httpService.GetHelperAsync <List <CategoryDTO> >($"{CategoryClientEndpoints.Search}?{categorySearchDTO.ToQueryString()}")); }