public void given_information() { representation = Builder <JourneyPostRp> .CreateNew() .With(x => x.Name = $"{Guid.NewGuid()}") .With(x => x.ProductId = this.DefaultProductId) .Build(); }
public void given_information() { representation = Builder <JourneyPostRp> .CreateNew() .With(x => x.Name = KeyConstants.JourneyName) .With(x => x.ProductId = this.DefaultProductId) .Build(); }
public async Task <IActionResult> Post([FromBody] JourneyPostRp resource) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var response = await this._journeyComponent.Create(resource); return(this.Created(Url.RouteUrl("GetJourneyId", new { id = response.Id }), response)); }
/// <summary> /// Create a new journey /// </summary> /// <param name="model">journey Model</param> /// <returns></returns> public async Task <JourneyGetListRp> Create(JourneyPostRp 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 product = await this._dbContext.Products.Where(c => c.Id == model.ProductId).SingleAsync(); var entity = await this._dbContext.Journeys.Where(c => c.ProductId == model.ProductId && c.Name == model.Name).SingleOrDefaultAsync(); if (entity == null) { entity = JourneyEntity.Factory.Create(model.Name, this._datetimeGateway.GetCurrentDateTime(), createdBy, product); this._dbContext.Journeys.Add(entity); await this._dbContext.SaveChangesAsyncRetry <DbUpdateException>(); } return this._mapper.Map <JourneyGetListRp>(entity); })); }