예제 #1
0
        public async Task <IActionResult> Create([Bind("Id,PlatformName")] GamePlatform gamePlatform)
        {
            if (ModelState.IsValid)
            {
                _context.Add(gamePlatform);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(gamePlatform));
        }
        public async Task <IActionResult> Create(GameProduct gameProduct, IFormFile uploadImg, string url)
        {
            try
            {
                if (uploadImg != null)
                {
                    var path = await FileUploadHelper.UploadFile(uploadImg);

                    gameProduct.Image = path;
                    if (ModelState.IsValid)
                    {
                        _context.GameProducts.Add(gameProduct);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                }
                else
                {
                    if (ModelState.IsValid)
                    {
                        var path = await ImageLoader.DownloadFile(url);

                        gameProduct.Image = path;
                        _context.GameProducts.Add(gameProduct);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                }
            }
            catch (Exception)
            {
                TempData["LinkError"] = "Invalid link";
            }
            ViewData["GamePlatformId"] = new SelectList(_context.GamePlatforms, "Id", "PlatformName", gameProduct.GamePlatformId);
            return(View(gameProduct));
        }
예제 #3
0
 public async Task AddReviewAsycn(Review review)
 {
     context.Reviews.Add(review);
     await context.SaveChangesAsync();
 }
예제 #4
0
        public async Task AddPostAsync(Post post)
        {
            await context.Posts.AddAsync(post);

            await context.SaveChangesAsync();
        }