예제 #1
0
        public async Task <VacationType> AddAsync(VacationTypeDto typeDto)
        {
            var existingType = _urlopikDbContext.VacationTypes.SingleOrDefault(x => x.Name == typeDto.Name);

            if (existingType != null)
            {
                if (existingType.IsDeleted)
                {
                    existingType.IsDeleted = false;
                    await _urlopikDbContext.SaveChangesAsync();

                    return(existingType);
                }
                else
                {
                    throw new ApiException($"VacationType {typeDto.Name} already exists!");
                }
            }

            var newType = _mapper.Map <VacationType>(typeDto);
            await _urlopikDbContext.AddAsync(newType);

            await _urlopikDbContext.SaveChangesAsync();

            return(newType);
        }
예제 #2
0
        public async Task <IActionResult> AddAsync([FromBody] VacationTypeDto vacationDto)
        {
            var createdType = await _vacationTypeService.AddAsync(vacationDto);

            return(Ok(createdType));
        }