private async void LogIn_Load(object sender, EventArgs e) { var isLoggedIn = await Infrastructure.CheckIfLoggedIn(); if (isLoggedIn.ErrorCode) { var metadetaErrorModel = await Infrastructure.GetMetadata(); MetaDataResponse metadata = (MetaDataResponse)metadetaErrorModel.Object; Wine_Application wineApp = new Wine_Application(metadata); wineApp.Show(); this.Hide(); } else if (!string.IsNullOrEmpty(isLoggedIn.Message)) { MessageBox.Show(isLoggedIn.Message, "Fel"); btnLogin.Enabled = true; btnSignUpInLogin.Enabled = true; } else { btnLogin.Enabled = true; btnSignUpInLogin.Enabled = true; } }
private async void btnAddDistrict_Click(object sender, EventArgs e) { var selectedCountry = (CountryResponse)cbOriginCountry.SelectedItem; var selectedRegion = (RegionResponse)cbOriginRegion.SelectedItem; var addCountryResponse = await Infrastructure.AddDistrict(tbNewDistrict.Text, selectedRegion.RegionId); if (addCountryResponse.ErrorCode) { var metadetaErrorModel = await Infrastructure.GetMetadata(); MetaDataResponse metadata = (MetaDataResponse)metadetaErrorModel.Object; Metadata = metadata; ShowCountriesAddNewWine(); cbOriginCountry.SelectedIndex = cbOriginCountry.FindStringExact(selectedCountry.CountryName); cbOriginRegion.SelectedIndex = cbOriginRegion.FindStringExact(selectedRegion.RegionName); cbOriginDistrict.SelectedIndex = cbOriginDistrict.FindStringExact(tbNewDistrict.Text); } else if (!string.IsNullOrEmpty(addCountryResponse.Message)) { MessageBox.Show(addCountryResponse.Message, "Fel"); } }
private async void btnAddCountry_Click(object sender, EventArgs e) { var addCountryResponse = await Infrastructure.AddCountry(tbNewCountry.Text); if (addCountryResponse.ErrorCode) { var metadetaErrorModel = await Infrastructure.GetMetadata(); MetaDataResponse metadata = (MetaDataResponse)metadetaErrorModel.Object; Metadata = metadata; ShowCountriesAddNewWine(); cbOriginCountry.SelectedIndex = cbOriginCountry.FindStringExact(tbNewCountry.Text); } else if (!string.IsNullOrEmpty(addCountryResponse.Message)) { MessageBox.Show(addCountryResponse.Message, "Fel"); } }
private async void btnSignup_Click(object sender, EventArgs e) { var isSignedUp = await Infrastructure.SignUp(tbEmailSignup.Text, tbDisplayName.Text, tbPasswordSignUp.Text, tbRepeatPasswordSignUp.Text); if (isSignedUp.ErrorCode) { var metadetaErrorModel = await Infrastructure.GetMetadata(); MetaDataResponse metadata = (MetaDataResponse)metadetaErrorModel.Object; Wine_Application wineApp = new Wine_Application(metadata); wineApp.Show(); this.Hide(); } else if (!string.IsNullOrEmpty(isSignedUp.Message)) { MessageBox.Show(isSignedUp.Message, "Fel"); } }
private async void btnLogin_Click(object sender, EventArgs e) { //tbEmailLogin.Text = "*****@*****.**"; //tbPasswordLogin.Text = "123456"; ErrorModel loggedInSuccessfully = await Infrastructure.LogInWithEmailAndPassword(tbEmailLogin.Text, tbPasswordLogin.Text); if (loggedInSuccessfully.ErrorCode) { var metadetaErrorModel = await Infrastructure.GetMetadata(); MetaDataResponse metadata = (MetaDataResponse)metadetaErrorModel.Object; Wine_Application wineApp = new Wine_Application(metadata); wineApp.Show(); this.Hide(); } else if (!string.IsNullOrEmpty(loggedInSuccessfully.Message)) { MessageBox.Show(loggedInSuccessfully.Message, "Fel"); } }
public static async Task <ErrorModel> GetMetadata() { MetaDataResponse responseBodyJson = new MetaDataResponse(); var url = Links.baseLink + Links.metadata; var token = await GetToken(); var responseErrorModel = await RestVerbs.Get(url, token); if (responseErrorModel.ErrorCode) { responseBodyJson = JsonConvert.DeserializeObject <MetaDataResponse>((string)responseErrorModel.Object); } else { return(responseErrorModel); } return(new ErrorModel { ErrorCode = true, Message = null, Object = responseBodyJson }); }
public Wine_Application(MetaDataResponse _metadata) { InitializeComponent(); Metadata = _metadata; }
private static async Task <ErrorModel> GetWineList(string url, string startsWith, long countryId, long regionId) { var shelves = await GetUsersShelves(); var metadetaErrorModel = await Infrastructure.GetMetadata(); MetaDataResponse metadata = (MetaDataResponse)metadetaErrorModel.Object; if (!string.IsNullOrEmpty(startsWith)) { url = url.Replace("startswith=", "startswith=" + startsWith); } if (countryId > 0) { url = url.Replace("countryid=-1", "countryid=" + countryId); } if (regionId > 0) { url = url.Replace("regionid=-1", "regionid=" + regionId); } ICollection <WineListResponse> responseBodyJson = new List <WineListResponse>(); var token = await GetToken(); var responseErrorModel = await RestVerbs.Get(url, token); if (responseErrorModel.ErrorCode) { responseBodyJson = JsonConvert.DeserializeObject <ICollection <WineListResponse> >((string)responseErrorModel.Object); } else { return(responseErrorModel); } var wineTickets = new List <WineTicket>(); responseBodyJson = responseBodyJson.Take(10).ToList(); foreach (var wine in responseBodyJson) { //List<VintageResponse> vintages = await GetVintages(wine.WineId); List <InventoryTicket> inves = new List <InventoryTicket>(); if (wine.Vintages != null) { foreach (var inv in wine.Vintages) { inves.Add(new InventoryTicket(shelves) { Year = inv != null ? inv.Year : "", CurrentAmount = inv != null ? inv.Amount.ToString() : "", Shelf = inv.ShelfName, //Grade = (inv.Grade != null && inv.Grade.Grade >= 1 && inv.Grade.Grade <= 5) ? inv.Grade.Grade.ToString() : "-", Grade = "--", InventoryId = inv.InventoryId, ShelfId = inv.ShelfId, }); } } else { inves.Add(new InventoryTicket(shelves) { CurrentAmount = "-", Year = "-", Grade = "--", Shelf = "-" }); } //string origin = wine.Country.CountryName; //// if (wine.Region.RegionName != "Okänt region") //origin += " >> \r\n" + wine.Region.RegionName; //// if (wine.District.DistrictName != "Okänt distrikt") //origin += " >> \r\n" + wine.District.DistrictName; string grapes = ""; foreach (var grape in wine.WineGrapes) { grapes += grape.GrapeName + ((grape.Percent > 0) ? " " + grape.Percent + "%" + "\r\n" : "\r\n"); } wineTickets.Add(new WineTicket(metadata) { WineId = wine.WineId, WineName = wine.WineName, Alcohol = wine.Alcohol.ToString() + '%', Bottles = inves, Country = wine.Country.CountryName, Region = wine.Region.RegionName, District = wine.District.DistrictName, Producer = wine.Producer, Grapes = grapes, WinePic = wine.ImageThumbnail }); } return(new ErrorModel { ErrorCode = true, Message = null, Object = wineTickets }); }
public WineTicket(MetaDataResponse _metadata) { InitializeComponent(); Metadata = _metadata; }