Пример #1
0
        public async Task <IActionResult> AddVideo([FromBody] VideoRequest videoRequest)
        {
            if (!await _genreManager.IsGenresIdValid(videoRequest.GenresId))
            {
                return(BadRequest("Genres is Invalid"));
            }

            if (!await IsUser())
            {
                return(Forbid());
            }

            var video = _mapper.Map <Video>(videoRequest);

            video.LastUpdated = DateTime.Now;
            var author = await _authorManager.GetAuthor(videoRequest.AuthorId);

            if (author == null)
            {
                return(BadRequest("Author is Invalid"));
            }

            video.UserId   = _userManager.GetUserId(HttpContext.User);
            video.AuthorId = author.Id;
            _videoManager.AddVideo(video);
            await _videoManager.SaveChangesAsync();

            var response = _mapper.Map <VideoResponse>(video);

            return(CreatedAtAction(nameof(GetVideoById), new { id = video.Id }, response));
        }
Пример #2
0
 public ActionResult Create(BookViewModel book)
 {
     try
     {
         List <AuthorDTO> authors = new List <AuthorDTO>();
         for (int i = 0; i < book.SelectedAuthorId.Count; i++)
         {
             authors.Add(authorService.GetAuthor(book.SelectedAuthorId[i]));
         }
         var bookCreate = new BookDTO()
         {
             Title       = book.Title,
             Theme_Id    = book.SelectedThemeId,
             Price       = book.Price,
             PenaltyType = Library.DAL.Entities.Penalty.Medium,
             //Authors = authors
         };
         bookService.Create(bookCreate, book.SelectedAuthorId);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Пример #3
0
        // GET: Author/Edit/5
        public ActionResult Edit(int id)
        {
            //var model = new BookViewModel();
            var author     = authorService.GetAuthor(id);
            var bookMapper = new MapperConfiguration(cfg => cfg.CreateMap <BookDTO, BookViewModel>()).CreateMapper();
            var viewModel  = new AuthorViewModel()
            {
                Id      = author.Id,
                Name    = author.Name,
                Surname = author.Surname,
                Books   = bookMapper.Map <IEnumerable <BookDTO>, List <BookViewModel> >(authorService.GetBooks(id))
            };

            ViewData["AllBooks"] = from book in viewModel.Books
                                   select new SelectListItem {
                Text = book.Title, Value = book.Id.ToString()
            };
            return(View(viewModel));
        }
 public IActionResult GetByID(Guid id)
 {
     return(new JsonResult(authorManager.GetAuthor(id)));
 }