public void then_update()
        {
            var memberPost = new SquadProductPostRp();

            memberPost.ProductId = KeyConstants.ProductId;
            memberPost.SquadId   = squadId;

            var jsonContent  = HttpClientExtension.ParseModelToHttpContent(memberPost);
            var responsePost = this._client.PostAsync($"/squadProducts", jsonContent).Result;

            Assert.Equal(StatusCodes.Status201Created, (int)responsePost.StatusCode);
        }
        public async Task <IActionResult> Post([FromBody] SquadProductPostRp resource)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var response = await this._squadProductComponent.CreateSquadProduct(resource);

            if (response.HasConflicts())
            {
                return(this.Conflict(response.GetConflicts()));
            }

            var id          = response.GetResult <int>("Id");
            var newResource = await this._squadProductComponent.GetId(id);


            return(this.Created(Url.RouteUrl("GetSquadProductById", new { id }), newResource));
        }
Exemple #3
0
        public async Task <BaseComponentResultRp> CreateSquadProduct(SquadProductPostRp model)
        {
            var result = new BaseComponentResultRp();

            var createdBy = this._identityService.GetIdentity();

            var squad = await this._dbContext.Squads.SingleAsync(c => c.Id == model.SquadId);

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

            var entity = SquadProductEntity.Factory.Create(squad, Product, this._datetimeGateway.GetCurrentDateTime(), createdBy);

            this._dbContext.SquadProducts.Add(entity);

            await this._dbContext.SaveChangesAsync();

            result.AddResult("Id", entity.Id);

            return(result);
        }