예제 #1
0
        public async Task CreateCustomer(CustomerPostRp resource)
        {
            string createdBy = _identityService.GetClientId();

            User existingUser = await _userRepository.GetUserById(resource.AdminId.ToString());

            if (existingUser == null)
            {
                await _domainManagerService.AddConflict($"The user with id {resource.AdminId} does not exists.");

                return;
            }

            Customer existingCustomer = await _customerRepository.GetCustomerByName(resource.Name);

            if (existingCustomer != null)
            {
                await _domainManagerService.AddConflict($"The team with name {resource.Name} has already been taken.");

                return;
            }

            Customer newCustomer = Customer.Factory.Create(resource.CustomerId, resource.Name, resource.AdminId.ToString(),
                                                           resource.AdminName, resource.AdminEmail, createdBy);

            _customerRepository.Add(newCustomer);
            await _customerRepository.SaveChanges();
        }
예제 #2
0
        public async Task <IActionResult> Post([FromBody] CustomerPostRp resource)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var response = await this._customerComponent.CreateCustomer(resource);

            return(this.Created(Url.RouteUrl("GetCustomerId", new { id = response.Id }), response));
        }
예제 #3
0
        public async Task <IActionResult> CreateCustomer([FromBody] CustomerPostRp resource)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequest(ModelState));
            }

            await _CustomerService.CreateCustomer(resource);

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

            return(this.Ok(base.DefaultResponse));
        }
예제 #4
0
        public async Task <CustomerGetListRp> CreateCustomer(CustomerPostRp model)
        {
            var createdBy = this._identityGateway.GetIdentity();

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

            return(await retryPolicy.ExecuteAsync(async() =>
            {
                var entity = await this._dbContext.GetCustomer(model.Name);
                if (entity == null)
                {
                    entity = CustomerEntity.Factory.Create(createdBy,
                                                           this._datetimeGateway.GetCurrentDateTime()
                                                           , model.Name, defaultValue: model.Default);
                    await this._dbContext.AddAsync(entity);
                    await this._dbContext.SaveChangesAsync();
                }
                return this._mapper.Map <CustomerGetListRp>(entity);
            }));
        }
 public void given_information()
 {
     representation = Builder <CustomerPostRp> .CreateNew()
                      .With(x => x.Name = Faker.Company.Name())
                      .Build();
 }