Пример #1
0
        public async Task <IActionResult> OnPost()
        {
            if (!ModelState.IsValid)
            {
                TempData["Warning"] = "The values entered for blog are not correct, try again";
                return(RedirectToPage());
            }

            Blog blog = new Blog
            {
                Title        = ViewModel.Title,
                Introduction = ViewModel.Introduction,
                DateAdded    = DateTime.Now
            };

            // process file upload
            if (ViewModel.Banner != null)
            {
                using (var memoryStream = new MemoryStream())
                {
                    await ViewModel.Banner.CopyToAsync(memoryStream);

                    blog.Banner = memoryStream.ToArray();
                }
            }

            _ = await _blogService.AddBlogAsync(blog);

            TempData["Success"] = "Blog added successfully";
            return(RedirectToPage());
        }