예제 #1
0
 public bool Update(Photo entity)
 {
     using (_logger.BeginScope(nameof(Update)))
     {
         if (entity == null)
         {
             _logger.LogWarning("ArgumentNullException while updating photo in DB");
             return(false);
         }
         using (var context = new PsqlContext())
         {
             try
             {
                 DbPhoto dbPhoto = entity.ToDbEntity();
                 context.Photos.Update(dbPhoto);
                 context.SaveChanges();
                 _logger.LogDebug("Photo updated successfully");
                 return(true);
             }
             catch (Exception e)
             {
                 _logger.LogWarning(e.ToString() + " while updating photo in DB");
                 return(false);
             }
         }
     }
 }
예제 #2
0
        internal static Photo ToDomainEntity(this DbPhoto entity)
        {
            Photo photo = new Photo
            {
                PhotoID   = entity.PhotoId,
                SessionID = entity.SessionId,
                Image     = entity.Image,
                TimeStamp = DateTime.SpecifyKind(entity.Timestamp, DateTimeKind.Utc)
            };

            return(photo);
        }
예제 #3
0
        internal static DbPhoto ToDbEntity(this Photo entity)
        {
            DbPhoto photo = new DbPhoto
            {
                PhotoId   = entity.PhotoID,
                SessionId = entity.SessionID,
                Image     = entity.Image,
                Timestamp = entity.TimeStamp
            };

            return(photo);
        }
예제 #4
0
        public string Save(byte[] bytes)
        {
            using var context = contextFactory.Create();
            var photo = new DbPhoto
            {
                Id      = Guid.NewGuid().ToString(),
                Content = bytes,
            };

            context.Photos.Add(photo);
            context.SaveChanges();
            return(photo.Id);
        }