/// <summary> /// Command to confirm all the added items and add them to the database /// </summary> /// <returns></returns> private async Task ConfirmCommand() { foreach (var item in TempListOfArticles) { // Adds the item to the database if (!await IoC.CreateInstance <ApplicationViewModel>().rep.AddArticle(item.ToModel <IArticle, Article>())) { // TODO: Skapa varningstext break; } // Set the out animation item.ShouldAnimateOut = true; await Task.Delay(100); } // Make sure all animations are finished await Task.Delay(500); // Clears the temp list TempListOfArticles.Clear(); // Closes the pop up and updates the list IoC.CreateInstance <ApplicationViewModel>().ClosePopUp(); IoC.CreateInstance <TableControlViewModel>().LoadItems(); }
public AddArticleControlViewModel() { // Setting commands AddToTempList = new RelayCommand(async() => await AddToTempListCommad()); Close = new RelayCommand(() => { IoC.CreateInstance <ApplicationViewModel>().ClosePopUp(); IsFilledCorrect = true; }); Confirm = new RelayCommand(async() => await ConfirmCommand()); RemoveAddedItem = new RelayParameterizedCommand((item) => { TempListOfArticles.Remove(item as ArticleViewModel); }); GetAllCategories(); }
/// <summary> /// Command to add items to <see cref="TempListOfArticles"/> /// </summary> /// <returns></returns> private async Task AddToTempListCommad() { // Check inputs if (int.TryParse(InputPrice, out int price) && int.TryParse(InputLoanTime, out int loanTime) && int.TryParse(InputQuantity, out int quantity) && CurrentArticle.title != null && CurrentArticle.author != null && CurrentArticle.publisher != null && CurrentArticle.isbn != null && CurrentArticle.edition != null ) { (CurrentArticle as ArticleViewModel).price = price; (CurrentArticle as ArticleViewModel).loanTime = loanTime; (CurrentArticle as ArticleViewModel).quantity = quantity; IsFilledCorrect = true; } else { IsFilledCorrect = false; return; } // Set the quantity to 1 if nothing else is mentioned if ((CurrentArticle as ArticleViewModel).quantity == 0) { (CurrentArticle as ArticleViewModel).quantity = 1; } // Set the edition if nothing put in if ((CurrentArticle as ArticleViewModel).edition == "") { (CurrentArticle as ArticleViewModel).edition = "1"; } // Set the category CurrentArticle.categoryID = CurrentCategory.categoryID; // Add the chosen number of articles for (int i = 0; i < (CurrentArticle as ArticleViewModel).quantity; i++) { // Add a new item TempListOfArticles.Add((CurrentArticle as ArticleViewModel).ToModel <IArticle, ArticleViewModel>()); await Task.Delay(100); } // Clear all input parameters ClearProperties(); }