Пример #1
0
        public IActionResult Create(AuthorViewModel vm)
        {
            Author a = Converter.AuthorViewModelToAuthor(vm);

            a.Id  = Repo.CreateAuthor(a);
            vm.Id = a.Id;
            return(RedirectToAction("Detail", new { id = vm.Id }));
        }
Пример #2
0
        private void CreateAuthorHelper(out AuthorForCreationDto model, out string authorId)
        {
            authorId = System.Guid.NewGuid().ToString();
            string bookId = Guid.NewGuid().ToString();

            model = ObjectMocks.GetAuthorForCreation(authorId, bookId);
            _auRepo.CreateAuthor(model, authorId);
        }
Пример #3
0
 private void SaveButton_Click(object sender, EventArgs e)
 {
     if (_authors.GetAuthorList().Any(author => author.FirstName == FirstNameBox.Text) &&
         _authors.GetAuthorList().Any(author => author.LastName == LastNameBox.Text))
     {
         MessageBox.Show(@"Author already in database!", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         if (string.IsNullOrWhiteSpace(FirstNameBox.Text) || string.IsNullOrWhiteSpace(LastNameBox.Text))
         {
             MessageBox.Show(@"Inputs are empty!", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             _authors.CreateAuthor(FirstNameBox.Text, LastNameBox.Text);
             Close();
         }
     }
 }
Пример #4
0
 public AuthorDto CreateAuthor(AuthorInputModel body)
 {
     return(_authorRepo.CreateAuthor(body));
 }
Пример #5
0
 public int CreateAuthor(AuthorInputModel author)
 {
     return(_authorRepository.CreateAuthor(author));
 }
Пример #6
0
        static void Main(string[] args)
        {
            connectionString = ConfigurationManager.ConnectionStrings["BooksDb"].ConnectionString;

            var authorRepo = new AuthorRepository(connectionString);

            Console.WriteLine("--- Get all authors with art in the name ---");
            var arts = authorRepo.GetAuthorsByName("art");

            PrintAuthors(arts);

            Console.WriteLine("--- Get George R.R. Martin by id ---");
            var grrm = authorRepo.GetAuthorById(198);

            Console.WriteLine(grrm);

            Console.WriteLine("--- Insert new author ---");
            Author author;
            string testName = "Test McTest";

            try
            {
                author = authorRepo.CreateAuthor(testName);
                Console.WriteLine(author);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
                author = authorRepo.GetAuthorsByName(testName).Single(a => a.Name == testName);
            }

            Console.WriteLine("--- Insert author again ---");
            try
            {
                author = authorRepo.CreateAuthor(testName);
                Console.WriteLine(author);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("--- Delete author ---");
            var deleted = authorRepo.DeleteAuthor(author);

            if (deleted)
            {
                Console.WriteLine($"Successfully deleted author {author.Id}");
            }
            else
            {
                Console.WriteLine($"Error deleting author {author.Id}");
            }

            Console.WriteLine("--- More delete author ---");
            deleted = authorRepo.DeleteAuthor(author);
            if (deleted)
            {
                Console.WriteLine($"Successfully deleted author {author.Id}");
            }
            else
            {
                Console.WriteLine($"Error deleting author {author.Id}");
            }
        }
Пример #7
0
 public async Task <Author> CreateAuthor(Author author)
 {
     return(await repository.CreateAuthor(author));
 }
Пример #8
0
 public AuthorDetailDto CreateAuthor(AuthorInputModel model)
 {
     return(_authorRepository.CreateAuthor(model));
 }
Пример #9
0
 public AuthorDto CreateAuthor(AuthorInputModel author)
 {
     return(_authorRepo.CreateAuthor(author));
 }