예제 #1
0
 public async Task <ValidationResult> IsSatisfiedBy(AddSegmentDto dto)
 {
     if (await repository.Any(dto))
     {
         return(new ValidationResult("Should be unique"));
     }
     return(ValidationResult.Success);
 }
예제 #2
0
 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);
     }
 }
예제 #3
0
        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);
        }
예제 #4
0
 public Segment(AddSegmentDto dto)
 {
 }