public async Task <IActionResult> Post([FromBody] SquadFeaturePostRp resource)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var response = await this._squadFeatureComponent.CreateSquadFeature(resource);

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

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


            return(this.Created(Url.RouteUrl("GetSquadFeatureById", new { id }), newResource));
        }
Exemplo n.º 2
0
        public async Task RegisterSquad(SquadFeaturePostRp model)
        {
            var result = new BaseComponentResultRp();

            var createdBy = this._identityGateway.GetIdentity();


            var target = await this._dbContext.SquadFeatures.Where(c => c.SquadId == model.SquadId &&
                                                                   c.FeatureId == model.FeatureId).SingleOrDefaultAsync();

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

                var feature = await this._dbContext.Features.SingleAsync(c => c.Id == model.FeatureId);

                var entity = SquadFeatureEntity.Factory.Create(squad, feature, this._datetimeGateway.GetCurrentDateTime(), createdBy);
                this._dbContext.SquadFeatures.Add(entity);
                await this._dbContext.SaveChangesAsync();
            }
        }