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); } } } }
public bool Update(RecognitionResults entity) { using (logger.BeginScope(nameof(this.Update))) { if (entity == null) { logger.LogWarning("ArgumentNullException while updating Recognition Result in DB"); return(false); } using (var context = new PsqlContext()) { try { DbResult dbResult = entity.ToDbEntity(); context.Results.Update(dbResult); context.SaveChanges(); logger.LogDebug("RecognitionResult updated successfully"); return(true); } catch (Exception e) { logger.LogWarning(e.ToString() + " while updating pulse in DB"); return(false); } } } }
public bool Add(Session entity) { using (_logger.BeginScope(nameof(Add))) { if (entity == null) { _logger.LogWarning("Entity is null, Add failed"); return(false); } var dbEntity = entity.ToDbEntity(); using (var context = new PsqlContext()) { context.Sessions.Add(dbEntity); try { context.SaveChanges(); } catch (Exception e) { _logger.LogWarning($"Exception from {e.Source}:{e.Message}, Add failed"); return(false); } } entity.SessionID = dbEntity.SessionId; _logger.LogDebug("Add succeeded"); return(true); } }
public bool Update(Pulse entity) { using (logger.BeginScope(nameof(this.Update))) { if (entity == null) { logger.LogWarning("ArgumentNullException while updating pulse in DB"); return false; } using (var context = new PsqlContext()) { try { DbPulse dbPulse = entity.ToDbEntity(); context.Pulse.Update(dbPulse); context.SaveChanges(); logger.LogDebug("Pulse updated successfully"); return true; } catch (Exception e) { logger.LogWarning(e.ToString() + " while updating pulse in DB"); return false; } } } }
public bool Update(Session entity) { using (_logger.BeginScope(nameof(Update))) { if (entity == null) { _logger.LogWarning("Entity is null, Update failed"); return(false); } var dbEntity = entity.ToDbEntity(); using (var context = new PsqlContext()) { var oldEntity = (from session in context.Sessions where session.SessionId == dbEntity.SessionId select session).FirstOrDefault(); if (oldEntity == null) { _logger.LogWarning("Entity to update was not found, Update failed"); return(false); } oldEntity.Start = dbEntity.Start; oldEntity.Status = dbEntity.Status; try { context.SaveChanges(); } catch (Exception e) { _logger.LogWarning($"Exception from {e.Source}:{e.Message}, Update failed"); return(false); } } _logger.LogDebug("Update succeeded"); return(true); } }