Пример #1
0
        public ActionResult Details(int id)
        {
            var viewModel = new AuthorDetailsViewModel();

            try
            {
                var author      = _repository.GetAuthorById(id);
                var authorBooks = _repository.GetBooks()
                                  .Where(x => x.AuthorId == author.Id)
                                  .ToList();

                viewModel.PrepareData(authorBooks, author);
            }
            catch (Exception e)
            {
                var errorModel = new ErrorModel
                {
                    Message = "Greška prilikom prikazivanja autora"
                };

                return(View("Error", errorModel));
            }

            return(View(viewModel));
        }
Пример #2
0
        public ActionResult Edit(Guid?authorId)
        {
            var detailedAuthor           = _dataAccess.GetAuthorDetails(authorId.GetValueOrDefault());
            AuthorDetailsViewModel model = Mapper.Instance.Map <AuthorDetailsViewModel>(detailedAuthor);

            return(View(model));
        }
Пример #3
0
        public async Task <IActionResult> OnGetAsync(int id)
        {
            var author = await _db.Authors
                         .Include(a => a.Books)
                         .ThenInclude(b => b.BookBorrowers)
                         .FirstOrDefaultAsync(a => a.Id == id);

            if (author == null)
            {
                return(RedirectToPage("/Index"));
            }

            this.Author = new AuthorDetailsViewModel()
            {
                Name     = author.Name,
                BookList = author.Books
                           .Select(b => new AuthorDetailsBookViewModel()
                {
                    Id     = b.Id,
                    Title  = b.Title,
                    Status = b.BookBorrowers.Any(bb => bb.IsBookReturned == false) ? "Borrowed" : "At Home"
                })
                           .ToList()
            };

            return(Page());
        }
Пример #4
0
        public ActionResult Edit(AuthorDetailsViewModel authorDetails, HttpPostedFileBase ImageFile)
        {
            var authorDto = Mapper.Map <AuthorDTO>(authorDetails);

            if (ImageFile == null)
            {
                var authorDto2 = _dataAccess.GetAuthorDetails(authorDetails.Id);
                authorDto.Image = authorDto2.Image;
            }
            else
            {
                using (var ms = new MemoryStream())
                {
                    ImageFile.InputStream.CopyTo(ms);
                    authorDto.Image = ms.ToArray();
                }
            }

            if (ModelState.IsValid)
            {
                _dataAccess.UpdateAuthor(authorDto);
                _dataAccess.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(authorDetails));
        }
Пример #5
0
        public ActionResult Details(int Id)
        {
            Author author = _context.Authors.Where(x => x.Id == Id).FirstOrDefault();

            if (author == null)
            {
                return(RedirectToAction("Index", "Error"));
            }

            var courses = (from project in _context.Projects.ToList()
                           join authors in _context.Authors.ToList() on project.AuthorId equals authors.Id
                           join projectimages in _context.ProjectImages.ToList() on project.Id equals projectimages.ProjectId
                           where projectimages.IsMain == 1 && project.AuthorId == Id
                           select new ProjectListViewModel
            {
                Id = project.Id,
                Name = project.Name,
                Image = projectimages.ImageUrl,
                AuthorFullName = authors.FirstName + " " + authors.LastName
            }).ToList();

            AuthorDetailsViewModel vm = new AuthorDetailsViewModel
            {
                author  = author,
                Courses = courses
            };

            return(View(vm));
        }
Пример #6
0
        public IActionResult Details(int id)
        {
            var author = DbContext.Authors.FirstOrDefault(a => a.Id == id);

            if (author == null)
            {
                ViewData["Message"] = "Error! There is no such author!";

                return(View());
            }

            var booksInfo = new List <(int, string, string)>();

            var authorBooks = DbContext.Books.Where(b => b.AuthorId == author.Id).ToList();

            foreach (var book in authorBooks)
            {
                bool isAvailable = book.Loans.TrueForAll(l => l.IsReturned == true);

                string status = isAvailable ? "At home" : "Borrowed";

                booksInfo.Add((book.Id, book.Title, status));
            }

            var authorModel = new AuthorDetailsViewModel()
            {
                Name  = author.Name,
                Books = booksInfo
            };

            return(View(authorModel));
        }
