public void given_information()
 {
     representation = Builder <FeaturePostRp> .CreateNew()
                      .With(x => x.Name      = $"{Guid.NewGuid()}")
                      .With(x => x.ProductId = KeyConstants.ProductId)
                      .Build();
 }
Ejemplo n.º 2
0
 public void given_information()
 {
     representation = Builder <FeaturePostRp> .CreateNew()
                      .With(x => x.Name      = KeyConstants.FeatureName)
                      .With(x => x.ProductId = this.DefaultProductId)
                      .Build();
 }
Ejemplo n.º 3
0
        public async Task <IActionResult> Post([FromBody] FeaturePostRp resource)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var response = await this._featureComponent.CreateFeature(resource);

            return(this.Created(Url.RouteUrl("GetFeatureId", new { id = response.Id }), response));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create a new Feature
        /// </summary>
        /// <param name="model">Feature Model</param>
        /// <returns></returns>
        public async Task <FeatureGetListRp> CreateFeature(FeaturePostRp model)
        {
            var result    = new BaseComponentResultRp();
            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.Features.Where(c => c.ProductId == model.ProductId && c.Name == model.Name).SingleOrDefaultAsync();
                if (entity == null)
                {
                    var product = await this._dbContext.Products.SingleAsync(c => c.Id == model.ProductId);
                    entity = FeatureEntity.Factory.Create(model.Name, this._datetimeGateway.GetCurrentDateTime(), createdBy, product);
                    await this._dbContext.AddAsync(entity);
                    await this._dbContext.SaveChangesAsync();
                }

                return this._mapper.Map <FeatureGetListRp>(entity);
            }));
        }