示例#1
0
        public ActionResult Edit(int?id)
        {
            ProductsRepository productsRepo = new ProductsRepository();
            GenresRepository   genresRepo   = new GenresRepository();
            Product            item         = id == null ? new Product() : productsRepo.GetById(id.Value);

            EditVM model = new EditVM();

            model.Id      = item.Id;
            model.GenreId = item.GenreId;
            model.Artist  = item.Artist;
            model.Title   = item.Title;
            model.Genres  = new SelectList
                            (
                genresRepo.GetAll(),
                "Id",
                "Name",
                model.GenreId
                            );
            model.Price        = item.Price;
            model.VinylImgPath = item.VinylImgPath;
            model.OnSale       = item.OnSale;

            return(View(model));
        }
示例#2
0
 public UnitOfWork(ApplicationDbContext ctx)
 {
     _ctx          = ctx;
     Gigs          = new GigRepository(ctx);
     Genres        = new GenresRepository(ctx);
     Follows       = new FollowsRepository(ctx);
     Attedances    = new AttendanceRepository(ctx);
     Notifications = new NotificationsRepository(ctx);
 }
示例#3
0
 public UnitOfWork(ApplicationDbContext context)
 {
     _context    = context;
     Gigs        = new GigsRepository(_context);
     Users       = new UserRepository(_context);
     Followings  = new FollowingsRepository(_context);
     Genres      = new GenresRepository(_context);
     Attendences = new AttendencesRepository(_context);
 }
示例#4
0
        public bool DeleteGenre(int id)
        {
            if (!GenresRepository.GenreExists(id))
            {
                return(false);
            }

            GenresRepository.DeleteGenre(id);
            return(true);
        }
 public EntityService()
 {
     _bookService       = new BooksRepository();
     _studentService    = new StudentsRepository();
     _genresService     = new GenresRepository();
     _departmentService = new DepartmentRepository();
     _staffService      = new StaffRepository();
     _bookissueService  = new BookIssueRepository();
     _bookreturnService = new BookReturnRepository();
 }
        // ReSharper disable once InconsistentNaming
        public async Task GetGenresByNamesAsync_should_return_empty_array_if_the_genre_names_array_is_empty()
        {
            using (var context = CreateContext())
            {
                await SeedGenresAsync(context);

                var repo = new GenresRepository(context);

                var genres = await repo.GetGenresByNamesAsync(Array.Empty<string>());

                Assert.Equal(0, genres.Length);
            }
        }
示例#7
0
        public IActionResult Index(string searchByBookTitle, string searchByGenreName, string searchByWriterName, int?page)
        {
            var books = BooksRepository.GetAll().ToList();

            if (!string.IsNullOrEmpty(searchByBookTitle))
            {
                books = books.Where(b => b.Title.Contains(searchByBookTitle)).ToList();
            }

            if (!string.IsNullOrEmpty(searchByGenreName))
            {
                books = books.Where(b => b.Genre.GenreName.Contains(searchByGenreName)).ToList();
            }

            if (!string.IsNullOrEmpty(searchByWriterName))
            {
                books = books.Where(b =>
                                    b.Writer.FirstName.Contains(searchByWriterName) || b.Writer.LastName.Contains(searchByWriterName)).ToList();
            }

            var pagenatedList = PaginatedList <Book> .Create(books, page ?? 1, GlobalConstants.pageSize);

            pagenatedList.SearchByBookTitle  = searchByBookTitle;
            pagenatedList.SearchByGenreName  = searchByGenreName;
            pagenatedList.SearchByWriterName = searchByWriterName;
            if (pagenatedList.Genres == null)
            {
                pagenatedList.Genres = new List <Genre>()
                {
                    new Genre()
                    {
                        GenreName = string.Empty
                    }
                };
                pagenatedList.Genres.AddRange(GenresRepository.GetAll().ToList());

                if (!string.IsNullOrEmpty(searchByGenreName))
                {
                    var index = pagenatedList.Genres.FindIndex(g => g.GenreName.Contains(searchByGenreName));
                    var temp  = pagenatedList.Genres[0];
                    pagenatedList.Genres[0]     = pagenatedList.Genres[index];
                    pagenatedList.Genres[index] = temp;
                }
            }
            return(View(pagenatedList));
        }
        // ReSharper disable once InconsistentNaming
        public async Task GetGenresByNamesAsync_should_return_empty_array_if_no_matching_genres_are_found()
        {
            using (var context = CreateContext())
            {
                await SeedGenresAsync(context);

                var repo = new GenresRepository(context);

                var names = new[]
                {
                    "action1",
                    "crime1"
                };

                var genres = await repo.GetGenresByNamesAsync(names);

                Assert.Equal(0, genres.Length);
            }
        }
