Exemplo n.º 1
0
        public async Task <AddProductPayload> AddProductAsync(
            AddProductInput input,
            [ScopedService] ApplicationDbContext context,
            [Service] ITopicEventSender eventSender)
        {
            var product = new Product
            {
                Name        = input.name,
                Description = input.description,
                UOM         = input.uom,
                Status      = input.status,
                BrandId     = input.brandId,
                CategoryId  = input.categoryId
            };

            await context.Products.AddAsync(product);

            await context.SaveChangesAsync();

            await eventSender.SendAsync(
                nameof(ProductsSubscription.OnProductCreatedAsync),
                product.Id
                );

            return(new AddProductPayload(product));
        }
Exemplo n.º 2
0
        public async Task <AddProductPayload> AddProductAsync(
            AddProductInput input,
            [Service] OMSOrdersContext context)
        {
            if (string.IsNullOrWhiteSpace(input.ProductName))
            {
                _logger.LogError("invalid input {@input}", input);
                throw new Exception("Bad request");
            }

            var product = new Product
            {
                ProductName = input.ProductName,
                Cost        = Convert.ToDecimal(input.Cost)
            };

            _logger.LogDebug("adding product {@input}", input);

            context.Products.Add(product);
            await context.SaveChangesAsync();

            return(new AddProductPayload(new GQLModels.Product
            {
                ProductName = input.ProductName,
                Cost = input.Cost
            }));
        }
Exemplo n.º 3
0
        public AddProductOutput AddProduct(AddProductInput input)
        {
            Product product = _productDomainService.Add(input.Name);

            return(new AddProductOutput
            {
                ProductId = product.Id,
                ProductName = product.Name
            });
        }
Exemplo n.º 4
0
        public async void AddProductShouldThrowErrorForInvalidInput()
        {
            //Arrange
            var product = new AddProductInput();

            //Act
            var mutationStatus = await Assert.ThrowsAsync <Exception>(() => mutation.AddProductAsync(product, null));

            //Assert
            mutationStatus.Message.Should().Be("Bad request");
        }
Exemplo n.º 5
0
        public async Task <Model.AddProductPayload> AddProductAsync(AddProductInput input, [ScopedService] ApplicationDbContext context)
        {
            var(name, description, categoryId) = input;
            var product = new Product(name, description, categoryId);

            await context.Products.AddAsync(product);

            await context.SaveChangesAsync();

            return(new(product));
        }
Exemplo n.º 6
0
 public ActionResult Add(AddProductInput input)
 {
     if (string.IsNullOrEmpty(input.ProSortID))
     {
         input.ProSortID = "0";
     }
     input.CreateID   = CurrentSession.UserId;
     input.CreateDate = DateTime.Now;
     input.ShopID     = CurrentSession.ShopID;
     this.Service.Add(input);
     return(this.AddSuccessMsg());
 }
Exemplo n.º 7
0
        public async Task <AddProductPayload> AddProductAsync(AddProductInput input, [Service] ApplicationDbContext context, CancellationToken cancellationToken)
        {
            Manufacturer?manufacturer = await context.Manufacturers.FindAsync(input.ManufacturerId);

            var product = new Product {
                Name = input.Name, Price = input.Price, LastUpdated = input.LastUpdated, PrimaryManufacturer = manufacturer
            };

            context.Products.Add(product);
            await context.SaveChangesAsync();

            return(new AddProductPayload(product));
        }
Exemplo n.º 8
0
        public async Task <AddProductPayload> AppProductAsync(AddProductInput input, [ScopedService] AppDbContext context)
        {
            var product = new Product
            {
                Name       = input.name,
                Price      = input.price,
                CategoryId = input.categoryId
            };

            context.Add(product);
            await context.SaveChangesAsync();

            return(new AddProductPayload(product));
        }
Exemplo n.º 9
0
        public async Task <AddProductPayload> AddProductAsync(AddProductInput input, [ScopedService] AppDbContext context)
        {
            var product = new Product
            {
                Name        = input.Name,
                Price       = input.Price,
                Type        = input.Type,
                Description = input.Description,
                ImgUrl      = input.ImgUrl
            };

            context.Products.Add(product);
            await context.SaveChangesAsync();

            var payload = new AddProductPayload(product);

            return(payload);
        }
Exemplo n.º 10
0
        public async Task <AddProductPayload> AddProductAsync(
            AddProductInput input,
            [ScopedService] NakodaAgenciesDbContext context,
            [Service] ITopicEventSender eventSender,
            CancellationToken cancellationToken
            )
        {
            try
            {
                //List<TestGraphQL.Models.Product> _address = Builder<TestGraphQL.Models.Product>.CreateListOfSize(10000).All()
                //  .With(c => c.ProductName = Faker.Address.StreetName())

                //  ).Build().ToList();

                var region = new TestGraphQL.Models.Product
                {
                    ProductName = input.ProductName,
                    Active      = true,
                    CreatedDate = DateTime.Now
                };
                context.Products.AddRange(region);


                await context.SaveChangesAsync(cancellationToken);

                await eventSender.SendAsync(nameof(ProductSubscription.OnProductAdded), region, cancellationToken);

                var _regionResponse = (from _region in context.Products
                                       where _region.ProductId.Equals(region.ProductId)
                                       select new Models.Product
                {
                    ProductId = _region.ProductId ?? default(Guid),
                    ProductName = _region.ProductName,
                    Active = _region.Active,
                    CreatedDate = _region.CreatedDate
                }).FirstOrDefault();

                return(new AddProductPayload(_regionResponse));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 11
0
        public async Task <AddProductPayload> AddProductAsync(
            AddProductInput input,
            [ScopedService] ApplicationDbContext context)
        {
            // create new Product
            var product = new Product
            {
                Name        = input.Name,
                Price       = input.Price,
                Type        = input.Type,
                Description = input.Description,
                ImgUrl      = input.ImgUrl
            };

            // add to db-context
            context.Products.Add(product);

            // save changes
            await context.SaveChangesAsync();

            return(new AddProductPayload(product));
        }
Exemplo n.º 12
0
 public AddProductOutput AddProduct(AddProductInput input)
 {
     return(_productAppService.AddProduct(input));
 }
Exemplo n.º 13
0
 public void Add(AddProductInput input)
 {
     this.InsertFromDto(input);
 }