using Ant.Core.SqlServer; using Ant.Core.Utils; using Ant.Core.WebApi.Model; using Central.Control.WebApi.Cache; using Central.Control.WebApi.DbEntity; using Central.Control.WebApi.EFDbContext; using Central.Control.WebApi.Enum; using Central.Control.WebApi.Models.Response; using Central.Control.WebApi.Service.Interface; using Microsoft.Extensions.Caching.Memory; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Web; namespace Central.Control.WebApi.Service { /// /// /// public class ProductService: IProductService { /// /// /// public readonly static string ImagePrefix = ConfigurationManager.AppSettings["ImagePrefix"].ToString(); private readonly ICacheHelper _cacheHelper; private readonly IDbContext _dbContent; /// /// /// /// public ProductService( ICacheHelper cacheHelper, IDbContext dbContent) { _cacheHelper = cacheHelper; _dbContent = dbContent; } /// /// /// /// public ApiResult Test() { var ww = _dbContent.Set().FirstOrDefault(p => p.Id == "cb8b354c-b713-4dd7-9752-a6f3217004a0"); if (ww != null) { ww.Name = ww.Name + "1"; } _dbContent.SaveChanges(); _cacheHelper.Set("test01", "95990934"); var ss = _cacheHelper.Get("test01"); _cacheHelper.Set("test02", new Test001() { Id = Guid.NewGuid().ToString(), Token = "998097" }); var ss1 = _cacheHelper.Get("test02"); return new ApiResult("查库得到数据:" + ww?.Name ?? "nodata"); } /// /// 商品列表 /// /// /// /// /// public PagedApiResult Query(string kw = "", int skip = 0, int limit = 1) { var query = _dbContent.Set().Where(p => p.IsDelete == 0 && p.Sale == SaleEnum.On); // kw搜索 query = query.WhereIf(!string.IsNullOrWhiteSpace(kw), p => p.Name.Contains(kw)); // total var total = query.Count(); // 查询结果 var queryResult = query.OrderByDescending(p => p.CreateDT).Skip(skip).Take(limit).ToList(); List result = new List(); queryResult.ForEach(item => { var current = SafeClone.Trans(item); // 图片转换TODO current.Img = $"{ImagePrefix}{current.Img}"; result.Add(current); }); return new PagedApiResult(result, total, skip, limit); } } public class Test001 { public string Id { set; get; } public string Token { set; get; } } }