Skip to content
Permalink
Browse files
Added full documentation
  • Loading branch information
elgezirn committed Nov 17, 2020
1 parent ab7cc8c commit 4c92e26a04c9639e504e58e0e6a51cf29010771d
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 55 deletions.
@@ -12,12 +12,13 @@ namespace Trady.Views
{
InitializeComponent();
}

// change Is Accepted field to true for the specfifc offer
async void acceptbtn_Clicked(System.Object sender, System.EventArgs e)
{
{ //connecting o the database
using (SQLiteConnection conn = new SQLiteConnection(App.FilePath))
{
{ //get the offerId through binding context
int OfferID = int.Parse(offerId.Text);
//get the details of the offer by using the offerId obtained in the previous step
var currentOffer = conn.Table<Offer>().First(o => o.OfferId == OfferID);
conn.Update(new Offer {
OfferId = currentOffer.OfferId,
@@ -33,17 +34,18 @@ namespace Trady.Views
IsRecieved = currentOffer.IsRecieved
});

var check = conn.Table<Offer>().First(o => o.OfferId == OfferID);
}

} //navigate to MyTrades Page
await Navigation.PushAsync(new MyTradesPage());
}

// change ISDeclined field to true for the soecific offer
async void declinebtn_Clicked(System.Object sender, System.EventArgs e)
{

//connect to database
using (SQLiteConnection conn = new SQLiteConnection(App.FilePath))
{
{ // get offer id through binding cintext
int OfferID = int.Parse(offerId.Text);
//get the details of the specific offer using th offerid Obtained in the previous step
var currentOffer = conn.Table<Offer>().First(o => o.OfferId == OfferID);
conn.Update(new Offer
{
@@ -60,8 +62,9 @@ namespace Trady.Views
IsRecieved = currentOffer.IsRecieved
});

var check = conn.Table<Offer>().First(o => o.OfferId == OfferID);

}
//navigate to MyTrades Page
await Navigation.PushAsync(new MyTradesPage());
}
}
@@ -18,17 +18,15 @@ namespace Trady.Views

async void PostOfferbtn_Clicked(System.Object sender, System.EventArgs e)
{


//get current user id
// connecting to database
using (SQLiteConnection conn = new SQLiteConnection(App.FilePath))
{ //getting the trade ID and the user id who posted the trade
int TradeId = int.Parse(tradeId.Text);
int tradeUserId = int.Parse(userId.Text);
//Getting the active user by getting the user with currentUser flag set to true
var currentUser = conn.Table<User>().First(r => r.CurrentUser == true);

// creating a new offer with isSubmitted field to true wfor the user that is submitting the offer
// creating a new offer with isSubmitted field to true for the user that is submitting the offer
Offer offer1 = new Offer()
{
UserId = currentUser.UserId,
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using SQLite;

using Xamarin.Forms;
using Trady.Models;

@@ -13,17 +12,16 @@ namespace Trady.Views
{
InitializeComponent();
}

// overriding onAppearing method
protected override void OnAppearing()
{
base.OnAppearing();


using (SQLiteConnection conn = new SQLiteConnection(App.FilePath))
{
// Getting the active user by getting the user with currentUser flag set to true
var currentUser = conn.Table<User>().First(r => r.CurrentUser == true);
//get the currentUserOffers
//get the currentUserOffers by getting the offers with the current user id
var currentUserOffers = conn.Table<Offer>().Where(i => i.UserId == currentUser.UserId);

//get submitted offers and display them in submittedOffers collection view
@@ -36,18 +34,17 @@ namespace Trady.Views
}

}

// navigate to post trade page once button is pressed
async void post_Clicked(System.Object sender, System.EventArgs e)
{
await Navigation.PushAsync(new PostTradePage());
}



// navigate to another page when coolection view item is selected in the recieved offers to accept or decline the offer
async void recievedOffers_SelectionChanged(System.Object sender, Xamarin.Forms.SelectionChangedEventArgs e)
{
await Navigation.PushAsync(new AcceptDeclineOfferPage
{
{ //setting the binding context to the offer detail
BindingContext = recievedOffersCollectionView.SelectedItem as Offer
});
}
@@ -13,16 +13,15 @@ namespace Trady.Views
InitializeComponent();
}



async void PostTradebtn_Clicked(System.Object sender, System.EventArgs e)
{

//get current user id
//connect to data-base
using (SQLiteConnection conn = new SQLiteConnection(App.FilePath))
{
//get current user id
var currentUser = conn.Table<User>().First(r => r.CurrentUser == true);

// create a new trade entry with user inputed info
Trade trade = new Trade()
{
UserId = currentUser.UserId,
@@ -33,11 +32,12 @@ namespace Trady.Views
Completed = false,
OffersPlaced = 0
};

// cretae new table or connect to it if exists
conn.CreateTable<Trade>();
//insert row to the table
int rowsAdded = conn.Insert(trade);
}

// navigate to My Trades Page
await Navigation.PushAsync(new MyTradesPage());
}
}
@@ -12,23 +12,25 @@ namespace Trady.Views
{
InitializeComponent();
}

// overriding on Appear method
protected override void OnAppearing()
{
base.OnAppearing();
// connect to database
using (SQLiteConnection conn = new SQLiteConnection(App.FilePath))
{
{ // create table or connet if exists
conn.CreateTable<User>();
// get current user
var user = conn.Table<User>().FirstOrDefault(r => r.CurrentUser == true);

// setting the values on screen to match databse values
userName.Text = user.Name;
userImage.Source = user.Picture;

}

}


// Navigation bar routuing
void tradesPagebtn_Clicked(System.Object sender, System.EventArgs e)
{

@@ -14,24 +14,25 @@ namespace Trady.Views
public TradesPage()
{
InitializeComponent();

}

// overriding onAppearing method
protected override void OnAppearing()
{
base.OnAppearing();
// connecting to the data base
using (SQLiteConnection conn = new SQLiteConnection(App.FilePath))
{
{ // create table or coonect to if exists
conn.CreateTable<Trade>();
// getting all trades as a list
var trades = conn.Table<Trade>().ToList();
//setting the carousel view source to the list
tradesCarouselView.ItemsSource = trades;
}

}

async void makeOfferbtn_Clicked(System.Object sender, System.EventArgs e)
{

//navigate to makeofferpage while setting the binding context to the selected trade info
await Navigation.PushAsync(new MakeOfferPage {

BindingContext = tradesCarouselView.CurrentItem as Trade
@@ -15,32 +15,32 @@ namespace Trady.Views

{
InitializeComponent();

// calling Fb Login API
WebView.Source = "https://www.facebook.com/v9.0/dialog/oauth?client_id=1272538809769102&redirect_uri=https://www.facebook.com/connect/login_success.html&response_type=token";
// calling event handeler
WebView.Navigated += WebView_Navigated;

}
private void WebView_Navigated(object sender, WebNavigatedEventArgs e)
{
{ // get recieved url
var AccessURL = e.Url;
if (AccessURL.Contains("access_token"))
{
{ // replace text before access token with an empty string(to get the access token alone)
AccessURL = AccessURL.Replace("https://www.facebook.com/connect/login_success.html#access_token=", string.Empty);
var accessToken = AccessURL.Split('&')[0];
HttpClient client = new HttpClient();
// responding with the access url and requestd user info
var response = client.GetStringAsync("https://graph.facebook.com/me?fields=name,picture,email,id&access_token=" + accessToken).Result;


// Deseralizing api response in Jason Format
var Data = JsonConvert.DeserializeObject<FacebookProfile>(response);


//connecto to database to check if user is already registered
using (SQLiteConnection conn = new SQLiteConnection(App.FilePath))
{


var Users = conn.Table<User>().ToList();
//set user with Current user true to false
//set user with Current user true to false( cuurent user is used to dertmine the user currently accessing the application)
var setActiveToFalse = conn.Table<User>().FirstOrDefault(r => r.CurrentUser == true);
if (setActiveToFalse != null)
{
@@ -54,10 +54,7 @@ namespace Trady.Views

});
}


var check = conn.Table<User>().FirstOrDefault(r => r.CurrentUser == false);

// creating a new user if first time accessing aplication by checking if fb id is already stored in database
var loggedInUser = conn.Table<User>().FirstOrDefault(c => c.FacebookId == Data.Id);

if(loggedInUser == null)
@@ -74,12 +71,12 @@ namespace Trady.Views

};


// add user if not registered
conn.CreateTable<User>();
int rowsAdded = conn.Insert(user);

}
//set current user to true to the logged in user
//set current user to true for the logged in user
var activeUser = conn.Table<User>().FirstOrDefault(c => c.FacebookId == Data.Id);
//var activeUser = conn.Table<User>().FirstOrDefault(c => c.UserId == 0);
conn.Update(new User {
@@ -90,14 +87,9 @@ namespace Trady.Views
Picture = activeUser.Picture,

});
//check if current user has true currentUser flag
var beforeCurrentActiveUsers = conn.Table<User>().First(r => r.CurrentUser == true);

}




//Navigate to trades Page
Navigation.PushAsync(new TradesPage());

}

0 comments on commit 4c92e26

Please sign in to comment.