public void ChangeStringSpaces() { foreach (Notification notification in this.notificationsList) { notification.MessageType = ReadStringConverter.ChangeGetString(notification.MessageType); } }
public void ChangeStringSpaces() { foreach (Comment comment in this.commentsList) { comment.UserComment = ReadStringConverter.ChangeGetString(comment.UserComment); } }
public void ChangeStringSpaces(byte option) { switch (option) { case 1: foreach (User user in this.usersList) { user.Name = ReadStringConverter.ChangeGetString(user.Name); } break; case 2: foreach (Recipe recipe in this.recipesList) { recipe.Name = ReadStringConverter.ChangeGetString(recipe.Name); recipe.CookingSpan = ReadStringConverter.ChangeGetString(recipe.CookingSpan); recipe.EatingTime = ReadStringConverter.ChangeGetString(recipe.EatingTime); recipe.Ingredients = ReadStringConverter.ChangeGetString(recipe.Ingredients); recipe.Steps = ReadStringConverter.ChangeGetString(recipe.Steps); recipe.Tags = ReadStringConverter.ChangeGetString(recipe.Tags); } break; } }
private async void SendComment() { if (string.IsNullOrEmpty(this.TextComment)) { this.BCComment = ColorsFonts.errorColor; return; } Response checkConnection = await ApiService.CheckConnection(); if (!checkConnection.IsSuccess) { await Application.Current.MainPage.DisplayAlert( "Error", "Check your internet connection", "Accept"); return; } string recipeName = ReadStringConverter.ChangePostString(this.UserRecipe.Name); string recipeComment = ReadStringConverter.ChangePostString(this.TextComment); string queryUrl = $"/users/new_notif?emisorUser={loggedUser.Email}&recieverUser={UserRecipe.Author}¬ifType=0&recipe={recipeName}&newComment={recipeComment}"; Notification notification = new Notification { EmisorUser = loggedUser.Email, RecieverUser = UserRecipe.Author, NotifType = 0, RecipeName = recipeName, NewComment = recipeComment }; Response response = await ApiService.Post <Notification>( "http://localhost:8080/CookTime.BackEnd", "/api", queryUrl, notification, false); if (!response.IsSuccess) { await Application.Current.MainPage.DisplayAlert( "Error", "Action can't be done", "Ok"); return; } this.TextComment = string.Empty; this.loadComments(); }
public void ChangeStringSpaces() { foreach (Recipe recipe in this.recipesList) { recipe.Name = ReadStringConverter.ChangeGetString(recipe.Name); recipe.CookingSpan = ReadStringConverter.ChangeGetString(recipe.CookingSpan); recipe.EatingTime = ReadStringConverter.ChangeGetString(recipe.EatingTime); recipe.Ingredients = ReadStringConverter.ChangeGetString(recipe.Ingredients); recipe.Steps = ReadStringConverter.ChangeGetString(recipe.Steps); recipe.Tags = ReadStringConverter.ChangeGetString(recipe.Tags); } }
private async Task <Response> LoadCompanyData() { //Check internet connection var connection = await ApiService.CheckConnection(); if (!connection.IsSuccess) { this.IsRefreshing = false; await Application.Current.MainPage.DisplayAlert( "Error", connection.Message, "Accept"); return(null); } //Creates the url needed to getthe information var url = "/companies/" + this.Email; //Asks the server for the list of recipes var response = await ApiService.Get <Company>( "http://localhost:8080/CookTime.BackEnd", "/api", url); if (!response.IsSuccess) { this.IsRefreshing = false; await Application.Current.MainPage.DisplayAlert( //if something goes wrong the page displays a message "Welcome to CookTime", "Add new recipes to have a complete MyMenu", "Accept"); return(null); } //Copies the list loaded from the server this.loggedCompany = (Company)response.Result; this.ServiceHours = "Service Hours: " + ReadStringConverter.ChangeGetString(this.loggedCompany.ServiceSchedule); this.ContactMethod = "Contact Method: " + ReadStringConverter.ChangeGetString(this.loggedCompany.Contact); this.Latitud = this.loggedCompany.Location[0]; this.Longitud = this.loggedCompany.Location[1]; this.Admins = this.loggedCompany.Admins; return(null); }
//COMMAND METHODS /* * Validates every single information given in the form defined in the SignUpPage.XAML * and if everything is correct creates an account */ private async void CreateAccount() { //Activates activity indicador IsRunning = true; if (string.IsNullOrEmpty(this.TextName)) { IsRunning = false; BCName = ColorsFonts.errorColor; await Application.Current.MainPage.DisplayAlert("Error", "You must enter a name", "Ok"); return; } if (string.IsNullOrEmpty(this.TextBirthday)) { IsRunning = false; BCBirthday = ColorsFonts.errorColor; await Application.Current.MainPage.DisplayAlert("Error", "You must enter a birth date", "Ok"); return; } if (string.IsNullOrEmpty(this.TextEmail)) { IsRunning = false; BCEmail = ColorsFonts.errorColor; await Application.Current.MainPage.DisplayAlert("Error", "You must enter an Email", "Ok"); return; } if (string.IsNullOrEmpty(this.TextPassword)) { IsRunning = false; BCPassword = ColorsFonts.errorColor; await Application.Current.MainPage.DisplayAlert("Error", "You must enter a password", "Ok"); return; } if (string.IsNullOrEmpty(this.TextConfirmPassword)) { IsRunning = false; BCConfirmPassword = ColorsFonts.errorColor; await Application.Current.MainPage.DisplayAlert("Error", "You must enter a confirmation password", "Ok"); return; } //Makes sure that the user is over 16 years old if (!(IsOverSixteen())) { IsRunning = false; BCBirthday = ColorsFonts.errorColor; await Application.Current.MainPage.DisplayAlert("Error", $"You must be over 16 years old", "Ok"); //BCBirthday = ColorsFonts.backGround; return; } //Makes sure that the email written has the format of an email this.match = emailRegex.Match(TextEmail); if (!(match.Success)) { IsRunning = false; BCEmail = ColorsFonts.errorColor; await Application.Current.MainPage.DisplayAlert("Error", "You must enter a valid Email", "Ok"); return; } //Validates that the password and confirmation password match if (this.TextPassword != this.TextConfirmPassword) { IsRunning = false; BCPassword = ColorsFonts.errorColor; BCConfirmPassword = ColorsFonts.errorColor; await Application.Current.MainPage.DisplayAlert("Error", "The confirmation password doesn't match", "Ok"); return; } //Checks the internet connection before interacting with the server Response checkConnection = await ApiService.CheckConnection(); if (!checkConnection.IsSuccess) { IsRunning = false; await Application.Current.MainPage.DisplayAlert( "Error", "Check your internet connection", "Accept"); return; } //Changes the spacing in the user name this.TextName = ReadStringConverter.ChangePostString(this.TextName); string controller = "/users/" + this.TextEmail; //Asking for the account information Response checkEmail = await ApiService.Get <User>( //Tries to get the account information "http://localhost:8080/CookTime.BackEnd", "/api", controller); //Checks if the email already exists (it doesn't have to) if (checkEmail.IsSuccess) { IsRunning = false; this.BCEmail = ColorsFonts.errorColor; await Application.Current.MainPage.DisplayAlert( "Error", "This email is already registered", "Accept"); this.BCEmail = ColorsFonts.backGround; return; } if (this.IsCompany) { if (string.IsNullOrEmpty(this.TextContactMethods)) { IsRunning = false; BCContactMethods = ColorsFonts.errorColor; await Application.Current.MainPage.DisplayAlert("Error", "You must enter the company contact methods", "Ok"); return; } if (string.IsNullOrEmpty(this.TextAddressLat)) { IsRunning = false; BCAddress = ColorsFonts.errorColor; await Application.Current.MainPage.DisplayAlert("Error", "You must enter the company adress latitud", "Ok"); return; } if (string.IsNullOrEmpty(this.TextAddressLon)) { IsRunning = false; BCAddress = ColorsFonts.errorColor; await Application.Current.MainPage.DisplayAlert("Error", "You must enter the company adress longitud", "Ok"); return; } if (string.IsNullOrEmpty(this.TextServiceHours)) { IsRunning = false; BCServiceHours = ColorsFonts.errorColor; await Application.Current.MainPage.DisplayAlert("Error", "You must enter the company service hours", "Ok"); return; } this.TextContactMethods = ReadStringConverter.ChangePostString(this.TextContactMethods); this.TextServiceHours = ReadStringConverter.ChangePostString(this.TextServiceHours); var address2 = this.TextAddressLat + "," + this.TextAddressLon; Company company = new Company { Email = this.TextEmail, Name = this.TextName, Password = this.TextPassword, Contact = this.TextContactMethods, ServiceSchedule = this.TextServiceHours, }; string queryUrlC = "/companies?email=" + this.TextEmail + "&password="******"&name=" + this.TextName + "&location=" + address2 + "&contact=" + this.TextContactMethods + "&serviceSchedule=" + this.TextServiceHours; //Posts the Company Response responseC = await ApiService.Post <Company>( "http://localhost:8080/CookTime.BackEnd", "/api", queryUrlC, company, true); if (!responseC.IsSuccess) { IsRunning = false; await Application.Current.MainPage.DisplayAlert( "Error", "Something was wrong", "Accept"); return; } } //Creates the user account with the data given User user = new User { Email = this.TextEmail, Name = this.TextName, Age = this.TextAge, Password = this.TextPassword, }; //Generates the query url string queryUrl = "/users?email=" + this.TextEmail + "&password="******"&name=" + this.TextName + "&age=" + this.TextAge + "&company=" + this.IsCompany; //if (this.IsCompany == true) //{ // queryUrl += "&company=true"; //} //Posts the account Response response = await ApiService.Post <User>( "http://localhost:8080/CookTime.BackEnd", "/api", queryUrl, user, true); if (!response.IsSuccess) { IsRunning = false; await Application.Current.MainPage.DisplayAlert( "Error", "Something was wrong", "Accept"); return; } User loggedUser = (User)response.Result; this.TextName = string.Empty; this.TextEmail = string.Empty; this.TextPassword = string.Empty; this.TextConfirmPassword = string.Empty; IsRunning = false; //The new user has been created, it can enter to the tabbed page MainViewModel.getInstance().TabbedHome = new TabbedHomeViewModel(loggedUser); await Application.Current.MainPage.Navigation.PushAsync(new TabbedHomePage()); }
private async void Share() { if (string.IsNullOrEmpty(this.TextRecipeName)) { BCRecipeName = ColorsFonts.errorColor; await Application.Current.MainPage.DisplayAlert("Error", "You must enter the recipe name", "Ok"); return; } if (string.IsNullOrEmpty(this.TextIngredients)) { BCIngredients = ColorsFonts.errorColor; await Application.Current.MainPage.DisplayAlert("Error", "You must enter the ingredients", "Ok"); return; } if (string.IsNullOrEmpty(this.TextInstructions)) { BCInstructions = ColorsFonts.errorColor; await Application.Current.MainPage.DisplayAlert("Error", "You must enter the instructions", "Ok"); return; } if (string.IsNullOrEmpty(this.TextTags)) { BCTags = ColorsFonts.errorColor; await Application.Current.MainPage.DisplayAlert("Error", "You must enter some tags", "Ok"); return; } if (string.IsNullOrEmpty(this.TextPrice)) { BCPrice = ColorsFonts.errorColor; await Application.Current.MainPage.DisplayAlert("Error", "You must enter the price", "Ok"); return; } var checkConnection = await ApiService.CheckConnection(); //Checks the internet connection before interacting with the server if (!checkConnection.IsSuccess) { await Application.Current.MainPage.DisplayAlert( "Error", "Check your internet connection", "Accept"); return; } //Changes the spacing on every string that is being uploaded this.TextRecipeName = ReadStringConverter.ChangePostString(this.TextRecipeName); this.preparationTime = $"{this.DurationHourValue} h and {this.DurationMinutesValue} min"; this.preparationTime = ReadStringConverter.ChangePostString(this.preparationTime); this.TextDishTime = ReadStringConverter.ChangePostString(this.TextDishTime); this.TextIngredients = ReadStringConverter.ChangePostString(this.TextIngredients); this.TextInstructions = ReadStringConverter.ChangePostString(this.TextInstructions); this.TextTags = ReadStringConverter.ChangePostString(this.TextTags); var recipe = new Recipe { Name = this.TextRecipeName, Author = this.loggedUser.Email, Type = this.TextDishType, CookingSpan = this.preparationTime, Portions = this.PortionsValue, EatingTime = this.TextDishTime, Tags = this.TextTags, Ingredients = this.TextIngredients, Steps = this.TextInstructions, Price = this.TextPrice, Difficulty = this.DifficultyValue, Punctuation = 0 }; //Generates the query url var queryUrl = "/recipes?name=" + this.TextRecipeName + "&author=" + this.loggedUser.Email + "&type=" + this.TextDishType + "&cookingSpan=" + this.preparationTime + "&portions=" + this.PortionsValue + "&eatingTime=" + this.TextDishTime + "&tags=" + this.TextTags + "&ingredients=" + this.TextIngredients + "&steps=" + this.TextInstructions + "&price=" + this.TextPrice + "&difficulty=" + this.DifficultyValue + "&punctuation=0"; //Posts the recipe var response = await ApiService.Post <Recipe>( "http://localhost:8080/CookTime.BackEnd", "/api", queryUrl, recipe, false); if (!response.IsSuccess) { await Application.Current.MainPage.DisplayAlert( "Error", response.Message, "Accept"); return; } if (this.imageByteArray != null) { string arrayConverted = Convert.ToBase64String(this.imageByteArray); this.imageByteArray = null; var recipeImage = new RecipeImage { RecipeName = this.TextRecipeName, Image = arrayConverted }; var responseImage = await ApiService.Put <RecipeImage>( "http://localhost:8080/CookTime.BackEnd", "/api", "/recipes/image", recipeImage, false); if (!responseImage.IsSuccess) { await Application.Current.MainPage.DisplayAlert( "Error", responseImage.Message, "Accept"); return; } } // Redifines the addRecipe entries and editors this.TextRecipeName = string.Empty; this.DurationHourValue = 0; this.DurationMinutesValue = 10; this.TextDishType = "Breakfast"; this.PortionsValue = 1; this.TextDishTime = "Appetizer"; this.TextIngredients = string.Empty; this.TextInstructions = string.Empty; this.TextTags = string.Empty; this.TextPrice = string.Empty; this.DifficultyValue = 3; this.AddImageSource = "AddImageIcon"; await Application.Current.MainPage.DisplayAlert("New Recipe!", "Recipe succesfully posted", "Ok"); }
private async void SendQuery() { this.IsRunning = true; if (string.IsNullOrEmpty(this.TextChef)) { this.IsRunning = false; this.BCChef = ColorsFonts.errorColor; await Application.Current.MainPage.DisplayAlert("Error", "You must enter an explanation", "Ok"); return; } if (!this.IsChecked) { this.IsRunning = false; await Application.Current.MainPage.DisplayAlert("Error", "You must accept", "Ok"); return; } Response checkConnection = await ApiService.CheckConnection(); if (!checkConnection.IsSuccess) { this.IsRunning = false; await Application.Current.MainPage.DisplayAlert( "Error", "Check your internet connection", "Accept"); return; } string text = ReadStringConverter.ChangePostString(this.TextChef); ChefQuery chefQuery = new ChefQuery { User = this.loggedUser.Email, Text = text }; var responseImage = await ApiService.Post <ChefQuery>( "http://localhost:8080/CookTime.BackEnd", "/api", "/users/chef_request", chefQuery, false); if (!responseImage.IsSuccess) { this.IsRunning = false; await Application.Current.MainPage.DisplayAlert( "Error", responseImage.Message, "Accept"); return; } this.TextChef = string.Empty; this.IsChecked = false; this.IsRunning = false; }
private async void Like() { if (this.LikeSourse.Equals("UnLikedIcon")) { Response checkConnection = await ApiService.CheckConnection(); if (!checkConnection.IsSuccess) { await Application.Current.MainPage.DisplayAlert( "Error", "Check your internet connection", "Accept"); return; } string recipeName = ReadStringConverter.ChangePostString(this.UserRecipe.Name); string queryUrl = $"/users/new_notif?emisorUser={loggedUser.Email}&recieverUser={UserRecipe.Author}¬ifType=3&recipe={recipeName}"; Notification notification = new Notification { EmisorUser = loggedUser.Email, RecieverUser = UserRecipe.Author, NotifType = 3, RecipeName = recipeName }; Response response = await ApiService.Post <Notification>( "http://localhost:8080/CookTime.BackEnd", "/api", queryUrl, notification, false); if (!response.IsSuccess) { await Application.Current.MainPage.DisplayAlert( "Error", "Action can't be done", "Ok"); return; } this.LikeSourse = "LikedIcon"; this.Punctuation += 1; string queryUrl2 = $"/users/new_notif?emisorUser={loggedUser.Email}&recieverUser={UserRecipe.Author}¬ifType=5&recipe={recipeName}"; Notification notification2 = new Notification { EmisorUser = loggedUser.Email, RecieverUser = UserRecipe.Author, NotifType = 5, RecipeName = recipeName }; Response response2 = await ApiService.Post <Notification>( "http://localhost:8080/CookTime.BackEnd", "/api", queryUrl2, notification2, false); if (!response2.IsSuccess) { await Application.Current.MainPage.DisplayAlert( "Error", "Action can't be done", "Ok"); return; } } else { Response checkConnection = await ApiService.CheckConnection(); if (!checkConnection.IsSuccess) { await Application.Current.MainPage.DisplayAlert( "Error", "Check your internet connection", "Accept"); return; } string recipeName = ReadStringConverter.ChangePostString(this.UserRecipe.Name); string queryUrl = $"/users/new_notif?emisorUser={loggedUser.Email}&recieverUser={UserRecipe.Author}¬ifType=4&recipe={recipeName}"; Notification notification = new Notification { EmisorUser = loggedUser.Email, RecieverUser = UserRecipe.Author, NotifType = 4, RecipeName = recipeName }; Response response = await ApiService.Post <Notification>( "http://localhost:8080/CookTime.BackEnd", "/api", queryUrl, notification, false); if (!response.IsSuccess) { await Application.Current.MainPage.DisplayAlert( "Error", "Action can't be done", "Ok"); return; } this.LikeSourse = "UnLikedIcon"; this.Punctuation -= 1; string queryUrl2 = $"/users/new_notif?emisorUser={loggedUser.Email}&recieverUser={UserRecipe.Author}¬ifType=6&recipe={recipeName}"; Notification notification2 = new Notification { EmisorUser = loggedUser.Email, RecieverUser = UserRecipe.Author, NotifType = 6, RecipeName = recipeName }; Response response2 = await ApiService.Post <Notification>( "http://localhost:8080/CookTime.BackEnd", "/api", queryUrl2, notification2, false); if (!response2.IsSuccess) { await Application.Current.MainPage.DisplayAlert( "Error", "Action can't be done", "Ok"); return; } } }