public OrganizationEditViewModel(Organization item = null) { if (item != null) { Item = item; Title = "Editar organización"; LogoUrl = item.LogoUrl; IsEditMode = true; } else { Item = new Organization(); Title = "Nueva organización"; IsEditMode = false; } SaveCommand = new Command(async() => await SaveAsync()); DeleteCommand = new Command(async() => await DeleteAsync()); PickImageCommand = new Command(async() => await PickImageAsync()); MessagingCenter.Subscribe <SettingsViewModel>(this, "RefreshLogin", (sender) => { if (!(CloudService.IsUserLoggedIn() && CloudService.GetCurrentUser().UserId.Equals(Item.AdminUser))) { NavigationService.Instance.GoToHomePage(); } }); }
public AnnouncementEditViewModel(Announcement item = null) { if (item != null) { Item = item; Title = "Editar noticia"; ImageUrl = item.ImageUrl; IsEditMode = true; } else { Item = new Announcement(); Title = "Nueva noticia"; IsEditMode = false; } SaveCommand = new Command(async() => await SaveAsync()); DeleteCommand = new Command(async() => await DeleteAsync()); PickImageCommand = new Command(async() => await PickImageAsync()); MessagingCenter.Subscribe <SettingsViewModel>(this, "RefreshLogin", (sender) => { if (!(CloudService.IsUserLoggedIn() && CloudService.GetCurrentUser().UserId.Equals(Item.Author))) { NavigationService.Instance.GoToHomePage(); } }); }
async Task SaveAsync() { if (IsBusy) { return; } IsBusy = true; try { if (!ValidateFields()) { await Application.Current.MainPage.DisplayAlert("Campos requeridos", "Por favor, introduce nombre y descripción de la organización", "Ok"); } else { if ((await Application.Current.MainPage.DisplayActionSheet("Se guardarán los cambios realizados. ¿Estás seguro?", "Guardar", "Cancelar")).Equals("Guardar")) { if (Image != null) { LogoUrl = await CloudService.UploadStreamAsync(CloudService.GetCurrentUser().UserId, Image.GetStream()); Item.LogoUrl = LogoUrl; } var table = await CloudService.GetTableAsync <Organization>(); if (Item.Id == null) { await table.CreateItemAsync(Item); } else { await table.UpdateItemAsync(Item); } await CloudService.SyncOfflineCacheAsync <Organization>(overrideServerChanges : true); MessagingCenter.Send(this, "ItemsChanged"); await NavigationService.Instance.GoToHomePage(); } } } catch (Exception ex) { Debug.WriteLine($"[OrganizationEdit] Save error: {ex.Message}"); } finally { IsBusy = false; } }
public AnnouncementDisplayViewModel(Announcement item) { Title = string.Empty; //item.Description = Regex.Replace(item.Description, @"\r\n?|\n", Environment.NewLine); Item = item; EditCommand = new Command(async() => await EditAsync()); OpenBrowserCommand = new Command <string>(async(param) => await OpenBrowserAsync(param)); IsAuthor = CloudService.IsUserLoggedIn() && CloudService.GetCurrentUser().UserId.Equals(Item.Author); MessagingCenter.Subscribe <SettingsViewModel>(this, "RefreshLogin", (sender) => { IsAuthor = CloudService.IsUserLoggedIn() && CloudService.GetCurrentUser().UserId.Equals(Item.Author); }); }
public OrganizationDisplayViewModel(Organization item) { //item.Description = Regex.Replace(item.Description, @"\r\n?|\n", Environment.NewLine); Item = item; Title = item.Name; EditCommand = new Command(async() => await EditAsync()); OpenBrowserCommand = new Command <string>(async(param) => await OpenBrowserAsync(param)); MakePhoneCallCommand = new Command <string>(MakePhoneCall); SendEmailCommand = new Command <string>(SendEmail); IsOrganizationAdmin = CloudService.IsUserLoggedIn() && CloudService.GetCurrentUser().UserId.Equals(Item.AdminUser); MessagingCenter.Subscribe <SettingsViewModel>(this, "RefreshLogin", (sender) => { IsOrganizationAdmin = CloudService.IsUserLoggedIn() && CloudService.GetCurrentUser().UserId.Equals(Item.AdminUser); }); }