public async Task <IActionResult> AddComment(Comment comment)
        {
            _context.Comments.Add(comment);
            _context.SaveChanges();
            await Task.CompletedTask;
            var entity = _context.Posts.FirstOrDefault(s => s.ID == comment.Post_Id);

            if (entity == null)
            {
                return(new BadRequestResult());
            }
            entity.CommentCount++;
            _context.Entry(entity).CurrentValues.SetValues(entity);
            _context.SaveChanges();
            return(Ok());
        }
        public IActionResult EditPost([FromBody] Article article)
        {
            var entity = _context.Article.FirstOrDefault(s => s.ID == article.ID);

            if (entity == null)
            {
                return(new BadRequestResult());
            }
            _context.Entry(entity).CurrentValues.SetValues(article);
            _context.SaveChanges();
            return(new OkObjectResult(true));
        }
        public IActionResult GetFile([FromBody] UploadedImg img, int id)
        {
            // Create unique file name
            string photoId = Guid.NewGuid().ToString();
            //string filePath = @"ClientApp\src\assets\Post\" + photoId + ".jpg";
            string filePath = @"wwwroot\Photo\" + photoId + ".jpg";

            // Remove file type from base64 encoding, if any
            if (img.FileAsBase64.Contains(","))
            {
                img.FileAsBase64 = img.FileAsBase64
                                   .Substring(img.FileAsBase64.IndexOf(",") + 1);
            }

            // Convert base64 encoded string to binary
            img.FileAsByteArray = Convert.FromBase64String(img.FileAsBase64);

            // Write binary file to server path
            using (var fs = new FileStream(filePath, FileMode.CreateNew))
            {
                fs.Write(img.FileAsByteArray, 0, img.FileAsByteArray.Length);
            }
            var entity = _context.Album.FirstOrDefault(s => s.ID == id);

            if (entity == null)
            {
                return(new BadRequestResult());
            }
            ImgPath path = new ImgPath();

            path.Path = filePath;
            entity.ImgPaths.Add(path);
            _context.Entry(entity).CurrentValues.SetValues(entity);
            _context.SaveChanges();
            return(new OkObjectResult("Photo/" + photoId + ".jpg"));
        }
Example #4
0
 public ActionResult Edit(TABLE2 e)
 {
     dc.Entry(e).State = EntityState.Modified;
     dc.SaveChanges();
     return(RedirectToAction("List"));
 }