示例#1
0
        public async Task <IActionResult> Add(AuthorAddViewModel viewModel)
        {
            /* Inutile grazie al [Required]. */
            //if (viewModel == null || string.IsNullOrWhiteSpace(viewModel.Name))
            //{
            //    ModelState.AddModelError(nameof(viewModel.Name), "Nome vuoto!");
            //    return View(viewModel);
            //}
            await _context.Authors.AddAsync(new Author(0, viewModel.Name));

            await _context.SaveChangesAsync();

            return(View(viewModel));
        }
示例#2
0
        /// <summary>
        /// Checking author's input and sending it to the database
        /// </summary>
        /// <returns>True if author sent to DB, otherwise false</returns>
        private bool AddItemAuthor()
        {
            AuthorAddViewModel viewmodel = (AuthorAddViewModel)DataContext;
            Author             author    = viewmodel.MyAuthor;

            if (string.IsNullOrEmpty(author.LastName))
            {
                MessageBox.Show("Last name cannnot be empty.");
                return(false);
            }
            try
            {
                int id = MSAConnectionDB.SaveAuthorToDB(author);
                author.AuthorId = id;
                Authors.AddAuthor(author);
                ActivateMainWindow();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            return(true);
        }
示例#3
0
 /// <summary>
 /// Showing author's adding view
 /// </summary>
 /// <param name="sender">The source of the event</param>
 /// <param name="e">The instance containing the event data</param>
 private void AuthorAddView_Selected(object sender, RoutedEventArgs e)
 {
     DataContext = new AuthorAddViewModel();
 }