示例#1
0
        public async Task <GetProductForEditOutput> GetProductForEdit(EntityDto input)
        {
            var product = await _productRepository.FirstOrDefaultAsync(input.Id);

            var output = new GetProductForEditOutput {
                Product = ObjectMapper.Map <CreateOrEditProductDto>(product)
            };

            return(output);
        }
示例#2
0
        public async Task <GetProductForEditOutput> GetProductForEdit(NullableIdDto <int> input)
        {
            GetProductForEditOutput productDto;

            if (input.Id.HasValue)
            {
                var product = await _productManager.GetByIdAsync(input.Id.Value);

                await _productManager.ProductRepository.EnsureCollectionLoadedAsync(product, t => t.Categories);

                await _productManager.ProductRepository.EnsureCollectionLoadedAsync(product, t => t.Pictures);

                await _productManager.ProductRepository.EnsureCollectionLoadedAsync(product, t => t.Attributes);

                await _productManager.ProductRepository.EnsureCollectionLoadedAsync(product, t => t.AttributeCombinations);

                productDto = ObjectMapper.Map <GetProductForEditOutput>(product);

                productDto.Categories = product.Categories.ToList().Select(i =>
                {
                    var item = new ProductCategoryDto()
                    {
                        Id = i.CategoryId,
                    };
                    item.Name = _categoryManager.GetByIdAsync(item.Id).Result?.Name ?? string.Empty;
                    return(item);
                }).ToList();

                productDto.Attributes = PrepareProductAttribute(product);

                productDto.AttributeCombinations = await PrepareProductAttributeCombination(product);

                productDto.Pictures = product.Pictures.OrderBy(p => p.DisplayOrder).ToList().Select(i =>
                {
                    var item = new ProductPictureDto()
                    {
                        Id  = i.PictureId,
                        Url = _pictureManager.GetPictureUrl(i.PictureId)
                    };

                    return(item);
                }).ToList();
            }
            else
            {
                productDto = new GetProductForEditOutput();
            }

            return(productDto);
        }
示例#3
0
        public virtual async Task <JsonResult> UpdateProductImage(long productId)
        {
            JsonResult jsonResult;
            Guid?      imageId;

            try
            {
                if (this.Request.Files.Count <= 0 || this.Request.Files[0] == null)
                {
                    throw new UserFriendlyException(this.L("ProductImage_Change_Error"));
                }
                HttpPostedFileBase item = this.Request.Files[0];
                if (item.ContentLength > 512000)
                {
                    throw new UserFriendlyException(this.L("ProductImage_Warn_SizeLimit"));
                }
                GetProductForEditOutput productForEdit = await this._productAppService.GetProductForEdit(new NullableIdInput <long>(new long?(productId)));

                GetProductForEditOutput nullable = productForEdit;
                if (nullable.Product.ImageId.HasValue)
                {
                    IBinaryObjectManager binaryObjectManager = this._binaryObjectManager;
                    imageId = nullable.Product.ImageId;
                    await binaryObjectManager.DeleteAsync(imageId.Value);
                }
                BinaryObject binaryObject = new BinaryObject(item.InputStream.GetAllBytes());
                await this._binaryObjectManager.SaveAsync(binaryObject);

                nullable.Product.ImageId = new Guid?(binaryObject.Id);
                UpdateProductImageInput updateProductImageInput = new UpdateProductImageInput()
                {
                    ProductId = nullable.Product.Id.Value
                };
                imageId = nullable.Product.ImageId;
                updateProductImageInput.ImageId = new Guid?(imageId.Value);
                await this._productAppService.SaveProductImageAsync(updateProductImageInput);

                jsonResult = this.Json(new MvcAjaxResponse());
            }
            catch (UserFriendlyException userFriendlyException1)
            {
                UserFriendlyException userFriendlyException = userFriendlyException1;
                jsonResult = this.Json(new MvcAjaxResponse(new ErrorInfo(userFriendlyException.Message), false));
            }
            return(jsonResult);
        }
        public async Task <GetProductForEditOutput> GetProductForEdit(EntityDto input)
        {
            var product = await _productRepository.FirstOrDefaultAsync(input.Id);

            var output = new GetProductForEditOutput {
                Product = ObjectMapper.Map <CreateOrEditProductDto>(product)
            };

            if (output.Product.CategoryId != null)
            {
                var _lookupCategory = await _lookup_categoryRepository.FirstOrDefaultAsync((int)output.Product.CategoryId);

                output.CategoryName = _lookupCategory.Name.ToString();
            }

            return(output);
        }
示例#5
0
        /// <summary>
        /// 通过Id获取产品信息进行编辑或修改
        /// </summary>
        public async Task <GetProductForEditOutput> GetProductForEditAsync(NullableIdDto <int> input)
        {
            var            output = new GetProductForEditOutput();
            ProductEditDto productEditDto;

            if (input.Id.HasValue)
            {
                var entity = await _productRepository.GetAsync(input.Id.Value);

                productEditDto = entity.MapTo <ProductEditDto>();
            }
            else
            {
                productEditDto = new ProductEditDto();
            }
            output.Product = productEditDto;
            return(output);
        }
示例#6
0
        public async Task <GetProductForEditOutput> GetForEdit(NullableIdDto <Guid> input)
        {
            var            output = new GetProductForEditOutput();
            ProductEditDto editDto;

            if (input.Id.HasValue)
            {
                var entity = await _entityRepository.GetAsync(input.Id.Value);

                editDto = entity.MapTo <ProductEditDto>();

                //productEditDto = ObjectMapper.Map<List<productEditDto>>(entity);
            }
            else
            {
                editDto = new ProductEditDto();
            }

            output.Product = editDto;
            return(output);
        }
示例#7
0
 public CreateOrUpdateProductModalViewModel(GetProductForEditOutput output)
 {
     output.MapTo <GetProductForEditOutput, CreateOrUpdateProductModalViewModel>(this);
 }