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); } } } }
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); }
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); }
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); }