Beispiel #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid == false)
            {
                return(Page());
            }

            var path = "";

            if (CoverPhoto != null && CoverPhoto.Length != 0)
            {
                //取得現在的靜態檔案路徑
                path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", CoverPhoto.FileName);
                await using var stream = new FileStream(path, FileMode.Create);
                await CoverPhoto.CopyToAsync(stream);
            }

            var article = await UpdateArticle(path);

            _context.Attach(article).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ArticlesExists(ArticleForPage.Id))
                {
                    return(NotFound());
                }

                throw;
            }

            return(RedirectToPage("./Index"));
        }