コード例 #1
0
        public async Task <string> AddImage(string productId, ProductImageCreateRequest request)
        {
            var productImage = new productPhotos()
            {
                IdPhoto      = request.idImage,
                idProduct    = request.idProduct,
                uploadedTime = DateTime.Now,
            };

            if (request.ImageFile != null)
            {
                productImage.link = new string("https://localhost:5001" + await this.SaveFile(request.ImageFile));
            }
            _context.productPhotos.Add(productImage);
            await _context.SaveChangesAsync();

            return(productImage.IdPhoto);
        }
コード例 #2
0
        public async Task <int> AddImage(int idProduct, ProductImageCreateRequest request)
        {
            var ProductPhoto = new productPhotos()
            {
                Caption      = request.Caption,
                uploadedTime = DateTime.Now,
                IsDefault    = request.IsDefault,
                idProduct    = idProduct,
                SortOrder    = request.SortOrder,
            };

            if (request.ImageFile != null)
            {
                ProductPhoto.ImagePath = await this.SaveFile(request.ImageFile);

                ProductPhoto.FileSize = request.ImageFile.Length;
            }
            _context.productPhotos.Add(ProductPhoto);
            await _context.SaveChangesAsync();

            return(ProductPhoto.Id);
        }