public async Task<bool> DeleteAlertFavorite(AlertFavoriteDTO alertFavorite) { try { if (alertFavorite == null) return false; App.CurrentUserEnvironment.LsAlertFavorites.Remove(alertFavorite); await _dataService.DeleteAlertFavorite(alertFavorite.IdAlertFavorite); return true; } catch (WebException) { await _dialogService.ShowError(Resources.TimeoutError , Resources.WebErrorTitle , Resources.WebErrorButtonText, null); } catch (TimeoutException e) { await _dialogService.ShowError(e, Resources.TimeoutErrorTitle , Resources.WebErrorButtonText , null); } return false; }
/// <summary> /// Check if the alert favorite has empty fields /// </summary> private async Task<bool> CheckIfEmptyFieldInAlertFavorite(AlertFavoriteDTO source) { //TODO : handle error message var isDisplayError = false; var msg = string.Empty; var title = string.Empty; // message error if empty fields switch (IdAlertTypeEnum) { case AlertDefinitionEnum.SMS: msg = Resources.ContentEmptySMS; title = Resources.UnexpectedErrorTitle; if (string.IsNullOrEmpty(source.Content)) isDisplayError = true; break; case AlertDefinitionEnum.Email: msg = Resources.ContentEmptyEmail; title = Resources.UnexpectedErrorTitle; if (string.IsNullOrEmpty(source.EmailObject) || string.IsNullOrEmpty(source.Content)) isDisplayError = true; break; case AlertDefinitionEnum.MessageCall: msg = Resources.ContentEmptyEmail; title = Resources.UnexpectedErrorTitle; if (source.Record == null) isDisplayError = true; break; } // error message if (isDisplayError) { await _dialogService.ShowMessage(msg, title); return true; } return false; }
public async Task AddFavoriteAlert(AlertFavoriteDTO alertFavorite) { try { if (alertFavorite == null) return; if (!await CheckIfEmptyFieldInAlertFavorite(alertFavorite)) { if (await CheckIfAlertFavoriteAlreadyExist(alertFavorite)) { alertFavorite.IdUser = App.CurrentUserEnvironment.User.IdUser; App.CurrentUserEnvironment.LsAlertFavorites.Add(alertFavorite); var id = await _dataService.InsertAlertFavorite(alertFavorite); alertFavorite.IdAlertFavorite = id; } } } catch (WebException) { await _dialogService.ShowError(Resources.TimeoutError , Resources.WebErrorTitle , Resources.WebErrorButtonText, null); } catch (TimeoutException e) { await _dialogService.ShowError(e, Resources.TimeoutErrorTitle , Resources.WebErrorButtonText , null); } return; }
/// <summary> /// Check if the alert already exists in favorite /// </summary> private async Task<bool> CheckIfAlertFavoriteAlreadyExist(AlertFavoriteDTO source) { if (App.CurrentUserEnvironment.LsAlertFavorites.Any(el => el.Content == source.Content)) { await _dialogService.ShowMessage(Resources.FavoriteAlertAlreadyExist , Resources.FavoriteAlertAlreadyExistTitle); return false; } return true; }