public static void AddAndSave <T>(this ObservableCollection <T> collection, T item) where T : class { var dbCommunicator = new DatabaseCommunicator(); dbCommunicator.Add(item); collection.Add(item); }
public void TestSaveRecommendationSuccessfullyWithNewUrl() { string link = "www.fakeurl4.com"; int count = 4; Assert.IsTrue(DatabaseCommunicator.SaveRecommendations(link, count)); DeleteRecommendation(link); }
public void TestAddUserSuccessfully() { Newtonsoft.Json.Linq.JObject response = DatabaseCommunicator.AddUser("*****@*****.**", "1"); Assert.AreEqual(response.GetValue("message").ToString(), "Success"); DeleteUser("*****@*****.**"); }
public ClubsTabControl() { InitializeComponent(); var dbCommun = new DatabaseCommunicator(); _clubs = new ObservableCollection <Club>(dbCommun.GetAll <Club>()); ClubsListBox.ItemsSource = _clubs; DataContext = this; }
public AdministrationTabControl() { InitializeComponent(); var communicator = new DatabaseCommunicator(); Clubs = communicator.GetAll <Club>(); ClubsComboBox.SelectedValue = communicator.Get <Club>(x => x.IsDefault).Id; DataContext = this; }
public PlayersAndMatchesControl() { InitializeComponent(); var dbCommunicator = new DatabaseCommunicator(); _players = new ObservableCollection <Player>(dbCommunicator.GetAll <Player>()); PlayersListBox.ItemsSource = _players; DataContext = this; }
public ManagerProfilesTab() { InitializeComponent(); var dbCommunicator = new DatabaseCommunicator(); _managerProfiles = new ObservableCollection <ManagerProfile>(dbCommunicator.GetAll <ManagerProfile>()); ManagerProfilesListBox.ItemsSource = _managerProfiles; DataContext = this; }
public void TestGetRecommendationSuccessfully() { string link = "www.fakeurl1.com"; DatabaseCommunicator.SaveRecommendations(link, 10); Assert.AreEqual(DatabaseCommunicator.SetRecommendations(link), 10); DeleteRecommendation(link); }
public void TestCheckRegistrationReturnsTrue() { string user = "******"; DatabaseCommunicator.AddUser(user, "3"); Assert.IsTrue(DatabaseCommunicator.CheckRegistration(user)); DeleteUser(user); }
public void TestSaveUrlUnsuccessfully() { string user = "******"; string url = "gpnotebook.com"; DatabaseCommunicator.email = user; Newtonsoft.Json.Linq.JObject response = DatabaseCommunicator.SaveURL(url); Assert.AreEqual(response.GetValue("message").ToString(), "User not found"); }
public void TestSaveQueryUnsuccessfully() { string user_not_in_db = "*****@*****.**"; string query = "liver failure"; DatabaseCommunicator.email = user_not_in_db; Newtonsoft.Json.Linq.JObject response = DatabaseCommunicator.SaveQuery(query); Assert.AreEqual(response.GetValue("message").ToString(), "User not found"); }
public NotesTabControl() { InitializeComponent(); var dbCommunicator = new DatabaseCommunicator(); _notes = new ObservableCollection <Note>(dbCommunicator.GetAll <Note>()); NotesListBox.ItemsSource = _notes; DataContext = this; EditDeletePair.Visibility = Visibility.Visible; SaveCancelPair.Visibility = Visibility.Collapsed; }
public void TestAddUserUnsuccessfully() { string user = "******"; DatabaseCommunicator.AddUser(user, "11"); Newtonsoft.Json.Linq.JObject response = DatabaseCommunicator.AddUser(user, "9"); Assert.AreEqual(response.GetValue("message").ToString(), "User already created."); DeleteUser(user); }
public AddPlayerDialog() { InitializeComponent(); var communicator = new DatabaseCommunicator(); PositionComboBox.ItemsSource = Enum.GetValues(typeof(PositionTypes)).Cast <PositionTypes>(); RoleComboBox.ItemsSource = Enum.GetValues(typeof(PlayerRoleTypes)).Cast <PlayerRoleTypes>(); DataContext = this; Clubs = communicator.GetAll <Club>(); ClubsComboBox.SelectedValue = communicator.Get <Club>(x => x.IsDefault).Id; }
public void TestSaveRecommendationSuccessfullyWithAlreadyExistingUrl() { string link = "www.fakeUrl5.com"; int count = 3; DatabaseCommunicator.SaveRecommendations(link, count); Assert.IsTrue(DatabaseCommunicator.SaveRecommendations(link, 4)); Assert.AreEqual(DatabaseCommunicator.SetRecommendations(link), 4); DeleteRecommendation(link); }
private void SaveEdit_ButtonClick(object sender, RoutedEventArgs e) { var dbCommunicator = new DatabaseCommunicator(); Cancel_ButtonClick(sender, e); if (NotesListBox.SelectedItem is Note selectedItem) { selectedItem.Message = TextBoxReadonly.Text; dbCommunicator.Get <Note>(x => x.Id == selectedItem.Id).Message = TextBoxReadonly.Text; dbCommunicator.SaveChanges(); } }
private void ResetDatabase_buttonClick(object sender, RoutedEventArgs e) { var confirmDialog = new ConfirmDialog() { Owner = Window.GetWindow(this) }; confirmDialog.ShowDialog(); if (confirmDialog.DialogResult != null && confirmDialog.DialogResult == true) { var dbCommun = new DatabaseCommunicator(); dbCommun.ResetDatabase(); } }
public void TestSaveQuerySuccessfully() { string user = "******"; string query = "chronic kidney disease"; DatabaseCommunicator.email = user; DatabaseCommunicator.AddUser(user, "9"); Newtonsoft.Json.Linq.JObject response = DatabaseCommunicator.SaveQuery(query); Assert.AreEqual(response.GetValue("message").ToString(), "Success"); DeleteQuery(user, query); DeleteUser(user); }
private void SetDefaultClub_Event(object sender, RoutedEventArgs e) { var dbComm = new DatabaseCommunicator(); var clubs = dbComm.GetAll <Club>(); foreach (var club in clubs) { club.IsDefault = false; } var selectedClub = clubs.First(x => x.Id == (int)ClubsComboBox.SelectedValue); selectedClub.IsDefault = true; dbComm.SaveChanges(); }
public void TestSaveUrlSuccessfully() { string user = "******"; string url = "gpnotebook.com"; DatabaseCommunicator.email = user; DatabaseCommunicator.AddUser(user, "7"); Newtonsoft.Json.Linq.JObject response = DatabaseCommunicator.SaveURL(url); Assert.AreEqual(response.GetValue("message").ToString(), "Success"); DeleteUrl(user, url); DeleteUser(user); }
private void UploadPhotoButton_Click(object sender, RoutedEventArgs e) { var fileDialog = new Microsoft.Win32.OpenFileDialog() { DefaultExt = ".png", Filter = "PNG Files (*.png)|*.png|JPEG Files (*.jpeg)|*.jpeg|JPG Files (*.jpg)|*.jpg", Multiselect = false, Title = "Upload Player Picture" }; var result = fileDialog.ShowDialog(); if (result.HasValue && result.Value) { var dbCommunicator = new DatabaseCommunicator(); var filename = fileDialog.FileName; } }
private void Delete_ButtonClick(object sender, RoutedEventArgs e) { var dbCommunicator = new DatabaseCommunicator(); var confirmDialog = new ConfirmDialog() { Owner = Window.GetWindow(this) }; confirmDialog.ShowDialog(); if (confirmDialog.DialogResult != null && confirmDialog.DialogResult == true) { if (NotesListBox.SelectedItem is Note selectedItem) { dbCommunicator.Remove <Note>(x => x.Id == selectedItem.Id); _notes.Remove(selectedItem); ResetTextBox(TextBoxReadonly); } } }
/// <summary> /// Gets an Azure SQL Database by name /// </summary> /// <param name="resourceGroupName">The name of the resource group</param> /// <param name="serverName">The name of the Azure SQL Server</param> /// <param name="databaseName">The name of the Azure SQL Database</param> /// <returns>The Azure SQL Database object</returns> internal AzureSqlDatabaseModel GetDatabase(string resourceGroupName, string serverName, string databaseName) { var resp = DatabaseCommunicator.Get(resourceGroupName, serverName, databaseName); return(AzureSqlDatabaseAdapter.CreateDatabaseModelFromResponse(resourceGroupName, serverName, resp)); }
public void TestCheckRegistrationReturnsFalse() { Assert.IsFalse(DatabaseCommunicator.CheckRegistration("*****@*****.**")); }
public void TestCheckConnectionFalse() { // RUN THIS WHILE DATABASE IS NOT CONNECTED SINCE WE WANT IT TO RETURN FALSE. DatabaseCommunicator.CheckIfConnected(); Assert.IsFalse(Program.connected_to_database); }
public void TestCheckConnection() { DatabaseCommunicator.CheckIfConnected(); Assert.IsTrue(Program.connected_to_database); }
public void TestGetRecommendationWithUrlNotInDB() { Assert.AreEqual(DatabaseCommunicator.SetRecommendations("www.fakeurl2.com"), 0); }
protected async void Page_Load(object sender, EventArgs e) { if (Session["userSession"] == null) { Response.Redirect("/Login.aspx?redirect=MakeAListing.aspx", false); return; } filteredWords_ = (await DatabaseCommunicator.GetFilteredWords(Guid.NewGuid().ToString())).Split('|').ToList(); thisListing = new Listing(); if (IsPostBack && FileUpload1.PostedFiles.SafeCount() > 0) { try { thisListing.imagesBytes = new List <byte[]>(); int imageCount = 0; for (int i = 0; i < Math.Min(FileUpload1.PostedFiles.Count, 6); i++) { string b64 = ""; var file = FileUpload1.PostedFiles[i]; if (file.ContentLength / 1024 / 1024 > 20) { continue; } if (file.FileName.Contains("png")) { b64 = "data:image/png;charset=utf-8;base64, "; } else if (file.FileName.ToLower().Contains("jpg") || file.FileName.ToLower().Contains("jpeg")) { b64 = "data:image/jpeg;charset=utf-8;base64, "; } else { continue; } byte[] fileData = null; using (var binaryReader = new BinaryReader(Request.Files[i].InputStream)) { fileData = binaryReader.ReadBytes(Request.Files[i].ContentLength); } b64 += System.Convert.ToBase64String(fileData); thisListing.imagesBytes.Add(fileData); if (imageCount == 0) { item1.Src = b64; } if (imageCount == 1) { item2.Src = b64; } if (imageCount == 2) { item3.Src = b64; } if (imageCount == 3) { item4.Src = b64; } if (imageCount == 4) { item5.Src = b64; } if (imageCount == 5) { item6.Src = b64; } imageCount++; } if (imageCount < 6) { item6.Src = ""; } if (imageCount < 5) { item5.Src = ""; } if (imageCount < 4) { item4.Src = ""; } if (imageCount < 3) { item3.Src = ""; } if (imageCount < 2) { item2.Src = ""; } if (thisListing.imagesBytes.SafeCount() > 0) { Session["images"] = thisListing.imagesBytes; } } catch { } } var session = (SessionObject)Session["userSession"]; bool isEditing = false; try { var editId = Request.QueryString["editingId"].ToString(); var listing = (await DatabaseCommunicator.RetrieveListing(session.auth, new List <string>(new string[] { editId }), ListingStatus.Active)).First(); if (listing.sellerUsername == session.user.Id) { title.InnerText = "Edit Listing"; isEditing = true; editingListing = listing; if (!IsPostBack) { List <byte[]> bytes = new List <byte[]>(); foreach (var ah in listing.images) { bytes.Add(await WebCrawler.ReadBytes(ah)); } Session["images"] = bytes; try { if (bytes.Count > 0) { item1.Src = listing.images[0]; } if (bytes.Count > 1) { item2.Src = listing.images[1]; } if (bytes.Count > 2) { item3.Src = listing.images[2]; } if (bytes.Count > 3) { item4.Src = listing.images[3]; } if (bytes.Count > 4) { item5.Src = listing.images[4]; } if (bytes.Count > 5) { item6.Src = listing.images[5]; } } catch { } titleBox.Text = listing.title; brandBox.Text = listing.brand; descriptionBox.Text = listing.description; ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "tmp", "<script type='text/javascript'>setcategory('" + listing.category + "'); conditionClick('" + listing.condition + "');</script>", false); TextBox1.Text = listing.price.ToString(); TextBox2.Text = listing.shippingPrice.ToString(); } } else { Response.Redirect("/MakeAListing.aspx", false); } } catch { } }
public async void publish_listing(object sender, EventArgs e) { if (ValidateListing()) { return; } var listing = new Listing(); try { var session = (SessionObject)Session["userSession"]; listing.imagesBytes = (List <byte[]>)Session["images"]; var thumbnailBytes = listing.imagesBytes.First(); System.IO.MemoryStream myMemStream = new System.IO.MemoryStream(thumbnailBytes); System.Drawing.Image fullsizeImage = System.Drawing.Image.FromStream(myMemStream); System.Drawing.Image newImage = fullsizeImage.GetThumbnailImage(210, 280, null, IntPtr.Zero); System.IO.MemoryStream myResult = new System.IO.MemoryStream(); newImage.Save(myResult, System.Drawing.Imaging.ImageFormat.Jpeg); for (int i = 0; i < listing.imagesBytes.Count; i++) { System.IO.MemoryStream myMemStreamX = new System.IO.MemoryStream(listing.imagesBytes[i]); System.Drawing.Image fullsizeImageX = System.Drawing.Image.FromStream(myMemStreamX); System.Drawing.Image newImageX = fullsizeImageX.GetThumbnailImage(900, 1200, null, IntPtr.Zero); System.IO.MemoryStream myResultX = new System.IO.MemoryStream(); newImageX.Save(myResultX, System.Drawing.Imaging.ImageFormat.Jpeg); listing.imagesBytes[i] = myResultX.ToArray(); } listing.thumbnailBytes = myResult.ToArray(); listing.Id = editingListing != null ? editingListing.Id : Guid.NewGuid().ToString(); listing.brand = brandBox.Text; listing.description = descriptionBox.Text; listing.title = titleBox.Text; listing.category = category.Value; listing.condition = condition.Value; listing.price = Convert.ToInt64(TextBox1.Text.Replace(".00", "")); listing.shippingPrice = string.IsNullOrEmpty(TextBox2.Text.Replace(".00", "")) ? 0 : Convert.ToInt64(TextBox2.Text.Replace(".00", "")); listing.sellerUsername = session.user.Id; listing.sellerPayPal = ""; if (editingListing != null) { var succes = await DatabaseCommunicator.EditListing(session.auth, listing); if (succes.listingUpdated) { Response.Redirect("/MyProfile.aspx", false); } else { alert.InnerText = succes.errorMessage; alert.Visible = true; return; } } var success = await DatabaseCommunicator.AddListing(session.auth, listing); if (success.listingPosted) { Response.Redirect("/MyProfile.aspx", false); } else { alert.InnerText = success.errorMessage; alert.Visible = true; return; } } catch { } }