示例#9
0
        public ActionResult Edit(EditVM model)
        {
            GenresRepository genresRepo = new GenresRepository();

            if (!ModelState.IsValid)
            {
                model.Genres = new SelectList
                               (
                    genresRepo.GetAll(),
                    "Id",
                    "Name",
                    model.GenreId
                               );
                return(View(model));
            }

            ProductsRepository repo = new ProductsRepository();
            Product            item = new Product();

            item.Id           = model.Id;
            item.GenreId      = model.GenreId;
            item.Artist       = model.Artist;
            item.Title        = model.Title;
            item.Price        = (decimal)model.Price;
            item.VinylImgPath = model.VinylImgPath;
            item.OnSale       = model.OnSale;

            if (item.Id > 0)
            {
                repo.Update(item);
            }
            else
            {
                repo.Insert(item);
            }

            return(RedirectToAction("Index", "Products"));
        }
示例#10
0
        // ReSharper disable once InconsistentNaming
        public async Task GetGenresByNamesAsync_should_return_genres_by_names()
        {
            using (var context = CreateContext())
            {
                await SeedGenresAsync(context);

                var repo = new GenresRepository(context);

                var names = new[]
                {
                    "action",
                    "crime"
                };

                var genres = await repo.GetGenresByNamesAsync(names);

                Assert.Equal(names.Length, genres.Length);

                for (int i = 0; i < names.Length; i++)
                {
                    Assert.Equal(names[i], genres[i].Name);
                }
            }
        }
示例#11
0
        public Genre UpdateGenre(int id, EditGenreRequest request)
        {
            var updatedGenre = GenresRepository.UpdateGenre(id, request.Name);

            return(Mapper.Map <Genre>(updatedGenre));
        }
示例#12
0
        public SimpleGenre CreateGenre(CreateGenreRequest request)
        {
            var genre = GenresRepository.CreateGenre(request.Name);

            return(Mapper.Map <SimpleGenre>(genre));
        }
示例#13
0
        public List <Genre> GetFullList(GenresSearchRequest request)
        {
            var genres = GenresRepository.GetGenreList(request.Search).ToList();

            return(Mapper.Map <List <Genre> >(genres));
        }
示例#14
0
 public GenreService(GenresRepository repository, IMapper mapper)
 {
     Mapper           = mapper;
     GenresRepository = repository;
 }
示例#15
0
 public GenresService(GenresRepository genresRepository, IOptions <AppSettings> options)
 {
     _genresRepository = genresRepository;
     _options          = options;
 }
示例#16
0
 public BooksByGenresFilter(GenresRepository genresRepository)
 {
     this.genresRepository = genresRepository;
 }
示例#17
0
 public GenresAccess()
 {
     _genresRepositor = new GenresRepository();
 }
示例#18
0
 public GenresController(GenresRepository genresRepository)
 {
     this.genresRepository = genresRepository;
 }
示例#19
0
 public void Dispose()
 {
     GenresRepository.Dispose();
 }
 public GenresService()
 {
     _genresRepo = new GenresRepository();
 }