public void ImportCompanyProducts() { Logger.LogInformation($"Web job started."); var inputFilePath = Config["InputFilePath"]; var files = Directory.GetFiles(inputFilePath, "catalog*.csv"); foreach (var file in files) { var companyCode = file.Replace("catalog", "").Replace(inputFilePath, "").Replace(".csv", ""); using FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read); CompanyProductService.ImportCompanyProductsFromFileStream(new ImportCompanyProductRequest() { FileStream = fs, CompanyCode = companyCode }); } Logger.LogInformation($"Web job completed."); }
public ActionResult Detail() { int productId = CECRequest.GetQueryInt("id", 0); //根据产品ID获得公司信息 var productInfo = CompanyProductService.Get(productId); if (productInfo.Id == 0) { return(Redirect("/")); } //模板所用公司信息 var companyInfo = MemberService.GetCompanyInfo(productInfo.CompanyId); ViewBag.CompanyInfo = companyInfo; return(View("ProductDetail", productInfo)); }
public void ProductSkuNotFound() { // Assemble var request = TestData.GetCreateCompanyProductBarcodeRequest(); request.ProductSku = "ABC"; CompanyProductService.Setup(m => m.GetCompanyProduct(request.ProductSku, TestData.CompanyCodeA)).Returns((CompanyProduct)null); CompanyProductService.Setup(m => m.ValidateCompanyProductExist(request.ProductSku, TestData.CompanyCodeA)).Returns(new List <Error>() { new ProductSkuNotFoundError(request.ProductSku, request.CompanyCode) }); // Act var result = Subject.CreateCompanyProductBarcode(request); // Assert Assert.False(result.Success); Assert.Contains(typeof(ProductSkuNotFoundError), result.Errors.Where(m => m.Field == "ProductSku").Select(e => e.GetType()).ToList()); }
public ActionResult ProductList() { var companyInfo = MemberService.GetCompanyInfoByUserId(PlantEngContext.Current.UserId); if (CECRequest.GetQueryString("action").ToLower().Equals("delete")) { int id = CECRequest.GetQueryInt("id", 0); //如果是删除 CompanyProductService.Delete(id, companyInfo.CompanyId); } var pageIndex = CECRequest.GetQueryInt("page", 1); var list = CompanyProductService.List(new CompanyProductSearchSetting { PageIndex = pageIndex, CompanyId = companyInfo.CompanyId }); ViewBag.ProductList = list; return(View()); }
public ActionResult ProductEdit(CompanyProductInfo oldModel, FormCollection fc) { bool errors = false; bool isAdd = oldModel.Id == 0; var companyInfo = MemberService.GetCompanyInfoByUserId(PlantEngContext.Current.UserId); if (string.IsNullOrEmpty(oldModel.Title)) { errors = true; ModelState.AddModelError("TitleEmpty", "标题不能为空"); } if (string.IsNullOrEmpty(oldModel.Content)) { errors = true; ModelState.AddModelError("ContentEmpty", "内容不能为空"); } oldModel.SystemCategoryId = Utils.StrToInt(fc["syscat"], 0); if (oldModel.SystemCategoryId == 0) { errors = true; ModelState.AddModelError("SysCatEmpty", "请选择产品系统分类"); } //为了在更新的时候,判断新分类是否还是以前的分类,然后为更新新分类产品数做判断 int oldCatId = oldModel.CategoryId; oldModel.CategoryId = Utils.StrToInt(fc["cat"], 0); if (oldModel.CategoryId == 0) { errors = true; ModelState.AddModelError("CatEmpty", "请选择自定义分类"); } if (!errors && ModelState.IsValid) { oldModel.CompanyId = companyInfo.CompanyId; oldModel = CompanyProductService.Update(oldModel); if (isAdd) { //如果是添加,则更新产品分类表中的产品数 + 1 CompanyProductCategoryService.UpdateProductCount(oldModel.CategoryId, companyInfo.CompanyId, true); } else { //如果没有更改分类,则什么都不变 //否则则原来的分类的产品数-1,新分类产品数+ 1 if (oldCatId == oldModel.CategoryId) { //说明还是在原来的分类上更新 } else { //分类改变了 //原来的分类产品数 - 1 ,新分类数 + 1 CompanyProductCategoryService.UpdateProductCount(oldCatId, companyInfo.CompanyId, false); //新分类 + 1 CompanyProductCategoryService.UpdateProductCount(oldModel.CategoryId, companyInfo.CompanyId, true); } } ViewBag.Msg = "保存成功!"; } //产品分类 ViewBag.CategoryList = CompanyProductCategoryService.GetCategoryList(companyInfo.CompanyId); return(View(oldModel)); }