コード例 #1
0
ファイル: TraceService.cs プロジェクト: randyrod/oss-traces
        public async Task <TraceDto> CreateTraceAsync(CreateTraceDto createTraceDto)
        {
            Check.NotNull(createTraceDto, nameof(createTraceDto));

            if (string.IsNullOrWhiteSpace(createTraceDto.Title) ||
                createTraceDto.DueDate < LocalDate.FromDateTime(DateTime.Today))
            {
                throw new BusinessValidationException(TextConstants.CreateTraceWithoutTitleOrFutureDateErrorMessage);
            }

            var trace = new Trace
            {
                Description   = createTraceDto.Description.ValueOrDefault(),
                State         = TraceState.Active,
                Title         = createTraceDto.Title,
                DueDate       = createTraceDto.DueDate,
                PropertyId    = createTraceDto.PropertyId,
                ReservationId = createTraceDto.ReservationId.ValueOrDefault(),
                AssignedRole  = createTraceDto.AssignedRole.ValueOrDefault()
            };

            _traceRepository.Insert(trace);

            await _traceRepository.SaveAsync();

            return(TraceToDto(trace));
        }
コード例 #2
0
        public async Task <IActionResult> Post([FromBody] Trace t)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var trace = _traceRepository.Add(t);
            await _traceRepository.SaveAsync();

            await EnsureOriginAsync(t);

            return(CreatedAtAction(nameof(Get), new { TraceId = trace.TraceId }, trace));
        }