public void Create(DaeHeurigen heurigen) { using (var session = _sessionFactory.OpenSession()) { using (var transaction = session.BeginTransaction()) { try { session.Save(heurigen); transaction.Commit(); } catch (Exception e) { throw new DataAccessLayerException("Failed to Create Heurigen in Database", e); } } } }
public void Delete(DaeHeurigen heurigen) { using (var session = _sessionFactory.OpenSession()) { using (var transaction = session.BeginTransaction()) { try { session.Delete(heurigen); transaction.Commit(); } catch (Exception e) { //_log.Error("MySQLRepo: Failed to Delete Heurigen in Database"); throw new DataAccessLayerException("Failed to Delete Heurigen in Database", e); } } } }
public void Update(DaeHeurigen heurigen) { using (var session = _sessionFactory.OpenSession()) { using (var transaction = session.BeginTransaction()) { DaeHeurigen heurigenToUpdate; try { heurigenToUpdate = session.Query<DaeHeurigen>() .Where(x => x.Id == heurigen.Id) .Select(x => x).Single(); } catch (Exception e) { //_log.Error("MySQLRepo: Failed to Select Heurigen at Update"); throw new DataAccessLayerException("Failed to Select Heurigen at Update", e); } try { foreach (var prop in heurigen.GetType().GetProperties() .Where(x => !x.GetIndexParameters().Any()) .Where(x => x.CanRead && x.CanWrite)) { var value = prop.GetValue(heurigen, null); prop.SetValue(heurigenToUpdate, value, null); } } catch (Exception e) { //log fehlt throw new DataAccessLayerException("Failed during Updating Objects for DB Update", e); } try { session.Merge(heurigenToUpdate); transaction.Commit(); } catch (Exception e) { //_log.Error("MySQLRepo: Failed to Update Heurigen"); throw new DataAccessLayerException("Failed to Update Heurigen in Database", e); } } } }