コード例 #1
0
        public ActionResult Create(GigFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Genres = _context.Genres.ToList();
                return(View("GigsForm", viewModel));
            }

            var gig = new Gig
            {
                ArtistId = User.Identity.GetUserId(),
                DateTime = viewModel.GetDateTime(),
                GenreId  = viewModel.Genre,
                Venue    = viewModel.Venue
            };

            var attendees = _context.Users.ToList();

            gig.Create(attendees);

            _context.Gigs.Add(gig);
            _context.SaveChanges();

            return(RedirectToAction("Mine", "Gigs"));
        }
コード例 #2
0
 public void AddGig(Gig gig)
 {
     gig.Artist = _context.Users.Where(u => u.Id == gig.ArtistId)
                  .Include(a => a.Followers.Select(f => f.Follower))
                  .SingleOrDefault();
     _context.Gigs.Add(gig);
     gig.Create();
 }
コード例 #3
0
        public void Add(Gig gig)
        {
            var artist = _context.Users
                         .Include(u => u.Followers)
                         .Single(u => u.Id == gig.ArtistId);

            artist.Followers = _context.Followings
                               .Include(f => f.Follower)
                               .Where(f => f.Followee.Id == gig.ArtistId).ToList();

            gig.Artist = artist;

            _context.Gigs.Add(gig);

            gig.Create();
        }
コード例 #4
0
        public ActionResult Create(GigsViewFormModel view)
        {
            if (!ModelState.IsValid)
            {
                view.Geners = _unitOfWork.Gener.GetAllGener();
                return(View("Create", view));
            }


            var newGig = new Gig();

            newGig.Create(User.Identity.GetUserId(), view);
            _unitOfWork.Gig.Add(newGig);
            _unitOfWork.Finish();

            return(RedirectToAction("UpcomingGig", "Gigs"));
        }
コード例 #5
0
ファイル: GigController.cs プロジェクト: dinamer/Muzzo
        public ActionResult Create(GigFormViewModel gigViewModel)
        {
            if (!ModelState.IsValid)
            {
                gigViewModel.Genres = _unitOfWork.Genres.GetGenres();

                return(View("GigForm", gigViewModel));
            }

            _unitOfWork.Gigs.AddGig(Gig.Create(User.Identity.GetUserId(),
                                               _unitOfWork.Followings.GetFollowersByArtist(User.Identity.GetUserId()),
                                               gigViewModel.GetDateTime(),
                                               gigViewModel.Venue,
                                               gigViewModel.Genre));

            _unitOfWork.Complete();

            return(RedirectToAction("MyUpcomingGigs", "Gig"));
        }
コード例 #6
0
        public IActionResult Create(GigFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Genres = new List <Genre>()
                {
                    new Genre {
                        Id = 1, Name = "Jazz"
                    },
                    new Genre {
                        Id = 2, Name = "Blues"
                    },
                    new Genre {
                        Id = 3, Name = "Rock"
                    },
                    new Genre {
                        Id = 4, Name = "Country"
                    }
                };
                return(View("GigForm", viewModel));
            }
            var gig = new Gig
            {
                ArtistId = User.FindFirstValue(ClaimTypes.NameIdentifier),
                DateTime = viewModel.GetDateTime(),
                GenreId  = viewModel.Genre,
                Venue    = viewModel.Venue,
            };

            var followers = _context.ApplicationUsers
                            .Include(f => f.Followers)
                            .ThenInclude(f => f.Followee)
                            .FirstOrDefault(i => i.Id == gig.ArtistId)?.Followers.ToList();


            gig.Create(followers);

            _context.Gigs.Add(gig);
            _context.SaveChanges();

            return(RedirectToAction("Mine", "Gigs"));
        }
コード例 #7
0
        public ActionResult Create(GigFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Genres = _unitOfWork.Genres.GetGenres();
                return(View("GigForm", viewModel));
            }

            var gig = new Gig
            {
                ArtistId = User.Identity.GetUserId(),
                DateTime = viewModel.GetDateTime(),
                Genre    = _unitOfWork.Genres.GetGenre(viewModel.GenreId),
                Venue    = viewModel.Venue
            };

            gig.Create(_unitOfWork);
            _unitOfWork.Complete();

            return(RedirectToAction("Mine", "Gigs"));
        }
コード例 #8
0
        [ValidateAntiForgeryToken] // used to prevent CSRF attacks. Used in conjuction with @Html.AntiForgeryToken() on view, this validates this token existed on the form that submitted this request.
        public ActionResult Create(GigFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Genres = Context.Genres.ToList();
                return(View("GigForm", viewModel)); // will return current model back to same view, which will keep fields populated and validation messages displayed
            }

            Gig gig = new Gig
            {
                ArtistId  = User.Identity.GetUserId(),
                DateAdded = viewModel.GetDateAdded(),
                GenreId   = viewModel.Genre,
                Venue     = viewModel.Venue
            };

            gig.Create();

            Context.Gigs.Add(gig);
            Context.SaveChanges(); // writes to the database

            return(RedirectToAction("Mine", "Gigs"));
        }
コード例 #9
0
        private async Task SeedCatalogAsync(DataSeedContext context)
        {
            var names = new[] { "Development", "Marketing", "Cooking" };

            var rollDice = new Random();

            var categories = names
                             .Select(t => names[rollDice.Next(0, names.Length)])
                             .Select(name => Category
                                     .Create(Guid.NewGuid(), name, $"{name} description"))
                             .ToList();
            var specialCategory = Category.Create(Guid.Parse(Zero1FiveTestData.CategoryId), "Special", "Special Category");

            categories.Add(specialCategory);
            await categoryRepository.InsertManyAsync(categories, true);

            List <Gig> gigs = new();

            for (var i = 1; i < 10; i++)
            {
                var id          = Guid.NewGuid();
                var title       = $"Gig {i}";
                var cover       = $"cover{i}.jpg";
                var description = $"Gig {i} Description";
                if (i == 2)
                {
                    id = Guid.Parse(Zero1FiveTestData.GigId);
                }
                var gig = Gig
                          .Create(id,
                                  categoryId: Guid.Parse(Zero1FiveTestData.CategoryId),
                                  title,
                                  cover,
                                  description);

                gig.CreatorId    = Guid.Parse(Zero1FiveTestData.UserId);
                gig.CreationTime = DateTime.Now;
                gigs.Add(gig);
            }

            await gigRepository.InsertManyAsync(gigs, true);

            List <Product> products = new();

            for (var x = 0; x < 10; x++)
            {
                var name       = $"Product {x}";
                var categoryId = categories[rollDice.Next(0, categories.Count)].Id;

                var gigId   = Guid.Parse(Zero1FiveTestData.GigId);
                var product = Product.Create(Guid.NewGuid(), gigId, categoryId, name, $"image");

                product.Description = $"{name} Description";

                if (x == 1)
                {
                    product.IsPublished = true;
                }

                products.Add(product);
            }
            await productRepository.InsertManyAsync(products, true);           // List<Product> products = new();
        }