/// <summary> /// /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <PagedResultOutputDto <ProductOutput> > GetProductListAsync(GetProductListInput input) { var query = _productRepository.GetAll().Include(x => x.Category). WhereIf(!string.IsNullOrEmpty(input.Name), x => x.Name == input.Name) .WhereIf(input.CategoryId.HasValue, x => x.CategoryId == input.CategoryId.Value); var count = query.Count(); var result = await query.OrderBy(x => x.Sort).ThenByDescending(x => x.CreationTime).Skip(input.SkipCount).Take(input.PageCount).ToListAsync(); var reusltOut = result.MapTo <List <ProductOutput> >(); foreach (var producOutput in reusltOut) { var firstOrDefault = FileRelationRepository .GetAll().FirstOrDefault (x => x.KeyId == producOutput.Id && x.ModuleId == ModuleType.ProductMan); if (firstOrDefault != null) { producOutput.FileId = firstOrDefault .FileId; } } return(new PagedResultOutputDto <ProductOutput>(count, reusltOut)); }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task AddCategoryAsync(CategoryInput input) { var category = input.MapTo <Category>(); if (input.Id.HasValue) { category = _categoryRepository.Get(input.Id.Value); category.Description = input.Description; category.Name = input.Name; category.Sort = input.Sort; FileRelationRepository.Delete(x => x.KeyId == input.Id && x.ModuleId == ModuleType.Category); } else { await _categoryRepository.InsertAsync(category); CurrentUnitOfWork.SaveChanges(); } // await AddFileRelationAsync(input.FileId, category.Id, ModuleType.Category); }
/// <summary> /// 添加产品 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task AddProductAsync(ProductInput input) { var product = input.MapTo <Product>(); if (input.Id.HasValue) { product = _productRepository.Get(input.Id.Value); product.CategoryId = input.CategoryId; product.Description = input.Description; product.Name = input.Name; product.Package = input.Package; product.Sort = input.Sort; FileRelationRepository.Delete(x => x.KeyId == input.Id.Value && (x.ModuleId == ModuleType.ProductMan || x.ModuleId == ModuleType.ProductDetail)); } else { product = _productRepository.Insert(product); CurrentUnitOfWork.SaveChanges(); } await AddFileRelationAsync(input.ProductImage, product.Id, ModuleType.ProductMan); await AddFileRelationAsync(input.StyleImage, product.Id, ModuleType.ProductDetail); }