Exemple #1
0
        public async Task <Photo> CreateAsync(Photo photo)
        {
            context.Add(photo);
            await context.SaveChangesAsync();

            return(photo);
        }
        public async Task <IActionResult> PutComment(int id, Comment comment)
        {
            if (id != comment.Id)
            {
                return(BadRequest());
            }

            _context.Entry(comment).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <Comment> CreateAsync(Comment comment)
        {
            context.Add(comment);
            await context.SaveChangesAsync();

            return(comment);
        }
        public async Task <IActionResult> Create([Bind("Id,Title,Description")] Photo photo, IFormFile thePicture)
        {
            if (ModelState.IsValid)
            {
                photo.UserName = User.Identity.Name;

                photo.DateUploaded = DateTime.Now;

                using MemoryStream memoryStream = new MemoryStream();
                await thePicture.CopyToAsync(memoryStream);

                photo.Picture     = memoryStream.ToArray();
                photo.ContentType = thePicture.ContentType;

                _context.Add(photo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(photo));
        }