public async Task <(bool isSuccess, string errorMessage, int pollingStationId)> AddPollingStationAsync(PollingStationModel pollingStation) { try { using (var transaction = _context.Database.BeginTransaction()) { var newId = await _context.PollingStations.MaxAsync(x => x.Id) + 1; var entity = new PollingStationEntity { Id = newId, Address = pollingStation.Address, Longitude = pollingStation.Longitude, Latitude = pollingStation.Latitude, County = pollingStation.County, PollingStationNumber = pollingStation.PollingStationNumber, Locality = pollingStation.Locality, Institution = pollingStation.Institution, }; await _context.PollingStations.AddAsync(entity); _context.SaveChanges(); transaction.Commit(); return(true, string.Empty, newId); } } catch (Exception e) { _logger.LogError(e, "Could not add new polling station"); return(false, e.Message, -1); } }
public async Task <(bool isSuccess, string errorMessage)> AddApplicationContentAsync(ApplicationContentModel content) { try { using (var transaction = _context.Database.BeginTransaction()) { var languageContent = await _context.ApplicationContent.FirstOrDefaultAsync(x => x.Language == content.Language); if (languageContent != null) { return(false, $"Content for language {content.Language} already exists"); } var entity = new ApplicationContentEntity() { Language = content.Language, ApplicationContent = content }; await _context.ApplicationContent.AddAsync(entity); _context.SaveChanges(); transaction.Commit(); return(true, string.Empty); } } catch (Exception e) { _logger.LogError(e, "Could not add new polling station"); return(false, e.Message); } }
public async Task <(bool isSuccess, string errorMessage)> DeleteApplicationContentAsync(Language language) { try { var entity = await _context.ApplicationContent.FirstOrDefaultAsync(x => x.Language == language); if (entity == null) { return(false, $"Could not find content for language = {language}"); } _context.ApplicationContent.Remove(entity); _context.SaveChanges(); return(true, string.Empty); } catch (Exception e) { _logger.LogError(e, $"Could not delete content for language ={language}"); return(false, e.Message); } }