Example #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            else
            {
                if (Image != null)
                {
                    using (var stream = new MemoryStream())
                    {
                        await Image.CopyToAsync(stream);

                        Pie.Image            = stream.ToArray();
                        Pie.ImageContentType = Image.ContentType;
                    }
                }
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PieExists(Pie.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

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