Exemple #1
0
 public async Task <ValidationResult> IsSatisfiedBy(AddSegmentDto dto)
 {
     if (await repository.Any(dto))
     {
         return(new ValidationResult("Should be unique"));
     }
     return(ValidationResult.Success);
 }
 public async Task<IActionResult> Add([FromBody] AddSegmentDto dto, 
     [FromServices] AddSegmentService service) 
 {
     try
     {
         var segment = await service.ExecAsync(dto);
         if(service.Result == ValidationResult.Success)
             return CreatedAtAction(nameof(GetById), new { id = segment.Id });                
         return BadRequest(service.Result);
     }
     catch (Exception e)
     {
         return base.StatusCode(500, e);
     }
 }
        public async Task <Segment> ExecAsync(AddSegmentDto dto)
        {
            Result = await specification.IsSatisfiedBy(dto);

            if (Result != ValidationResult.Success)
            {
                return(null);
            }

            var segment = new Segment(dto);
            await repository.Add(segment);

            await Task.WhenAll(eventHandlers.Select(e => e.Handle(segment)));

            return(segment);
        }
Exemple #4
0
 public Segment(AddSegmentDto dto)
 {
 }