Esempio n. 1
0
        public async Task <bool> CreateBook(BookCreateInputModel bookModel)
        {
            Publication publication = new Publication
            {
                CreatedOn = DateTime.UtcNow,
                Title     = bookModel.PublicationTitle,
                UserId    = bookModel.PublicationUserId,
            };

            await this.context.Publications.AddAsync(publication);

            Book book = new Book
            {
                Description   = bookModel.Description,
                AuthorName    = bookModel.AuthorName,
                Year          = bookModel.Year,
                PublicationId = publication.Id,
            };

            await this.context.Books.AddAsync(book);

            int result = await this.context.SaveChangesAsync();

            return(result > 0);
        }
Esempio n. 2
0
        public async Task <IActionResult> Create(BookCreateInputModel input)
        {
            var imageUrl = await this.cloudinary.UploadAsync(input.Image, "book_covers");

            var bookId = await this.booksService.CreateAsync(input.Title, input.Description, imageUrl, input.SelectedCategories, input.SelectedAuthors);

            return(this.RedirectToAction("ById", "Books", new { id = bookId, Area = "" }));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create()
        {
            var userId = this.userManager.GetUserId(this.User);
            var bookCreateInputModel = new BookCreateInputModel
            {
                PublicationUserId = userId,
            };

            return(this.View(bookCreateInputModel));
            //return this.Json(bookCreateInputModel);
        }
Esempio n. 4
0
        public IActionResult Create()
        {
            var categories = this.categoriesService.GetAll <CategoryDropDownViewModel>();
            var viewModel  = new BookCreateInputModel()
            {
                Categories = categories,
            };

            var authors = this.authorsService.GetAll <AuthorDropDownViewModel>();

            viewModel.Authors = authors;

            return(this.View(viewModel));
        }
Esempio n. 5
0
        public async Task <IActionResult> Create(BookCreateInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var userId = this.userManager.GetUserId(this.User);

            model.PublicationUserId = userId;

            bool isCreted = await this.booksService.CreateBook(model);

            if (!isCreted)
            {
                return(this.View(model));
            }

            return(this.Redirect("/Books/All"));
            // return this.Json(model);
        }