예제 #1
0
        public async Task <SourceGetListRp> Create(SourcePostRp model)
        {
            var createdBy = this._identityGateway.GetIdentity();

            var product = await this._dbContext.Products.SingleAsync(c => c.Id == model.ProductId);

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

            return(await retryPolicy.ExecuteAsync(async() =>
            {
                var entity = await this._dbContext.GetSource(model.ProductId, model.Name);

                if (entity == null)
                {
                    entity = SourceEntity.Factory.Create(product, model.Name,
                                                         this._datetimeGateway.GetCurrentDateTime(), createdBy);
                    await this._dbContext.AddAsync(entity);
                    await this._dbContext.SaveChangesAsync();
                }

                return this._mapper.Map <SourceGetListRp>(entity);
            }));
        }
예제 #2
0
        public async Task <IActionResult> Post([FromBody] SourcePostRp resource)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }
            var response = await this._sourceComponent.Create(resource);

            return(this.Created(Url.RouteUrl("GetSourceById", new { response.Id }), response));
        }