public static async Task SendEmail(string pToEmail, string pSubject, string pBody) { try { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("*****@*****.**"); mail.To.Add(pToEmail); mail.Subject = pSubject; mail.Body = pBody; SmtpServer.Port = 587; SmtpServer.Host = "smtp.gmail.com"; SmtpServer.EnableSsl = true; SmtpServer.UseDefaultCredentials = false; SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Joinup_92"); SmtpServer.Send(mail); } catch (Exception ex) { ToastNotificationUtils.ShowErrorToastNotifications("Ha habido un error al enviar el correo. Intentelo de nuevo más tarde"); } }
private async void SavePlan() { IsRunning = true; IsEnabled = false; plan.UserId = LoggedUser.Id; if (Image1 != null) { images.Add(new Common.Models.Image() { ImageArray = image1bytes }); } if (Image2 != null) { images.Add(new Common.Models.Image() { ImageArray = image2bytes }); } if (Image3 != null) { images.Add(new Common.Models.Image() { ImageArray = image3bytes }); } var response = await DataService.GetInstance().SavePlan(plan, images); if (!response.IsSuccess) { ToastNotificationUtils.ShowErrorToastNotifications("Ha habido un error en la creación del plan. Intentelo de nuevo más tarde"); } else { Plan plan = (Plan)response.Result; var responseJoin = await DataService.GetInstance().JoinAPlan(plan.PlanId, LoggedUser.Id, true); if (!responseJoin.IsSuccess) { ToastNotificationUtils.ShowErrorToastNotifications("Ha habido un error en la creación del plan. Intentelo de nuevo más tarde"); } else { MessagingCenter.Send(ViewModelLocator.Instance.Resolve <PlansViewModel>(), "RefreshPlans"); MessagingCenter.Send(ViewModelLocator.Instance.Resolve <MyPlansViewModel>(), "RefreshPlans"); MessagingCenter.Send(ViewModelLocator.Instance.Resolve <ProfileViewModel>(), "RefreshPlans"); await NavigationService.NavigateToRootAsync(); } } IsRunning = false; IsEnabled = true; }
private async void AddImage() { await CrossMedia.Current.Initialize(); var source = await Application.Current.MainPage.DisplayActionSheet( "¿Desde donde desea tomar la imagen?", "Cancelar", null, "Galeria", "Camara"); if (source == "Cancelar" || string.IsNullOrEmpty(source)) { file = null; return; } if (source == "Camara") { if (!CrossMedia.Current.IsTakePhotoSupported) { ToastNotificationUtils.ShowErrorToastNotifications("Galeria no disponible"); return; } this.file = await CrossMedia.Current.TakePhotoAsync( new StoreCameraMediaOptions { Directory = "Joinup", Name = DateTime.Now.ToString() } ); } else { if (!CrossMedia.Current.IsTakePhotoSupported) { ToastNotificationUtils.ShowErrorToastNotifications("Camara no disponible"); return; } this.file = await CrossMedia.Current.PickPhotoAsync(); } if (this.file != null) { this.ImageSource = ImageSource.FromStream(() => { var stream = this.file.GetStream(); return(stream); }); } }
private async void UnJoinPlan() { IsRunning = true; IsEnabled = false; var response = await DataService.GetInstance().UnJoinAPlan(plan.PlanId, LoggedUser.Id); if (!response.IsSuccess) { ToastNotificationUtils.ShowErrorToastNotifications("Ha habido un error al desvincularse del plan. Intentelo de nuevo más tarde"); } else { RefreshMeets(); } IsRunning = false; IsEnabled = true; }
public void SendRemark() { if (Score == 0) { ToastNotificationUtils.ShowErrorToastNotifications("Ups...Debes puntuar el plan del 1 al 5"); return; } else { remark.PlanId = plan.PlanId; remark.PlanName = plan.Name; remark.UserId = LoggedUser.Id; remark.UserDisplayName = LoggedUser.Name; remark.UserDisplayImage = LoggedUser.UserImage; remark.CommentDate = DateTime.Now; SaveRemark(); } }
private async void EditPlan() { var source = await Application.Current.MainPage.DisplayActionSheet( "¿Estas seguro de modificar el plan? Los usuarios serán notificados de dichos cambios", "Cancelar", null, "Si", "No"); if (source == "No") { return; } else { IsEnabled = false; IsRunning = true; plan.UserId = LoggedUser.Id; var response = await DataService.GetInstance().EditPlan(plan); if (!response.IsSuccess) { ToastNotificationUtils.ShowErrorToastNotifications("Ha habido un error en al editar el plan. Intentelo de nuevo más tarde"); } else { Plan plan = (Plan)response.Result; SendEmails(); MessagingCenter.Send(ViewModelLocator.Instance.Resolve <PlansViewModel>(), "RefreshPlans"); MessagingCenter.Send(ViewModelLocator.Instance.Resolve <MyPlansViewModel>(), "RefreshPlans"); MessagingCenter.Send(ViewModelLocator.Instance.Resolve <ProfileViewModel>(), "RefreshPlans"); await NavigationService.NavigateBackAsync(); } IsRunning = false; IsEnabled = true; } }
private async void SaveRemark() { IsEnabled = false; IsRunning = true; var response = await DataService.GetInstance().SaveRemark(remark); if (!response.IsSuccess) { ToastNotificationUtils.ShowErrorToastNotifications("Ha habido un error en la publicación de la reseña. Intentelo de nuevo más tarde"); } else { Remark remark = (Remark)response.Result; plan.Remarks.Add(remark); NavigationService.NavigateBackAsync(); } IsRunning = false; IsEnabled = true; MessagingCenter.Send(ViewModelLocator.Instance.Resolve <MyPlansViewModel>(), "RefreshPlans"); }
private async void AddImage(int pPhoto) { if (!isEditing) { MediaFile file; await CrossMedia.Current.Initialize(); var source = await Application.Current.MainPage.DisplayActionSheet( "¿Desde donde desea tomar la imagen?", "Cancelar", null, "Galeria", "Camara"); if (source == "Cancelar") { return; } if (source == "Camara") { if (!CrossMedia.Current.IsTakePhotoSupported) { ToastNotificationUtils.ShowErrorToastNotifications("Galeria no disponible"); return; } file = await CrossMedia.Current.TakePhotoAsync( new StoreCameraMediaOptions { Directory = "Joinup", Name = DateTime.Now.ToString() } ); } else { if (!CrossMedia.Current.IsTakePhotoSupported) { ToastNotificationUtils.ShowErrorToastNotifications("Camara no disponible"); return; } file = await CrossMedia.Current.PickPhotoAsync(); } if (file != null) { if (pPhoto == 1) { Image1 = ImageSource.FromStream(() => { var stream = file.GetStream(); return(stream); }); image1bytes = FilesHelper.ReadFully(file.GetStream()); } else if (pPhoto == 2) { Image2 = ImageSource.FromStream(() => { var stream = file.GetStream(); return(stream); }); image2bytes = FilesHelper.ReadFully(file.GetStream()); } if (pPhoto == 3) { Image3 = ImageSource.FromStream(() => { var stream = file.GetStream(); return(stream); }); image3bytes = FilesHelper.ReadFully(file.GetStream()); } } } }
private void CreatePlan() { if (selectedCategory == null) { ToastNotificationUtils.ShowErrorToastNotifications("Ups...Debes seleccionar una categoria"); return; } if (string.IsNullOrEmpty(Name)) { ToastNotificationUtils.ShowErrorToastNotifications("Ups...Debes ponerle nombre a tu plan"); return; } if (plan.Latitude == 0 && plan.Longitude == 0) { ToastNotificationUtils.ShowErrorToastNotifications("Ups...Debes seleccionar una ubicación para tu plan"); return; } if (string.IsNullOrEmpty(Name)) { ToastNotificationUtils.ShowErrorToastNotifications("Ups...Debes ponerle nombre a tu plan"); return; } if (PlanDate == DateTime.MinValue) { ToastNotificationUtils.ShowErrorToastNotifications("Ups...Debes establecer una fecha de inicio para tu plan"); return; } if (PlanDate < DateTime.Now) { ToastNotificationUtils.ShowErrorToastNotifications("Ups...Debes establecer una fecha de inicio mayor que la fecha actual"); return; } if (EndPlanDate == DateTime.MinValue) { ToastNotificationUtils.ShowErrorToastNotifications("Ups...Debes establecer una fecha de fin para tu plan"); return; } if (PlanDate > EndPlanDate) { ToastNotificationUtils.ShowErrorToastNotifications("Ups...La fecha de finalización del plan no puede ser mayor a la fecha inicial"); return; } if (plan.PlanType == PLANTYPE.LANGUAGE && (plan.Language1 == LANGUAGE.UNDEFINED || plan.Language2 == LANGUAGE.UNDEFINED)) { ToastNotificationUtils.ShowErrorToastNotifications("Ups...Debes establecer los idiomas que se trabajaran en el intercambio"); return; } if (plan.PlanType == PLANTYPE.SPORT && plan.Sport == SPORT.UNDEFINED) { ToastNotificationUtils.ShowErrorToastNotifications("Ups...Debes especificar el deporte que se practicará en tu plan"); return; } if (isEditing) { EditPlan(); } else { SavePlan(); } }
private async void Login() { var url = Application.Current.Resources["UrlAPI"].ToString(); var prefix = Application.Current.Resources["UrlPrefix"].ToString(); var controller = Application.Current.Resources["UrlUsersController"].ToString(); var connection = await ApiService.GetInstance().CheckConnection(); if (!connection.IsSuccess) { ToastNotificationUtils.ShowErrorToastNotifications("No hay conexion a internet"); return; } else if (string.IsNullOrEmpty(Email)) { ToastNotificationUtils.ShowErrorToastNotifications("Email no puede estar vacio"); return; } else if (string.IsNullOrEmpty(Password)) { ToastNotificationUtils.ShowErrorToastNotifications("Introduzca una contraseña"); return; } else if (Password.Length < 6) { ToastNotificationUtils.ShowErrorToastNotifications("La contraseña debe tener al menos 6 caracteres"); return; } else { IsRunning = true; IsEnabled = false; var token = await ApiService.GetInstance().GetToken(url, Email, Password); if (token == null || string.IsNullOrEmpty(token.AccessToken)) { Password = string.Empty; ToastNotificationUtils.ShowErrorToastNotifications("Usuario o contraseña incorrectos"); IsRunning = false; IsEnabled = true; return; } else { Settings.AccessToken = token.AccessToken; Settings.TokenType = token.TokenType; Settings.IsRemembered = IsRemembered; var response = await ApiService.GetInstance().GetUser(url, prefix, $"{controller}/GetUser", this.Email, token.TokenType, token.AccessToken); if (response.IsSuccess) { Settings.UserASP = JsonConvert.SerializeObject(response.Result); IsRunning = false; IsEnabled = true; NavigationService.NavigateToAsync <MainViewModel>(); } else { ToastNotificationUtils.ShowErrorToastNotifications("Algo fué mal. Contacte con el administrador del sistema."); IsRunning = false; IsEnabled = true; return; } } } }
private void ShowErrorMessage(string pMessage) { ToastNotificationUtils.ShowErrorToastNotifications(pMessage); }
private async void Register() { var url = Application.Current.Resources["UrlAPI"].ToString(); var prefix = Application.Current.Resources["UrlPrefix"].ToString(); var controller = Application.Current.Resources["UrlUsersController"].ToString(); var connection = await ApiService.GetInstance().CheckConnection(); if (!connection.IsSuccess) { ToastNotificationUtils.ShowErrorToastNotifications("No hay conexion a internet"); return; } else if (string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(Surname)) { ToastNotificationUtils.ShowErrorToastNotifications("Nombre incorrecto"); return; } else if (!RegexHelper.IsValidEmail(Email) || string.IsNullOrEmpty(Email)) { ToastNotificationUtils.ShowErrorToastNotifications("Email incorrecto"); return; } else if (Password.Length < 6) { ToastNotificationUtils.ShowErrorToastNotifications("La contraseña debe tener al menos 6 caracteres"); return; } else { IsRunning = true; byte[] imageArray = null; if (file != null) { imageArray = FilesHelper.ReadFully(file.GetStream()); } var userRequest = new UserRequest(); userRequest.Name = Name; userRequest.Surname = Surname; userRequest.Email = Email; userRequest.Password = Password; userRequest.ImageArray = imageArray; var postUserResponse = await ApiService.GetInstance().Post <UserRequest>(url, prefix, controller, userRequest); if (postUserResponse.IsSuccess) { var token = await ApiService.GetInstance().GetToken(url, Email, Password); if (token == null || string.IsNullOrEmpty(token.AccessToken)) { ShowErrorMessage("Error al obtener el token. Contacte con el administrador del sistema"); IsRunning = false; return; } Settings.TokenType = token.TokenType; Settings.AccessToken = token.AccessToken; Settings.UserASP = JsonConvert.SerializeObject(postUserResponse.Result); MyUserASP newUser = JsonConvert.DeserializeObject <MyUserASP>(Settings.UserASP); var userResponse = await DataService.GetInstance().PostUser(newUser.Id, newUser.Email, newUser.Name, newUser.Surname, newUser.Image); if (postUserResponse.IsSuccess) { IsRunning = false; NavigationService.NavigateToAsync <MainViewModel>(); } else { IsRunning = false; ShowErrorMessage("Se ha producido un error durante el registro del usuario"); } } else { IsRunning = false; ShowErrorMessage("Se ha producido un error durante el registro del usuario"); } } }