public async Task ValidateUniqueId <T>(IBaseDao <T> dao, long id) where T : BaseEntity <T> { if (await dao.ExistByIdAsync(id)) { var duplicateEntryException = new DuplicateEntryException(id, "Entity already exists!"); Logger.Error(duplicateEntryException, "{type} with {id} already exists!", typeof(T), id); throw duplicateEntryException; } }
public async Task <long> AddRowCategoryAsync(RowCategory category) { ValidateNotNull(category); if (await _rowCategoryDao.ExistByIdAsync(category.Id)) { var duplicateEntryException = new DuplicateEntryException(category.Id, "Category already exists!"); Logger.Error(duplicateEntryException, "{Category} already exists", category); throw duplicateEntryException; } return((await _rowCategoryDao.FluentInsert(category).ExecuteAsync()).First()); }
public async Task <long> AddCinemaHallAsync(CinemaHall cinemaHall) { ValidateNotNull(cinemaHall); if (await _cinemaHallDao.ExistByIdAsync(cinemaHall.Id)) { var duplicateEntryException = new DuplicateEntryException(cinemaHall.Id, "CinemaHall already exists!"); Logger.Error(duplicateEntryException, "{CinemaHall} already exists", cinemaHall); throw duplicateEntryException; } return((await _cinemaHallDao.FluentInsert(cinemaHall).ExecuteAsync()).First()); }
public async Task <long> AddRoleAsync(Role role) { ValidateNotNull(role); await ValidateUniqueId(_roleDao, role.Id); var roleExist = await _roleDao.ExistAsync(role.Label); if (roleExist.Exist) { var duplicateEntryException = new DuplicateEntryException(roleExist.Id, "Role label already exist!"); Logger.Error(duplicateEntryException, "{Role} label already exists", role); throw duplicateEntryException; } return((await _roleDao.FluentInsert(role).ExecuteAsync()).FirstOrDefault()); }
public async Task <long> AddCityAsync(City city) { ValidateNotNull(city); await ValidateUniqueId(_cityDao, city.Id); var cityExist = await CityExistAsync(city.PostalCode, city.Name); if (cityExist.Exist) { var duplicateEntryException = new DuplicateEntryException(cityExist.Id, "City already exist!"); Logger.Error(duplicateEntryException, "{City} already exists", city); throw duplicateEntryException; } return((await _cityDao.FluentInsert(city).ExecuteAsync()).FirstOrDefault()); }
public async Task <long> AddSeatAsync(Seat seat) { ValidateNotNull(seat); if (await _seatDao.ExistByIdAsync(seat.Id)) { var duplicateEntryException = new DuplicateEntryException(seat.Id, "Seat already exist!"); Logger.Error(duplicateEntryException, "{Seat} already exists", seat); throw duplicateEntryException; } if (seat.Row != null && seat.RowId <= 0) { seat.RowId = seat.Row.Id; } await ValidateId(_rowDao, seat.RowId); return((await _seatDao.FluentInsert(seat).ExecuteAsync()).First()); }
public async Task <long> AddRowAsync(Row row) { ValidateNotNull(row); if (await _rowDao.ExistByIdAsync(row.Id)) { var duplicateEntryException = new DuplicateEntryException(row.Id, "Row already exists!"); Logger.Error(duplicateEntryException, "{Row} already exists", row); throw duplicateEntryException; } if (row.CinemaHall != null && row.CinemaHallId <= 0) { row.CinemaHallId = row.CinemaHall.Id; } if (row.Category != null && row.CategoryId <= 0) { row.CategoryId = row.Category.Id; } await ValidateId(_cinemaHallDao, row.CinemaHallId); await ValidateId(_rowCategoryDao, row.CategoryId); return((await _rowDao.FluentInsert(row).ExecuteAsync()).First()); }