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