Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> AddAsync([FromBody] VacationTypeDto vacationDto)
        {
            var createdType = await _vacationTypeService.AddAsync(vacationDto);

            return(Ok(createdType));
        }