Beispiel #1
0
        public async Task <IActionResult> OnPost()
        {
            try
            {
                Post post = await _postMinion.GetAsync(ID ?? 0) ?? new Post();

                post.Title       = Post.Title;
                post.Author      = Post.Author;
                post.Description = Post.Description;

                if (ImageUpload != null)
                {
                    string tempFilePath = Path.GetTempFileName();
                    using (FileStream stream = new FileStream(tempFilePath, FileMode.Create))
                    {
                        await ImageUpload.CopyToAsync(stream);
                    }

                    post.ImageUrl = await BlobRoss.UploadBlob("images", ImageUpload.FileName, tempFilePath);
                }

                await _postMinion.SaveAsync(post);

                return(RedirectToPage("/Posts/View", new { id = post.ID }));
            } catch (Exception e)
            {
                ViewData["ErrorMessage"] = e.Message;
                return(RedirectToPage("/Posts/View", new { id = ID }));
            }
        }
Beispiel #2
0
        public async Task SaveModelAsync(ApplicationDbContext context)
        {
            var entity = new Project
            {
                Id          = Id,
                Title       = Title,
                Description = Description,
                ProjectType = ProjectType
            };

            if (ImageUpload != null)
            {
                using (var memoryStream = new MemoryStream())
                {
                    await ImageUpload.CopyToAsync(memoryStream);

                    entity.Image = memoryStream.ToArray();
                };
            }

            if (PortfolioItems != null)
            {
                entity.PortfolioItems = PortfolioItems.Select(pi => pi.ToEntity(context)).ToList();
            }

            context.Update(entity);
            context.Entry(entity).Property(p => p.Image).IsModified = ImageUpload != null ? true : false;

            await context.SaveChangesAsync();
        }