Пример #1
0
        public async Task <IActionResult> Create(CollectibleCreateViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(viewModel.Collectible);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(viewModel));
        }
Пример #2
0
        // GET: Collectibles/Create
        public async Task <IActionResult> Create()
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            var viewModel = new CollectibleCreateViewModel()
            {
                Collections = await _context.Collections.Where(c => c.UserId == user.Id).ToListAsync()
            };

            return(View(viewModel));
        }
        // GET: Collectibles/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var user = await _userManager.GetUserAsync(HttpContext.User);

            var viewModel = new CollectibleCreateViewModel()
            {
                Collections = await _context.Collections.Where(c => c.UserId == user.Id).ToListAsync()
            };
            var collectible = await _context.Collectibles.FindAsync(id);

            if (collectible == null)
            {
                return(NotFound());
            }
            return(View(collectible));
        }