public void given_information()
 {
     representation = Builder <SquadPostRp> .CreateNew()
                      .With(x => x.Name       = $"{Guid.NewGuid()}")
                      .With(x => x.CustomerId = this.DefaultCustomerId)
                      .Build();
 }
 public void given_information()
 {
     representation = Builder <SquadPostRp> .CreateNew()
                      .With(x => x.Name       = KeyConstants.SquadName)
                      .With(x => x.CustomerId = this.DefaultCustomerId)
                      .Build();
 }
Esempio n. 3
0
        public async Task <IActionResult> Post([FromBody] SquadPostRp resource)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var response = await this._squadComponent.CreateSquad(resource);

            return(this.Created(Url.RouteUrl("GetSquadId", new { id = response.Id }), response));
        }
Esempio n. 4
0
        /// <summary>
        /// Create a new Squad
        /// </summary>
        /// <param name="model">Squad Model</param>
        /// <returns></returns>
        public async Task <SquadGetRp> CreateSquad(SquadPostRp model)
        {
            var createdBy = this._identityGateway.GetIdentity();
            var customer  = await this._dbContext.Customers.Where(c => c.Id == model.CustomerId).SingleAsync();

            var entity = await this._dbContext.Squads.Where(c => c.Name == model.Name && c.CustomerId == model.CustomerId).SingleOrDefaultAsync();

            if (entity == null)
            {
                entity = SquadEntity.Factory.Create(model.Name, this._datetimeGateway.GetCurrentDateTime(), createdBy, customer);
                this._dbContext.Squads.Add(entity);
                await this._dbContext.SaveChangesAsync();
            }

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