Exemple #1
0
        public async Task <IActionResult> InsertBook(BookViewModel view)
        {
            int genId = 0, autorId = 0;

            var author = repository.VerifyAuthorByNameAsync(view.AUTOR.Nume.Trim() + " " + view.AUTOR.Prenume.Trim()).Result.ToList();

            if (author.LongCount() > 0)
            {
                autorId = author[0].AutorId;
            }
            else
            {
                await repository.InsertAuthorAsync(view.AUTOR);

                autorId = view.AUTOR.AutorId;
            }
            view.CARTE.AutorId = autorId;

            var genre = repository.VerifyGenreByDescriptionAsync(view.GEN.Descriere.Trim()).Result.ToList();

            if (genre.LongCount() > 0)
            {
                genId = genre[0].GenId;
            }
            else
            {
                await repository.InsertGenreAsync(view.GEN);

                genId = view.GEN.GenId;
            }
            view.CARTE.GenId = genId;

            for (var it = 0; it < view.numarCarti; ++it)
            {
                await repository.InsertBookAsync(view.CARTE);
            }

            return(RedirectToAction("AfisareCarti", "Book", view));
        }