private async Task UpdateAttribute(CreateOrUpdateAttributeInput input, EntityDto <long> output) { var attribute = await _productAttributeManager.GetByIdAsync(input.Id.Value); attribute.Name = input.Name; attribute.DisplayOrder = attribute.DisplayOrder; await _productAttributeManager.UpdateAsync(attribute); output.Id = attribute.Id; }
/// <summary> /// 创建或更新属性 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <EntityDto <long> > CreateOrUpdateAttribute(CreateOrUpdateAttributeInput input) { var output = new EntityDto <long>(); if (input.Id > 0) { await UpdateAttribute(input, output); } else { await CreateAttribute(input, output); } return(output); }
private async Task CreateAttribute(CreateOrUpdateAttributeInput input, EntityDto <long> output) { var attribute = await _productAttributeManager.FindByNameAsync(input.Name); if (attribute != null) { throw new UserFriendlyException("属性已存在"); } attribute = new ProductAttribute() { Name = input.Name, DisplayOrder = input.DisplayOrder, }; await _productAttributeManager.CreateAsync(attribute); await CurrentUnitOfWork.SaveChangesAsync(); output.Id = attribute.Id; }