예제 #1
0
        public async Task <IActionResult> Post([FromBody] CreateCampaignCommand command)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var response = await this._mediator.Send(command);

            return(this.Created(Url.RouteUrl("GetCampaignById", new { id = response.Id }), new { }));
        }
예제 #2
0
        public void CreateCampaign_Should_Not_Validated_When_Duration_Is_Lower_Than_1(int duration)
        {
            var createCampaignCommand = new CreateCampaignCommand
            {
                CampaignName           = FakeObjects.Instance.Random.AlphaNumeric(3),
                ProductCode            = FakeObjects.Instance.Random.AlphaNumeric(3),
                Duration               = duration,
                TargetSalesCount       = FakeObjects.Instance.Random.Int(10, 100),
                PriceManipulationLimit = FakeObjects.Instance.Random.Int(1, 20)
            };
            var validationResult = _validator.Validate(createCampaignCommand);

            validationResult.Errors.Any(x => x.PropertyName == nameof(createCampaignCommand.Duration)).Should().Be(true);
        }
예제 #3
0
        public void CreateCampaign_Should_Not_Validated_When_ProductCode_Length_Is_GreaterThan_3(string productCode)
        {
            var createCampaignCommand = new CreateCampaignCommand
            {
                CampaignName           = FakeObjects.Instance.Random.AlphaNumeric(3),
                ProductCode            = productCode,
                Duration               = FakeObjects.Instance.Random.Int(1, 10),
                TargetSalesCount       = FakeObjects.Instance.Random.Int(10, 100),
                PriceManipulationLimit = FakeObjects.Instance.Random.Int(1, 20)
            };
            var validationResult = _validator.Validate(createCampaignCommand);

            validationResult.Errors.Any(x => x.PropertyName == nameof(createCampaignCommand.ProductCode)).Should().Be(true);
        }
예제 #4
0
        public override async Task <string> Process()
        {
            var command = new CreateCampaignCommand
            {
                CampaignName           = _parameters[1],
                ProductCode            = _parameters[2],
                Duration               = int.Parse(_parameters[3]),
                PriceManipulationLimit = int.Parse(_parameters[4]),
                TargetSalesCount       = int.Parse(_parameters[5])
            };
            var response = await _mediator.Send(command);

            return("Campaign created; " +
                   $"name {response.Campaign.Name}," +
                   $" product {response.Campaign.ProductCode}," +
                   $" duration {response.Campaign.Duration}," +
                   $"limit {response.Campaign.PriceManipulationLimit}," +
                   $" target sales count {response.Campaign.TargetSalesCount} \r\n");
        }
예제 #5
0
        public async Task <IActionResult> PostAsync([FromBody] CreateCampaignCommand command, CancellationToken cancellationToken = default)
        {
            var campaign = await this.mediator.Send(command, cancellationToken);

            return(CreatedAtAction("Get", new { campaign.Id }, mapper.Map <CampaignDto>(campaign)));
        }
예제 #6
0
 public Task <Response <Campaign> > CreateCampaign(CreateCampaignCommand command)
 {
     return(_context.CreateCampaign(command));
 }
 public async Task <Guid> CreateCampaignAsync([FromBody] CreateCampaignCommand command)
 => await _mediator.Send(command);
예제 #8
0
        public async Task <IActionResult> PostCampaignAsync(CreateCampaignCommand command)
        {
            var response = await Mediator.Send(command);

            return(Accepted(response));
        }