示例#1
0
        public async Task <PeriodResponse> SaveAsync(Period period)
        {
            try
            {
                await _periodRepository.AddAsync(period);

                await _unitOfWork.CompleteAsync();

                return(new PeriodResponse(period));
            }
            catch (Exception e)
            {
                return(new PeriodResponse($"An error occurred when saving the period: {e.Message}"));
            }
        }
示例#2
0
        public async Task <Period> CreatePeriod(CreatePeriodDTO dto)
        {
            if (dto.End < dto.Start)
            {
                throw new HttpStatusCodeException(HttpStatusCode.BadRequest, $"Einddatum moet na de startdatum liggen.");
            }
            var newPeriod = new Period
            {
                Name  = dto.Name.Trim(),
                Start = dto.Start.Date,
                End   = dto.End.Date
            };

            await _periodRepository.AddAsync(newPeriod);

            await _periodRepository.SaveChangesAsync();

            return(newPeriod);
        }