public async Task <ToastDto> UpdateAsync(Guid id, ToastDto updatedToast) { if (updatedToast == null || id != updatedToast.Id) { throw new ArgumentException("Angegebener Trinkspruch ist null oder Id stimmt nicht mit der Id des Trinkspruches überein."); } Toast existingToast = await toastRepository.GetAsync(t => t.Id == id); if (existingToast == null) { throw new ArgumentException("Angegebene Id ist falsch"); } existingToast.Reviewed = updatedToast.Reviewed; existingToast.ToastText = updatedToast.ToastText; try { List <Tag> existingTags = existingToast.ToastTags.Select(tt => tt.Tag).ToList(); List <Tag> updatedTags = new List <Tag>(); foreach (TagDto tagDto in updatedToast.Tags) { Tag tag = await tagRepository.GetAsync(t => t.Id == tagDto.Id); updatedTags.Add(tag); } List <Tag> tagsToAdd = updatedTags.Except(existingTags).ToList(); foreach (Tag tagToAdd in tagsToAdd) { ToastTag toastTagToAdd = new ToastTag() { TagId = tagToAdd.Id, ToastId = existingToast.Id }; toastTagRepository.Create(toastTagToAdd); } List <Tag> tagsToDelete = existingTags.Except(updatedTags).ToList(); foreach (Tag tagToDelete in tagsToDelete) { toastTagRepository.Delete(tt => tt.TagId == tagToDelete.Id && tt.ToastId == existingToast.Id); } Toast res = await toastRepository.UpdateAsync(existingToast); return(res.ToDto()); } catch (Exception e) { logger.LogError(e.Message); throw; } }
public void ShowToastNotification(string title, string message, ToastDisplayDuration displayDuration, ToastTag tag = ToastTag.Default, PortableImage image = null, bool vibrate = false) { var duration = ToastDuration.Short; switch (displayDuration) { case ToastDisplayDuration.Short: duration = ToastDuration.Short; break; case ToastDisplayDuration.Long: duration = ToastDuration.Long; break; default: throw new ArgumentOutOfRangeException("timeTillHide"); } IToastText02 templateContent = ToastContentFactory.CreateToastText02(); //templateContent.TextHeading.Text = title; templateContent.TextBodyWrap.Text = message; templateContent.Duration = duration; templateContent.Audio.Content = ToastAudioContent.Silent; var toast = templateContent.CreateNotification(); toast.Tag = tag.ToString(); toast.Activated += ToastOnActivated; toast.Dismissed += ToastOnDismissed; toast.Failed += ToastOnFailed; if (vibrate) { VibrationDevice.GetDefault().Vibrate(TimeSpan.FromSeconds(0.5)); } ServiceLocator.DispatcherService.RunOnMainThread(() => ToastNotificationManager.CreateToastNotifier().Show(toast)); }
public ToastDto Create(ToastDto entity) { Toast toast = new Toast() { Id = Guid.Empty, ToastText = entity.ToastText, Reviewed = false, }; Toast res = toastRepository.Create(toast); try { List <ToastTag> toastTags = new List <ToastTag>(); foreach (TagDto tagDto in entity.Tags) { Tag tag = tagRepository.Get(t => t.Id == tagDto.Id); if (tag == null) { throw new ArgumentException("Ein Tag des Trinkspruches konnte nicht gefunden werden"); } ToastTag toastTag = new ToastTag() { TagId = tag.Id, ToastId = toast.Id }; toastTags.Add(toastTag); } toastTagRepository.CreateRange(toastTags); return(res.ToDto()); } catch (Exception e) { toastRepository.Delete(t => t.Id == toast.Id); logger.LogError(e.Message); throw; } }