public async Task SeedAsync(DataSeedContext context) { if (await _productTypeRepository.GetCountAsync() == 0) { await _productTypeRepository.InsertAsync(new ProductType(_guidGenerator.Create(), ProductsConsts.DefaultProductType, "Default", null, MultiTenancySides.Both), true); } }
/// <summary> /// 配置产品类型 /// </summary> /// <param name="productTypeCode"></param> /// <param name="productTypeName"></param> /// <returns></returns> public async Task <int> ConfigureProductType(string productTypeCode, string productTypeName, List <ProductOption> productOptions) { var pt = await _productTypeRepository.FirstOrDefaultAsync(e => e.Prot_Name == productTypeName); if (pt != null) { return(-1); } var productType = new CrmProductType() { Prot_Code = productTypeCode, Prot_Name = productTypeName, Prot_CreatedBy = 1, Prot_CreatedDate = DateTime.Now, Prot_UpdatedBy = 1, Prot_UpdatedDate = DateTime.Now, Prot_Deleted = 0, Prot_ClassRule = 0, Prot_IsClassInsert = 1, Prot_IsBundle = 1, Prot_SaleRule = 0, Prot_SyncSys = "MTS", }; List <CrmCaption> captions = await _captionRepository.Where(e => e.Capt_Family == "Clas_PeriodType" || e.Capt_Family == "Clas_ScaleType" || e.Capt_Family == "Clas_TeacherType").ToListAsync(); foreach (var po in productOptions) { int?periodTypeId = captions.FirstOrDefault(e => e.Capt_CS == po.Clas_PeriodType)?.Capt_Order; int?scaleTypeId = captions.FirstOrDefault(e => e.Capt_CS == po.Clas_ScaleType)?.Capt_Order; int?teacherTypeId = captions.FirstOrDefault(e => e.Capt_CS == po.Clas_TeacherType)?.Capt_Order; productType.ProductSubTypes.Add(new CrmProductSubType() { Clas_PeriodType = periodTypeId, Clas_ScaleType = scaleTypeId, Clas_TeacherType = teacherTypeId, Prost_Name = $"{po.Clas_PeriodType}-{po.Clas_ScaleType}-{po.Clas_TeacherType}", Prost_CreatedBy = 1, Prost_CreatedDate = DateTime.Now }); } await _productTypeRepository.InsertAsync(productType); await _uow.SaveChangesAsync(); return(productType.Prot_ID); }