コード例 #1
0
        public void AddLike(int id)
        {
            using var context = new ImagesDbContext(_connectionString);
            var image = context.Images.FirstOrDefault(i => i.Id == id);

            image.Likes++;
            context.SaveChanges();
        }
コード例 #2
0
 public void AddImage(string title, string fileName)
 {
     using var context = new ImagesDbContext(_connectionString);
     context.Images.Add(new Image
     {
         Title    = title,
         Date     = DateTime.Now,
         Likes    = 0,
         FileName = fileName
     });
     context.SaveChanges();
 }
コード例 #3
0
 public Image GetById(int id)
 {
     using var context = new ImagesDbContext(_connectionString);
     return(context.Images.FirstOrDefault(i => i.Id == id));
 }
コード例 #4
0
 public List <Image> GetAllImages()
 {
     using var context = new ImagesDbContext(_connectionString);
     return(context.Images.OrderByDescending(i => i.Date).ToList());
 }