public virtual bool AddTipsterIfNotExists(DbTipster tipster) { OnInformationSending("Dodawanie tipstera..."); if (_db.Tipsters.AsEnumerable().Any(t => t.NameDomainEquals(tipster))) { OnInformationSending("Dodano Tipstera"); return(false); } var tipsterDomain = tipster.Link.UrlToDomain(); var websiteId = _db.Websites.SingleOrDefault(w => w.Address == tipsterDomain)?.Id; if (websiteId == null) { var newWId = _db.Websites.Next(w => w.Id); var website = new DbWebsite(newWId, tipsterDomain, null); _db.Websites.Add(website); _db.SaveChanges(); websiteId = newWId; } var tipsterToAdd = new DbTipster { Id = _db.Tipsters.Next(v => v.Id), Name = tipster.Name, Link = tipster.Link, WebsiteId = websiteId }; _db.Tipsters.AddOrUpdate(tipsterToAdd); _db.SaveChanges(); OnInformationSending("Dodano Tipstera"); return(true); }
public async Task UpdateAsync(DbWebsite dbWebsite) { await using var connection = _connectionFactory.CreateConnection(); var query = @$ "UPDATE website SET address = @Address, status = @StatusAsString::e_status WHERE id = @Id"; await connection.ExecuteAsync(query, dbWebsite); }
public static WebsiteGvVM ToWebsiteGvVM(DbWebsite dbWebsite) { return(new WebsiteGvVM { Address = dbWebsite.Address, Login = dbWebsite.Login?.ToLoginGvVM() }); }
private async Task <DbWebsite> HandleUrlAddress(string address) { var isAccessed = await _websiteCheckerClient.CheckAsync(address); var website = new DbWebsite { Address = address, Status = isAccessed }; return(await _websiteRepository.CreateAsync(website)); }
public async Task <DbWebsite> CreateAsync(DbWebsite dbWebsite) { await using var connection = _connectionFactory.CreateConnection(); var query = @$ "INSERT INTO website (address, status) VALUES (@Address, @StatusAsString::e_status) RETURNING *"; var dbDataReader = await connection.ExecuteReaderAsync(query, dbWebsite); return(dbDataReader.Parse <DbWebsite>().FirstOrDefault()); }
private async Task UpdateStatus(DbWebsite website) { var isAccessed = await _websiteCheckerClient.CheckAsync(website.Address); if (isAccessed != website.Status) { website.Status = isAccessed; await _websiteRepository.UpdateAsync(website); } }
public async Task <Unit> Handle(WebsiteEditCommand request, CancellationToken cancellationToken) { var status = await _websiteCheckerClient.CheckAsync(request.Address); var website = new DbWebsite { Id = request.Id, Address = request.Address, Status = status }; await _websiteRepository.UpdateAsync(website); return(Unit.Value); }