private Task SendToDatabase(DownloadInfo info, State state) { return(Task.Run(() => { using (var context = new AppContext()) { var elements = context.DownloadInfos.Where(downloadInfo => downloadInfo.Id == info.Id); if (elements is null) { context.DownloadInfos.Add(info); context.SaveChanges(); } context.States.Add(state); context.SaveChanges(); } })); }
private async void DownloadButtonClick(object sender, RoutedEventArgs e) { _info.Url = urlTextBox.Text; _info.LocalPath = $"{Guid.NewGuid().ToString()}_File"; try { await SendToDatabase(_info, new State { DownloadInfo = _info, Status = "Begin", DateTime = DateTime.Now }); await DownloadFile(_info.Url, _info.LocalPath); } catch (Exception exception) { MessageBox.Show(exception.Message); } MessageBox.Show("Файл установлен!"); _info = new DownloadInfo(); }
public MainWindow() { InitializeComponent(); _info = new DownloadInfo(); }