예제 #1
0
        public async Task CreateShouldWorkCorrectly(
            string name,
            string description,
            string imageSource,
            int quantity,
            decimal price,
            int categoryId)
        {
            var request = new ProductsRequestModel
            {
                Name        = name,
                Description = description,
                ImageSource = imageSource,
                Quantity    = quantity,
                Price       = price,
                CategoryId  = categoryId
            };

            var id = await this.products.CreateAsync(request);

            var product = await this.Data.Products.FindAsync(id);

            product.Id.ShouldBe(id);
            product.Name.ShouldBe(request.Name);
            product.Description.ShouldBe(request.Description);
            product.ImageSource.ShouldBe(request.ImageSource);
            product.Quantity.ShouldBe(request.Quantity);
            product.Price.ShouldBe(request.Price);
            product.CategoryId.ShouldBe(request.CategoryId);
        }
예제 #2
0
        public async Task <int> CreateAsync(ProductsRequestModel model)
        {
            var product = new Product
            {
                Name        = model.Name,
                Description = model.Description,
                ImageSource = model.ImageSource,
                Quantity    = model.Quantity,
                Price       = model.Price,
                CategoryId  = model.CategoryId
            };

            await this.Data.AddAsync(product);

            await this.Data.SaveChangesAsync();

            return(product.Id);
        }
예제 #3
0
        public async Task <Result> UpdateAsync(
            int id, ProductsRequestModel model)
        {
            var product = await this.FindByIdAsync(id);

            if (product == null)
            {
                return(false);
            }

            product.Name        = model.Name;
            product.Description = model.Description;
            product.ImageSource = model.ImageSource;
            product.Quantity    = model.Quantity;
            product.Price       = model.Price;
            product.CategoryId  = model.CategoryId;

            await this.Data.SaveChangesAsync();

            return(true);
        }
        public async Task <Result> CreateProductAsync(ProductsRequestModel model)
        {
            var product = new Product
            {
                Name        = model.Name,
                Description = model.Description,
                Price       = model.Price,
                Article     = model.Article,
                IsActive    = model.IsActive,
                IsVariable  = model.IsSingleAttribute,
                VideoUrl    = model.VideoUrl,
                CategoryId  = model.CategoryId
            };

            await Data.Products.AddAsync(product)
            .ConfigureAwait(false);

            await Data.SaveChangesAsync()
            .ConfigureAwait(false);

            return(Result.Success);
        }
예제 #5
0
        public async Task UpdateShouldWorkCorrectly(
            int count,
            string name,
            string description,
            string imageSource,
            int quantity,
            decimal price,
            int categoryId)
        {
            const int id = 1;

            await this.AddFakeProducts(count);

            var request = new ProductsRequestModel
            {
                Name        = name,
                Description = description,
                ImageSource = imageSource,
                Quantity    = quantity,
                Price       = price,
                CategoryId  = categoryId
            };

            var result = await this.products.UpdateAsync(id, request);

            var product = await this.Data.Products.FindAsync(id);

            result.Succeeded.ShouldBeTrue();

            product.Id.ShouldBe(id);
            product.Name.ShouldBe(request.Name);
            product.Description.ShouldBe(request.Description);
            product.ImageSource.ShouldBe(request.ImageSource);
            product.Quantity.ShouldBe(request.Quantity);
            product.Price.ShouldBe(request.Price);
            product.CategoryId.ShouldBe(request.CategoryId);
        }
예제 #6
0
        protected override async Task OnInitializedAsync()
        {
            this.model = await this.ProductsService.DetailsAsync <ProductsRequestModel>(this.Id);

            this.categories = await this.CategoriesService.All();
        }
 public async Task <ActionResult> Create(ProductsRequestModel model)
 {
     return(await _products
            .CreateProductAsync(model)
            .ToActionResult());
 }