protected override async Task OnDelete(Member item) { var confirm = await DisplayAlert("Delete", $"Delete {item.Name}?", "Yes", "No"); if (confirm) { var parameters = new Dictionary <string, string>(); parameters.Add("teamId", ParentElement?.Id); parameters.Add("email", item.Email); bool res = false; try { res = await App.CloudClient.InvokeApiAsync <bool>("Operations/DeleteMember", HttpMethod.Delete, parameters); } catch (Exception exception) { Console.WriteLine(exception); } if (res) { await ParentVM.LoadItems(); Team = await ParentVM.GetItem(ParentElement.Id); VM.UpdateFilter(m => Team.Members.Select(tm => tm.Id).Contains(m.Id)); await VM.LoadItems(); } } }
/// <summary> /// Look for a shown child and replace it with a new one /// <para>This comes as we have set it up for items to be replaced in the hierarchy</para> /// </summary> /// <param name="shown">Shown item to replace</param> /// <param name="newItem">New item to replace the shown with</param> private void ReplaceShownChild(ListItemVM shown, ListItemVM newItem) { if (ParentItemVM == null) { if (ParentVM != null) { ParentVM.ReplaceSelectedItem(newItem); } } else { if (String.Equals(Model.Code.ChildType, IcdCodeStrings.ChildType_Direct)) { ParentItemVM.ReplaceShownChild(shown, newItem); } else { var newParentChildren = ParentItemVM.Children.ToList(); for (int childOn = 0; childOn < newParentChildren.Count; ++childOn) { if (Object.ReferenceEquals(newParentChildren[childOn], shown) || Object.ReferenceEquals(newParentChildren[childOn], this)) { newParentChildren[childOn] = newItem; } } ParentItemVM.Children = newParentChildren; } } }
public void ForwardChangeNotificationToParents_WhenParentsChangingDuringNotification_DoesntThrowException() { var parent = new ParentVM(); var child = new ChildVM(); parent.SetValue(x => x.Child, child); child.TriggerChange(); }
private void dodajSkladnikAkcja() { ElementGrid pTest = null; if (ParentVM.listaSkladnikow.Count > 0) { try { pTest = ParentVM.listaSkladnikow.First(x => x.NAZWA == nazwa); } catch (Exception) { pTest = null; } } if (pTest == null) { EntityMethods en = new EntityMethods(); Skladniki s = new Skladniki(); s.NAZWA = nazwa; s.OPIS = opis; s.UWAGI = uwagi; s.ID_KATEGORII = en.idKategoriiSkladnika(kategorieSelection); if (isEdit) { s.ID_SKLADNIKA = (int)idEdytowanegoSkladnika; if (zdjecie.GetType() == typeof(BitmapImage)) { string path = ((BitmapImage)zdjecie).UriSource.OriginalString; byte[] image = File.ReadAllBytes(path); s.ZDJECIE = image; } else { s.ZDJECIE = null; } en.edytujSkladnik(s); } else { string path = ((BitmapImage)zdjecie).UriSource.OriginalString; byte[] image = File.ReadAllBytes(path); s.ZDJECIE = image; idEdytowanegoSkladnika = en.dodajSkladnik(s); } CloseAction(); ParentVM.wypiszSkladniki(idEdytowanegoSkladnika); } else { MessageBoxShow mb = new MessageBoxShow(); mb.pokazMessageBox("Informacja", "Został już dodany taki składnik.", MessageBoxTyp.Normalny, MessageBoxIkona.Informacyjna); } }
public void OverlayOk() { if (_errored) { // Clear overlay and allow re-submit if an error occured. OverlayControl = null; } else { // If the overlay was a success overlay, switch back to login. ParentVM.SwitchToLogin(); } }
public void DependencyOnDescendant_WhenDescendantIsNotLoaded_DoesNotTriggerLoad() { var parentVM = new ParentVM( b => b .OnChangeOf .Descendant(x => x.ChildVM) .Execute((vm, args) => { }) ); parentVM.GetValue(x => x.ChangeTrigger).SetValue(x => x.Name, "ChangeTrigger"); Assert.IsFalse(parentVM.IsLoaded(x => x.ChildVM)); }
public void DependencyOnDescendentPropertiesWithRefreshAction_WhenDescendentIsNull_DoesntThrowException() { var parentVM = new ParentVM( b => b .OnChangeOf .Properties(x => x.ChangeTrigger) .Refresh .Descendant(x => x.ChildVM) .Properties(x => x.Name) ); parentVM.ChangeTrigger = true; }
[TestMethod] // regression test public void SetValue_WhenOldChildGetsInvalidAndNewChildIsValid_ParentValidationResultIsValid() { var parent = new ParentVM(); var oldChild = new ChildVM(); var newChild = new ChildVM(); parent.SetValue(x => x.Child, oldChild); oldChild.ChildPropertyErrorMessage = "Old validation error"; parent.SetValue(x => x.Child, newChild); ValidationAssert.IsValid(parent.ValidationResult); }
private void dodajAkcja() { string kategoria = null; if (ParentVM.kategorie.Count > 0) { try { kategoria = ParentVM.kategorie.First(x => x == nazwa); } catch (Exception) { kategoria = null; } } if (kategoria == null || kategoria == nazwaEdytowanejKategorii) { EntityMethods en = new EntityMethods(); int index = ParentVM.rodzajeKategorii.IndexOf(ParentVM.rodzajeKategoriiSelection); if (isEdit) { if (index == 0) { en.edytujKategorieSkladnikow(nazwaEdytowanejKategorii, nazwa); } else if (index == 1) { en.edytujKategoriePrzepisow(nazwaEdytowanejKategorii, nazwa); } } else { if (index == 0) { en.dodajKategorieSkladnikow(nazwa); } else if (index == 1) { en.dodajKategoriePrzepisow(nazwa); } } ParentVM.wypiszKategorie(index); CloseAction(); } else { MessageBoxShow mb = new MessageBoxShow(); mb.pokazMessageBox("Informacja", "Została już dodana taka kategoria.", MessageBoxTyp.Normalny, MessageBoxIkona.Informacyjna); } }
public void SetValue_ToNewChild_RevalidatesOldAndNewChild() { var vm = new ParentVM(); var oldChild = new ChildVM(); var newChild = new ChildVM(); vm.SetValue(x => x.Child, oldChild); oldChild.ChildPropertyErrorMessage = "Old validation error"; newChild.ChildPropertyErrorMessage = "New validation error"; vm.SetValue(x => x.Child, newChild); ValidationAssert.ErrorMessages(oldChild.ValidationResult, oldChild.ChildPropertyErrorMessage); ValidationAssert.ErrorMessages(newChild.ValidationResult, newChild.ChildPropertyErrorMessage); }
public void SetValue_RemovesValidationErrorsOfAncestorValidatorsFromOldChild() { string parentErrorMessage = "Parent error"; var vm = new ParentVM(); var oldChild = new ChildVM(); var newChild = new ChildVM(); vm.ChildPropertyErrorMessage = parentErrorMessage; vm.SetValue(x => x.Child, oldChild); ValidationAssert.ErrorMessages(oldChild.ValidationResult, parentErrorMessage); vm.SetValue(x => x.Child, newChild); ValidationAssert.IsValid(oldChild); }
public void ToString_WhenCaptionSourceReturnsNull_ReturnsEmptyString() { var source = new SelectionSource { Caption = null }; var vm = new ParentVM { AllItemsSource = new[] { source }, SelectedItemSource = source }; string caption = vm .GetValue(x => x.Selection) .SelectedItem .ToString(); Assert.AreEqual(String.Empty, caption); }
public void BaseSetup() { Results = new ValidatorMockConfigurationFluent(); var initialState = Results.GetState(); ChildDescriptor = ChildVM.ClassDescriptor; ItemDescriptor = ItemVM.ClassDescriptor; Item = new ItemVM(Results); Child = new ChildVM(Results); Parent = new ParentVM(Results); Grandparent = new GrandparentVM(Results); Child.GetValue(x => x.Items).Add(Item); Parent.SetValue(x => x.Child, Child); Grandparent.GetValue(x => x.Children).Add(Parent); initialState.RestoreToState(); }
[TestMethod] // regression test public void SetValue_WhenOldAndNewChildGetInvalid_ParentResultContainsOnlyErrorOfNewChild() { var parent = new ParentVM(); var oldChild = new ChildVM(); var newChild = new ChildVM(); parent.SetValue(x => x.Child, oldChild); oldChild.ChildPropertyErrorMessage = "Old validation error"; newChild.ChildPropertyErrorMessage = "New validation error"; parent.SetValue(x => x.Child, newChild); ValidationAssert.ErrorMessages( parent.ValidationResult, ParentVM.ChildInvalidMessage, newChild.ChildPropertyErrorMessage ); }
/// <summary> /// Replace a single, selected item /// <para>Attempts to propagate to the ListVM of ParentVM or calls ReplaceShownChild when appropriate</para> /// </summary> /// <param name="newItem">New item to replace the single selected item with</param> public void ReplaceSelectedChild(ListItemVM newItem) { if (newItem == null) { return; } if (ParentItemVM == null) { if (ParentVM != null) { ParentVM.ReplaceSelectedItem(newItem); } } else { ReplaceShownChild(this, newItem); } }
[TestMethod] // regression test public void SetValue_WhenOldChildGetsSameErrorAsNewChild_ParentValidationResultContainsErrorOfNewChild() { var parent = new ParentVM(); var oldChild = new ChildVM(); var newChild = new ChildVM(); parent.SetValue(x => x.Child, oldChild); string sameValidationError = "Same validation error"; oldChild.ChildPropertyErrorMessage = sameValidationError; newChild.ChildPropertyErrorMessage = sameValidationError; parent.SetValue(x => x.Child, newChild); ValidationError oldError = oldChild .ValidationResult .Errors .Single(); ValidationError newError = newChild .ValidationResult .Errors .Single(); Assert.AreNotSame(oldError, newError); bool newErrorIsContained = parent .ValidationResult .Errors .Any(x => Object.ReferenceEquals(x, newError)); bool oldErrorIsContained = parent .ValidationResult .Errors .Any(x => Object.ReferenceEquals(x, oldError)); Assert.IsFalse(oldErrorIsContained); Assert.IsTrue(newErrorIsContained); }
public ActionResult Index() { var parent = new ParentVM { ParName = "yo!!", ChildVms = new List <ChildVM>() { new ChildVM { Name = "frst", Other = "ot1" }, new ChildVM { Name = "frst1", Other = "ot12" }, new ChildVM { Name = "frst2", Other = "ot13" } } }; return(View(parent)); }
/// <summary> /// Attempt to clear the ParentVM ListVM when appropriate. /// <para>Will figure if needs to load </para> /// </summary> public void ClearForParent() { if (String.Equals(Model.Code.ChildType, IcdCodeStrings.ChildType_Direct)) { if ((ParentVM != null) && (ParentItemVM != null)) { ParentItemVM.ClearToAllChildren(); if (Object.ReferenceEquals(ParentVM.Items.Items[0], this)) { ParentVM.ReplaceSelectedItem(ParentItemVM, false); } else { ReplaceShownChild(this, ParentItemVM); } } else if (ParentVM != null) { ParentVM.ClearToFullList(); } } }
private void dodajAkcja() { string jednostka = null; if (ParentVM.jednostki.Count > 0) { try { jednostka = ParentVM.jednostki.First(x => x == nazwa); } catch (Exception) { jednostka = null; } } if (jednostka == null || jednostka == nazwaEdytowanejJednostki) { EntityMethods en = new EntityMethods(); if (isEdit) { en.edytujJednostke(nazwaEdytowanejJednostki, nazwa); ParentVM.wypiszJednostki(); } else { en.dodajJednostke(nazwa); ParentVM.wypiszJednostki(); } CloseAction(); } else { MessageBoxShow mb = new MessageBoxShow(); mb.pokazMessageBox("Informacja", "Została już dodana taka jednostka.", MessageBoxTyp.Normalny, MessageBoxIkona.Informacyjna); } }
public async Task <IFeedbackMessage> SubmitForm() { if (ValidateInput()) { ParentVM.ShowOverlay(); var returnedMsg = await FeedbackManager.Instance.SendFeedback(this.Message, this.Email, this.Subject, this.Username, this.Attachments.Select(a => a.FeedbackImage)); if (returnedMsg != null) { this.ClearFormAfterSubmit(); var imgReadOnlyVM = new FeedbackMessageReadOnlyVM(returnedMsg, this.ParentVM); ParentVM.Messages.Add(imgReadOnlyVM); ParentVM.SwitchToMessageList(); return(returnedMsg); } else { ParentVM.HideOverlay(); MessageBox.Show(LocalizedStrings.LocalizedResources.FeedbackSendError); } } return(null); }
public void PropagateChildErrors_WithInvalidChildren_ParentHasError() { var error = "Child records are invalid"; var validItem = new ChildVM(); var invalidItem = new ChildVM(); var childDescriptor = CreateChildDescriptor(b => b.CheckViewModel(args => { if (args.Target == invalidItem) { args.AddError("Item error"); } })); ParentVM vm = CreateParent(b => b.PropagateChildErrors(error), childDescriptor); vm.Children.Add(validItem); ValidationAssert.IsValid(vm.ValidationResult); vm.Children.Add(invalidItem); var actualParentValidationState = vm.GetValidationResult(ValidationResultScope.Self); ValidationAssert.ErrorMessages(actualParentValidationState, error); }
/// <summary> /// Update Comments and Children according to whether the item is chosen or not /// </summary> private void UpdateChosen() { if (IsChosen) { if (m_Children == null) { Children = CodesToItems.GetChildItems( Model.Children .Where(ci => !ParentHasEnabledCode(ci)), ParentVM, this); if (m_Children.Count == 0) { SpecificityComplete = true; } else { if (!String.Equals(m_Children[0].Title.Title, CodesToItems.SpecificityString)) { SpecificityComplete = true; } } m_TrueChildren.Clear(); m_TrueChildren.AddRange(Children); } if ((ParentItemVM != null) && (String.Equals(Model.Code.ChildType, Data.IcdCodeStrings.ChildType_Direct))) { Comment = ParentItemVM.Comment; ParentItemVM.Comment = ListItemVM.CommentStart; ParentItemVM.HasOwnComment = false; } } else { SpecificityComplete = false; foreach (var child in m_TrueChildren) { child.IsChosen = false; } m_TrueChildren.Clear(); if (HasOwnComment) { if ((ParentItemVM != null) && (String.Equals(Model.Code.ChildType, Data.IcdCodeStrings.ChildType_Direct))) { ParentItemVM.Comment = Comment; ParentItemVM.HasOwnComment = true; Comment = CommentStart; } } Children = null; } if (ParentVM != null) { if (ParentItemVM == null) { if (IsChosen) { ParentVM.ClearToItem(this); } else { ParentVM.ClearToFullList(); } } else { if (String.Equals(Model.Code.ChildType, IcdCodeStrings.ChildType_Direct)) { if (IsChosen) { ParentItemVM.ClearChildrenToSelected(); ParentItemVM.ReplaceSelectedChild(this); } else { ClearForParent(); } } ParentVM.UpdateChecks(); } } }
public ActionResult Index(ParentVM model) { return(View(model)); }
public void Setup() { Parent = new ParentVM(); Assert.IsTrue(Parent.IsValid); }
public void OpenOutputDirectory() { ParentVM.OpenDirectory(SelectedJob.Options.OutputDir); }
public void OpenOutputDirectory() { ParentVM.OpenDirectory(OutputDir); }
private void dodajPrzepisAkcja() { EntityMethods en = new EntityMethods(); ElementGrid pTest = null; if (ParentVM.listaPrzepisow.Count > 0) { try { pTest = ParentVM.listaPrzepisow.First(x => x.NAZWA == nazwa); } catch (Exception) { pTest = null; } } if (pTest == null) { Przepisy p = new Przepisy(); p.NAZWA = nazwa; p.NOTATKI = notatki; p.OPIS = opis; p.ILOSC_PORCJI = Double.Parse(iloscPorcji); p.ID_KATEGORII = en.idKategoriiPrzepisu(kategorieSelection); int czas = 0; if (czasH != null) { czas = Int32.Parse(czasH) * 60 + Int32.Parse(czasM); } else { czas = Int32.Parse(czasM); } p.CZAS_PRZYRZADZENIA = czas; if (isEdit == false) { string path = ((BitmapImage)zdjecie).UriSource.OriginalString; byte[] image = File.ReadAllBytes(path); p.ZDJECIE = image; idEdytowanegoPrzepisu = en.dodajPrzepis(p); } else { if (zdjecie.GetType() == typeof(BitmapImage)) { string path = ((BitmapImage)zdjecie).UriSource.OriginalString; byte[] image = File.ReadAllBytes(path); p.ZDJECIE = image; } else { p.ZDJECIE = null; } p.ID_PRZEPISU = (int)idEdytowanegoPrzepisu; en.edytujPrzepis(p); en.czyscPrzepisySkladniki((int)idEdytowanegoPrzepisu); } List <Przepisy_Skladniki> lista = new List <Przepisy_Skladniki>(); foreach (SkladnikPrzepisu sp in listaSkladnikow) { Przepisy_Skladniki ps = new Przepisy_Skladniki(); ps.L_ID_PRZEPISU = (int)idEdytowanegoPrzepisu; if (sp.ILOSC != null) { ps.ILOSC = sp.ILOSC; } if (!String.IsNullOrWhiteSpace(sp.JEDNOSTKA)) { ps.ID_JEDNOSTKI = en.pobierzIdJednostki(sp.JEDNOSTKA); } ps.L_ID_SKLADNIKA = en.idSkladnika(sp.NAZWA); en.dodajPrzepisySkladniki(ps); } ParentVM.wypiszPrzepisy((int)idEdytowanegoPrzepisu); CloseAction(); } else { MessageBoxShow mb = new MessageBoxShow(); mb.pokazMessageBox("Informacja", "Został już dodany taki przepis.", MessageBoxTyp.Normalny, MessageBoxIkona.Informacyjna); } }
public MyCustomCommand(ParentVM parent, MyTabItemViewModel item) { Parent = parent; Item = item; }
public MyTabItemViewModel(ParentVM parent) { MyCommand = new DeleteCommand(parent, this); }