コード例 #1
0
        public async Task UpdateAsync(Product product, ProductAddOrUpdateModel updated)
        {
            await product.LoadDataByOptionsAsync(_unitOfWork);

            updated.MapToExisting(product);

            _builder.SetBuildingEntity(product,
                                       _schemes.Query
                                       .Include(x => x.FieldDefenitions)
                                       .Include(x => x.FieldDefenitionGroups)
                                       .Include(x => x.FieldDefenitionGroups.Select(fdg => fdg.FieldDefenitions))
                                       .First(x => x.Id == product.SchemeId),
                                       _productCategories.Query
                                       .Include(x => x.FieldDefenitionGroups)
                                       .Include(x => x.FieldDefenitionGroups.Select(fdg => fdg.FieldDefenitions))
                                       .Include(x => x.FieldDefenitions)
                                       .First(x => x.Id == product.PrimaryCategoryId)
                                       );
            HandleFields(product, updated.Fields);
            product = _builder.GetResult();

            SanitizeAllowedQuantities(product);
            await HandleEshantionsAsync(product, updated.Eshantions.MapToModel());
            await HandleRequiredProductsAsync(product, updated.RequiredProducts.MapToModel());
            await HandleCrossSellingsAsync(product, updated.CrossSellings.MapToModel());
            await HandleUpSellingsAsync(product, updated.UpSellings.MapToModel());
            await HandleAssociatedProductsAsync(product, updated.AssociatedProducts.MapToModel());

            HandleDownLoadFileIfItIs(product);
            HandlePictures(product);
            await _baseBeforeUpdateEntityLogics.ForEachAsync(x =>
                                                             x.ApplyLogicAsync(product, _identityManager.GetCurrentPrincipal()));

            await _products.UpdateAsync(product);
        }