Пример #7
0
        public ActionResult Details(int?id, string returnUrl)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var author = db.Authors.Include(a => a.Books).FirstOrDefault(a => a.Id == id);

            if (author == null)
            {
                return(HttpNotFound());
            }

            var booksByAuthor = author.Books.ToList();

            var model = new AuthorDetailsViewModel()
            {
                Author        = author,
                BooksByAuthor = booksByAuthor
            };

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
Пример #8
0
        public ActionResult Details(int id)
        {
            AuthorDetailsViewModel authorViewModel = new AuthorDetailsViewModel();

            authorViewModel.Author = this._authorService.GetAuthorById(id);
            authorViewModel.Books  = this._authorService.GetBooksByAuthorId(id);
            return(View(authorViewModel));
        }
Пример #9
0
        public IActionResult Details(int id)
        {
            var authorDetailsViewModel = new AuthorDetailsViewModel();

            authorDetailsViewModel.AuthorName = authorService.GetAuthorName(id);
            authorDetailsViewModel.Books      = authorService.GetAllBooksFromAuthor(id);

            return(View(authorDetailsViewModel));
        }
        public IActionResult Details(int id)
        {
            var model = new AuthorDetailsViewModel();

            model.Author = authorService.GetAuthorById(id);
            if (model.Author == null)
            {
                return(View("NotFound"));
            }
            return(View(model));
        }
        public void OnGet(int id)
        {
            var author = this._context.Authors.Include(a => a.Books).FirstOrDefault(a => a.Id == id);

            this.BooksByAuthor = new AuthorDetailsViewModel
            {
                Name  = author.Name,
                Books = author.Books.Select(b => new BookByAuthorViewModel
                {
                    Title  = b.Title,
                    Id     = b.Id,
                    Status = b.IsBorrowed ? "Borrowed" : "At home",
                }).ToList()
            };
        }
        public async Task <IActionResult> GetAuthor([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var author = await _context.Authors.Include(a => a.Books).FirstOrDefaultAsync(a => a.ID == id);

            if (author == null)
            {
                return(NotFound());
            }

            return(Ok(AuthorDetailsViewModel.FromAuthor(author)));
        }
Пример #13
0
        public FileContentResult GetAuhtorsImage(Guid?authorId)
        {
            byte[] _dummyImage = System.IO.File.ReadAllBytes(Server.MapPath("~/Content/dummy-image.jpg"));


            var detailedAuthor           = _dataAccess.GetAuthorDetails(authorId.GetValueOrDefault());
            AuthorDetailsViewModel model = Mapper.Instance.Map <AuthorDetailsViewModel>(detailedAuthor);

            if (model != null && model.Id == authorId.GetValueOrDefault())
            {
                FileContentResult fcr = model.Image.Length == 0 ?
                                        new FileContentResult(_dummyImage, "image/jpg") :
                                        new FileContentResult(model.Image, "image/jpg");
                return(fcr);
            }

            return(new FileContentResult(_dummyImage, "image/jpg"));
        }
Пример #14
0
        public ActionResult Create(AuthorDetailsViewModel authorDetails, HttpPostedFileBase ImageFile)
        {
            using (var ms = new MemoryStream())
            {
                ImageFile.InputStream.CopyTo(ms);
                authorDetails.Image = ms.ToArray();
            }

            if (ModelState.IsValid)
            {
                var authorDto = Mapper.Map <AuthorDTO>(authorDetails);
                _dataAccess.CreateNewAuthor(authorDto);
                _dataAccess.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(authorDetails));
        }
Пример #15
0
        public IActionResult Details(int?id)
        {
            var allAuthors = _authorService.GetAllAuthors();

            if (id > allAuthors.Count)
            {
                return(View("Error"));
            }

            var authors = _authorService.GetAllAuthorsDetails();
            var author  = new AuthorDetailsViewModel();

            for (int i = 0; i < authors.Count; i++)
            {
                if (authors[i].AuthorId == id)
                {
                    author = authors[i];
                }
            }
            return(View(author));
        }
        public IActionResult OnGet(int id)
        {
            this.AuthorDetails = this.db.Authors
                                 .Where(a => a.Id == id)
                                 .Select(a => new AuthorDetailsViewModel()
            {
                AuthorName = a.Name,
                Books      = a.Books.Select(b => new AuthorBooksViewModel()
                {
                    Id        = b.Id,
                    BookTitle = b.Title,
                    Status    = b.Status
                }).ToList()
            })
                                 .FirstOrDefault();

            if (this.AuthorDetails == null)
            {
                return(this.NotFound());
            }

            return(this.Page());
        }