Ejemplo n.º 1
0
 public void given_information()
 {
     representation = Builder <ProductPostRp> .CreateNew()
                      .With(x => x.Name       = $"{Guid.NewGuid()}")
                      .With(x => x.CustomerId = this.DefaultCustomerId)
                      .Build();
 }
 public void given_information()
 {
     representation = Builder <ProductPostRp> .CreateNew()
                      .With(x => x.Name       = KeyConstants.ProductName)
                      .With(x => x.CustomerId = this.DefaultCustomerId)
                      .Build();
 }
Ejemplo n.º 3
0
        public async Task <IActionResult> Post([FromBody] ProductPostRp resource)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }
            var response = await this._productComponent.CreateProduct(resource);

            return(this.Created(Url.RouteUrl("GetProductId", new { response.Id }), response));
        }
Ejemplo n.º 4
0
        public async Task <ProductGetListItemRp> CreateProduct(ProductPostRp model)
        {
            var createdBy = this._identityGateway.GetIdentity();

            var retryPolicy = Policy.Handle <DbUpdateException>()
                              .WaitAndRetryAsync(this._configuration.DefaultRetryAttempts,
                                                 i => this._configuration.DefaultPauseBetweenFails);

            return(await retryPolicy.ExecuteAsync(async() =>
            {
                var entity = await this._dbContext.GetProduct(model.CustomerId, model.Name);
                if (entity == null)
                {
                    var customer = await this._dbContext.Customers.SingleAsync(c => c.Id == model.CustomerId);
                    entity = ProductEntity.Factory.Create(model.Name,
                                                          this._datetimeGateway.GetCurrentDateTime(),
                                                          createdBy, customer);
                    this._dbContext.Products.Add(entity);
                    await this._dbContext.SaveChangesAsync();
                }
                return this._mapper.Map <ProductGetListItemRp>(entity);
            }));
        }