/// <summary> /// 提交表单 /// </summary> protected override object OnSubmit(Product saveTo) { // 基本信息 var classManager = Application.Ioc.Resolve <GenericClassManager>(); var tagManager = Application.Ioc.Resolve <GenericTagManager>(); var userManager = Application.Ioc.Resolve <UserManager>(); saveTo.Name = Name; saveTo.Type = Type; saveTo.State = State; saveTo.DisplayOrder = DisplayOrder; saveTo.Classes = new HashSet <GenericClass>(classManager.GetMany(c => ProductClass.Contains(c.Id))); saveTo.Tags = new HashSet <GenericTag>(tagManager.GetMany(t => ProductTag.Contains(t.Id))); saveTo.Seller = Seller == null ? null : userManager.Get(u => u.Username == Seller); saveTo.Remark = Remark; if (saveTo.Seller == null && !string.IsNullOrEmpty(Seller)) { throw new NotFoundException(new T("Seller username not exist")); } // 属性规格 var categoryManager = Application.Ioc.Resolve <ProductCategoryManager>(); saveTo.Category = Category == null ? null : categoryManager.Get(Category.Value); saveTo.PropertyValues.Clear(); saveTo.PropertyValues.AddRange(PropertyValues.ToDatabaseSet(saveTo)); // 价格库存 saveTo.MatchedDatas.Clear(); saveTo.MatchedDatas.AddRange(MatchedDatas.ToDatabaseSet(saveTo)); // 商品介绍 saveTo.Introduction = Introduction; // 编辑后清除商品管理器的缓存 Application.Ioc.Resolve <ProductManager>().ClearCache(); return(this.SaveSuccessAndCloseModal()); }
/// <summary> /// 提交表单 /// </summary> protected override object OnSubmit(IDatabaseContext context, Database.Product saveTo) { // 基本信息 if (saveTo.Id <= 0) { saveTo.CreateTime = DateTime.UtcNow; } saveTo.Name = Name; saveTo.Type = Type; saveTo.State = State; saveTo.DisplayOrder = DisplayOrder; var classRepository = RepositoryResolver.Resolve <GenericClass>(context); var tagRepository = RepositoryResolver.Resolve <GenericTag>(context); saveTo.Classes = new HashSet <GenericClass>(classRepository.GetMany(c => ProductClass.Contains(c.Id))); saveTo.Tags = new HashSet <GenericTag>(tagRepository.GetMany(t => ProductTag.Contains(t.Id))); saveTo.Seller = Seller == null ? null : context.Get <User>(u => u.Username == Seller); saveTo.Remark = Remark; saveTo.LastUpdated = DateTime.UtcNow; if (saveTo.Seller == null && !string.IsNullOrEmpty(Seller)) { throw new NotFoundException(new T("Seller username not exist")); } // 属性规格 var categoryRepository = RepositoryResolver.Resolve <ProductCategory>(context); saveTo.Category = Category == null ? null : categoryRepository.GetById(Category); saveTo.PropertyValues.Clear(); saveTo.PropertyValues.AddRange(PropertyValues.ToDatabaseSet(saveTo)); // 价格库存 saveTo.MatchedDatas.Clear(); saveTo.MatchedDatas.AddRange(MatchedDatas.ToDatabaseSet(saveTo)); // 商品介绍 saveTo.Introduction = Introduction; // 编辑后清除商品管理器的缓存 Application.Ioc.Resolve <ProductManager>().ClearCache(); return(new { message = new T("Saved Successfully"), script = ScriptStrings.AjaxtableUpdatedAndCloseModal }); }