public async Task <GetProductOutput> GetProductAsync(GetProductInput input) { if (input.Id == 0) { throw new UserFriendlyException("خطا در دریافت اطلاعات"); } var pc = _productRepo.GetAll() .SingleOrDefault(p => p.Id == input.Id); if (pc == null) { throw new UserFriendlyException("آیتم مورد نظر وجود ندارد ویا حذف شده است !!!"); } return(new GetProductOutput() { P = new ProductDto() { Id = pc.Id, CreationTime = pc.CreationTime.ToString(), Description = pc.Description, Name = pc.Name, EnDescription = pc.EnDescription, EnName = pc.EnName, } }); }
/// <summary> /// 根据查询条件获取产品信息分页列表 /// </summary> public async Task <PagedResultDto <ProductListDto> > GetPagedProductsAsync(GetProductInput input) { var query = _productRepositoryAsNoTrack; //TODO:根据传入的参数添加过滤条件 query = query.WhereIf(input.CategoryId > 0, p => p.CategoryId == input.CategoryId) .WhereIf(!string.IsNullOrEmpty(input.FilterText), p => p.Title.Contains(input.FilterText)) .WhereIf(input.Id != null, p => p.Id == input.Id) .WhereIf(input.Status != null, p => p.IsShow == input.Status) .WhereIf(input.BeginDate != null, p => p.CreationTime >= input.BeginDate) .WhereIf(input.EndDate != null, p => p.CreationTime <= input.EndDate); var productCount = await query.CountAsync(); var products = await query .OrderByDescending(p => p.CreationTime) .PageBy(input) .ToListAsync(); var productListDtos = products.MapTo <List <ProductListDto> >(); return(new PagedResultDto <ProductListDto>( productCount, productListDtos )); }
public async Task <ContentResult> Delete(GetProductInput input) { ReturnMessage rm = new ReturnMessage(1, "Success"); try { var products = await Task.Run(() => _unitOfWork.Products.GetAsync(filter: e => e.Id == input.Id)); if (products.Count() == 0) { rm.msgCode = -1; rm.msg = "Not Found"; } else { _unitOfWork.Products.Remove(products.First()); _unitOfWork.Complete(); } _logger.LogInformation("Log:Delete Product for ID: {Id}", input.Id); return(this.Content(rm.returnMessage(null), "application/json")); } catch (Exception ex) { rm.msg = ex.Message.ToString(); rm.msgCode = 0; return(this.Content(rm.returnMessage(null))); } }
public async Task <IActionResult> Index(GetProductInput input) { var dto = await _productAppService.GetPagedProductAsync(input); ViewBag.Category = await _categoryAppService.GetAllCategoryAsync(); return(View(dto)); }
public ProductOutput GetProduct(GetProductInput input) { var product = _productManager.GetProduct(input.Id); var result = ObjectMapper.Map <ProductOutput>(product); return(result); }
/// <summary> /// 获取商品分页数据 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <PagedResultDto <ProductListDto> > GetPagedProductAsync(GetProductInput input) { var query = _productRepository.GetAllIncluding(p => p.Category); var productCount = await query.CountAsync(); var products = await query.OrderBy(input.Sorting).PageBy(input).ToListAsync(); var dtos = products.MapTo <List <ProductListDto> >(); return(new PagedResultDto <ProductListDto>(productCount, dtos)); }
public async Task <PagedResultDto <ProductListDto> > GetPagedProductAsync(GetProductInput input) { //var roles = await _productRepository.GetAllListAsync(); //return new PagedResultDto<ProductListDto>(1,ObjectMapper.Map<List<ProductListDto>>(roles)); var query = _productRepository.GetAll(); var productCount = await query.CountAsync(); var product = await query.OrderBy(input.Sorting).PageBy(input).ToListAsync(); var dtos = product.MapTo <List <ProductListDto> >(); return(new PagedResultDto <ProductListDto>(productCount, dtos)); }
public async Task <ValidationResult> ValidateGetProduct(GetProductInput input) { ValidationResult validationResult = new(); Product product = await _productRepository.GetAsync(input.Id); if (product is null) { validationResult.Messages.Add(new(nameof(GetProductInput.Id), "El producto no existe.")); } return(validationResult); }
public JsonResult GetDataPager(DataTableSearchModel searchInput) { if (searchInput.ActionType == "group_action") { if (string.IsNullOrEmpty(searchInput.CustomActionValue) || searchInput.id == null || searchInput.id.Count == 0) { return(Json(new { actionType = searchInput.ActionType, customActionStatus = false, customActionMsg = "无效参数" })); } try { _productAppService.BatchUpdateStatusAsync(searchInput.id, bool.Parse(searchInput.CustomActionValue)); return(Json(new { actionType = searchInput.ActionType, customActionStatus = true, customActionMsg = "" })); } catch (Exception e) { return(Json(new { actionType = searchInput.ActionType, customActionStatus = false, customActionMsg = "无效参数" })); } } int pageIndex = 0; GetProductInput defaultInput = new GetProductInput() { MaxResultCount = CarFactoryConsts.MaxPageSize, SkipCount = pageIndex * CarFactoryConsts.MaxPageSize, Sorting = "CreationTime", Page = pageIndex + 1 }; if (searchInput != null && searchInput.ActionType == "filter") { defaultInput.Id = searchInput.FilterId; defaultInput.BeginDate = searchInput.FilterDateFrom; defaultInput.EndDate = searchInput.FilterDateTo; defaultInput.FilterText = searchInput.FilterName ?? ""; defaultInput.Status = searchInput.FilterStatus; } var list = _productAppService.GetPagedProductsAsync(defaultInput).Result; var pagedProducts = new StaticPagedList <ProductListDto>(list.Items, defaultInput.Page.Value, defaultInput.MaxResultCount, list.TotalCount); var viewModelList = GenerateTablePagerData(pagedProducts, "/admin/products/detail/"); return(Json(new { draw = Request.Form["draw"], recordsTotal = pagedProducts.TotalItemCount, recordsFiltered = pagedProducts.Count, data = viewModelList }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 根据查询条件获取产品表分页列表 /// </summary> public async Task <PagedResultDto <ProductListDto> > GetPagedProductsAsync(GetProductInput input) { try { var query = _productRepositoryAsNoTrack; //TODO:根据传入的参数添加过滤条件 query = query.WhereIf(input.CompanyId > 0, c => c.CompanyId == input.CompanyId) .WhereIf(!string.IsNullOrEmpty(input.CompanyName), c => c.Company.CompanyName.Contains(input.CompanyName)) .WhereIf(input.Id > 0, c => c.Id == input.Id) .WhereIf(!string.IsNullOrEmpty(input.Title), c => c.Detail.Contains(input.Title)) .WhereIf(input.CategoryId > 0, c => c.CategoryId == input.CategoryId) .WhereIf(input.VerifyStatus != VerifyStatus.Invalid, c => c.VerifyStatus == input.VerifyStatus) .WhereIf(input.ReleaseStatus != ReleaseStatus.Invalid, c => c.ReleaseStatus == input.ReleaseStatus) .WhereIf(input.FromTime != null, c => c.CreationTime >= input.FromTime) .WhereIf(input.EndTime != null, c => c.CreationTime <= input.EndTime); var productCount = await query.CountAsync(); switch (input.Sorting.ToLower()) { case "creationtime": query = query.OrderByDescending(c => c.CreationTime); break; case "id": query = query.OrderByDescending(c => c.Id); break; default: query = query.OrderBy(input.Sorting); break; } var products = await query .PageBy(input) .ToListAsync(); var productListDtos = products.MapTo <List <ProductListDto> >(); return(new PagedResultDto <ProductListDto>( productCount, productListDtos )); } catch (Exception e) { Console.WriteLine(e); throw; } }
public List <ProductListDto> GetProducts(GetProductInput input) { var query = _productRepository .GetAll() .WhereIf( !input.Filter.IsNullOrEmpty(), p => p.Id.ToString().Contains(input.Filter) || p.Code.Contains(input.Filter) || p.Name.Contains(input.Filter) || p.Description.Contains(input.Filter) ) .OrderBy(p => p.CreationTime) .ThenBy(p => p.Name) .ToList(); return(new List <ProductListDto>(query.MapTo <List <ProductListDto> >())); }
/// <summary> /// 根据查询条件获取商品管理分页列表 /// </summary> public async Task<PagedResultDto<ProductListDto>> GetPagedProductsAsync(GetProductInput input) { var query = ProductRepositoryAsNoTrack; query = query.WhereIf(!input.Num.IsNullOrWhiteSpace(), c => c.ProductNum.Contains(input.Num)) .WhereIf(!input.Name.IsNullOrWhiteSpace(), c => c.ProductName.Contains(input.Name)); var productCount = await query.CountAsync(); var products = await query .OrderBy(input.Sorting) .PageBy(input) .ToListAsync(); var productListDtos = products.MapTo<List<ProductListDto>>(); return new PagedResultDto<ProductListDto>( productCount, productListDtos ); }
/// <summary> /// 根据查询条件获取产品分页列表 /// </summary> public async Task <PagedResultDto <ProductListDto> > GetPagedProductsAsync(GetProductInput input) { var query = _productRepository.GetAll(); //TODO:根据传入的参数添加过滤条件 var productCount = await query.CountAsync(); var products = await query .OrderBy(input.Sorting) .PageBy(input) .ToListAsync(); var productListDtos = products.MapTo <List <ProductListDto> >(); return(new PagedResultDto <ProductListDto>( productCount, productListDtos )); }
public async Task <PagedResultDto <ProductListDto> > GetProduct(GetProductInput input) { using (_unitOfWorkManager.Current.SetTenantId(_session.TenantId)) { var Product = _ProductRepository.GetAll() .WhereIf( !input.Filter.IsNullOrEmpty(), p => p.ProductCode.Contains(input.Filter) || p.ProductName.Contains(input.Filter) || p.ProductSubGroup.ProductSubGroupName.ToString().Contains(input.Filter) || p.ProductSubGroup.productGroups.ProductGroupName.ToString().Contains(input.Filter) ); var data = (from r in Product select new ProductListDto { Id = r.Id, ProductCode = r.ProductCode, ProductName = r.ProductName, Description = r.Description, Discontinued = r.Discontinued, ProductSubGroupId = r.ProductSubGroupId, ProductSubGroupName = r.ProductSubGroup.ProductSubGroupName, ProducGroupId = r.ProductSubGroup.ProductGroupId, ProductGroupName = r.ProductSubGroup.productGroups.ProductGroupName, Path = r.Path }); var Count = await data.CountAsync(); var datalist = await data .OrderBy(input.Sorting) .PageBy(input) .ToListAsync(); var ProductListDtos = datalist.MapTo <List <ProductListDto> >(); return(new PagedResultDto <ProductListDto>(Count, ProductListDtos)); } }
public async Task <PartialViewResult> PartialProducts() { GetProductInput defaultInput = new GetProductInput() { Status = true, MaxResultCount = CarFactoryConsts.MaxPageSize, Page = 1, SkipCount = 0 }; var products = await _productAppService.GetPagedProductsAsync(defaultInput); var categoryList = await _categoryAppService.GetCategorysOnShowAsync(); foreach (CategoryListDto dto in categoryList) { var filterProducts = products.Items.Where(p => p.CategoryId == dto.Id).Take(5).ToList(); dto.Products = filterProducts; } return(PartialView("PartialPages/Home/_PartialProducts", categoryList)); }
/// <summary> /// 根据查询条件获取产品分页列表 /// </summary> public async Task <PagedResultDto <ProductListDto> > GetPagedProductsAsync(GetProductInput input) { var query = ProductRepositoryAsNoTrack; query = query.WhereIf(!input.Name.IsNullOrWhiteSpace(), c => c.ProductName.Contains(input.Name)) .WhereIf(input.State.HasValue, c => c.IsActive == input.State.Value) .WhereIf(input.LevelOne.HasValue, c => c.LevelOneId == input.LevelOne.Value) .WhereIf(input.LevelTwo.HasValue, c => c.LevelTwoId == input.LevelTwo.Value); var productCount = await query.CountAsync(); var products = await query .OrderBy(input.Sorting) .PageBy(input) .ToListAsync(); var productListDtos = products.MapTo <List <ProductListDto> >(); return(new PagedResultDto <ProductListDto>( productCount, productListDtos )); }
public async Task <ContentResult> GetAll(GetProductInput input) { try { ReturnMessage rm = new ReturnMessage(1, "Success"); var products = await Task.Run(() => _unitOfWork.Products.GetAsync(filter: e => input.Id != 0 ? (e.Id == input.Id) : true)); var productsToReturn = _mapper.Map <IEnumerable <ProductDto> >(products); return(this.Content(rm.returnMessage(new PagedResultDto <ProductDto> (productsToReturn.AsQueryable(), input.pagenumber, input.pagesize)), "application/json")); } catch (Exception ex) { return(this.Content(JsonConvert.SerializeObject(new { // 0 is Exception msgCode = 0, msg = ex.Message }), "application/json")); } }
public ActionResult List(int?page, string shortName = "") { CategoryListDto activeCategory = null; int pageIndex = ((page != null && page.Value >= 1) ? page.Value : 1) - 1; var categoryList = _categoryAppService.GetCategorysOnShowAsync().Result; activeCategory = categoryList.FirstOrDefault(); ViewBag.ActiveCategory = activeCategory; if (!string.IsNullOrEmpty(shortName)) { var tempCategory = categoryList.FirstOrDefault(c => c.ShortName == shortName); if (tempCategory != null) { ViewBag.ActiveCategory = tempCategory; activeCategory = tempCategory; } } GetProductInput pagedInput = new GetProductInput() { CategoryId = activeCategory.Id, Sorting = "CreationTime" }; pagedInput.SkipCount = pageIndex * pagedInput.MaxResultCount; var products = _productAppService.GetPagedProductsAsync(pagedInput).Result; var pagedProducts = new StaticPagedList <ProductListDto>(products.Items, pageIndex + 1, pagedInput.MaxResultCount, products.TotalCount); ViewBag.SeoSetting = GetSeoSetting(); return(View(pagedProducts)); }
// GET: /<controller>/ public async Task <ActionResult> Index(GetProductInput input) { var dots = await _productAppService.GetPagedProductAsync(input); return(View(dots)); }
public async Task <PagedResultDto <ProductList> > GetProduct(GetProductInput input) { var query = _productRepository.GetAll(); query = query .Include(u => u.ProductSpecifications) .WhereIf( !input.Filter.IsNullOrEmpty(), p => p.ProductCode.Contains(input.Filter) || p.SuspectCode.Contains(input.Filter) || p.Gpcode.Contains(input.Filter) || p.ProductSpecifications.Name.Contains(input.Filter) ); var productCount = await query.CountAsync(); var product = from a in query join ur in UserManager.Users on a.CreatorUserId equals ur.Id select new ProductList { Id = a.Id, ProductCode = a.ProductCode, ProductName = a.ProductName, SuspectCode = a.SuspectCode, Gpcode = a.Gpcode, Description = a.Description, ProductSpecificationId = a.ProductSpecificationId, ProductSpecificationName = a.ProductSpecificationId > 0 ? a.ProductSpecifications.Name : "", Price = a.Price, ScreationTime = a.CreationTime.ToString(), DCreationTime = a.CreationTime, Width = a.Width, Height = a.Height, Depth = a.Depth, Dimention = "", RefId = a.RefId, ProductStateId = a.ProductStateId, ProductState = a.ProductState.Name, BafcoMade = a.ProductSpecificationId > 0 ? a.ProductSpecifications.BafcoMade : false, CategoryName = a.ProductSpecificationId > 0 ? (a.ProductSpecifications.ProductGroups.ProductCategoryId > 0 ? a.ProductSpecifications.ProductGroups.ProductCategorys.Name : "") : "", CreatedBy = ur != null ? ur.UserName : "", CreatorUserId = a.CreatorUserId ?? 0, LastModifierUserId = a.LastModifierUserId ?? 0, LastModifiedBy = a.LastModifierUserId != null ? (from l in UserManager.Users where l.Id == a.LastModifierUserId select l.UserName).FirstOrDefault() : "", }; var productlt = await product .OrderByDescending(p => p.DCreationTime) .PageBy(input) .ToListAsync(); if (input.Sorting != "ProductCode,ProductSpecificationName,SuspectCode,Gpcode,Price,CategoryName,BafcoMade") { productlt = await product .OrderBy(input.Sorting) .PageBy(input) .ToListAsync(); } var productlistoutput = productlt.MapTo <List <ProductList> >(); foreach (var data in productlistoutput) { var width = ""; var depth = ""; var height = ""; if (data.Width > 0) { width = data.Width.ToString() + " - "; } if (data.Depth > 0) { depth = data.Depth.ToString() + " - "; } if (data.Height > 0) { height = data.Height.ToString(); } data.Dimention = width + "" + depth + "" + height; var quotaion = _quotationProductRepository.GetAll().Where(p => p.ProductId == data.Id).FirstOrDefault(); if (quotaion != null) { data.IsQuotation = true; } if (data.RefId > 0) { var pro = _productRepository.GetAll().Where(p => p.Id == data.RefId).Select(x => x.ProductSpecifications).FirstOrDefault(); data.BafcoMade = pro != null ? pro.BafcoMade : false; data.CategoryName = pro.ProductGroups.ProductCategorys.Name ?? ""; } } return(new PagedResultDto <ProductList>(productCount, productlistoutput)); }