public History(Value oldVersion) { ValueId = oldVersion.Id; Time = oldVersion.Time; Author = oldVersion.Author; Value = oldVersion.Value1; }
internal static Value CreateValue(Value original) { return (Value)original.MemberwiseClone(); }
internal void ModifyItself(Value original) { this.Important = original.Important; this.SystemName = original.SystemName; this.Value1 = original.Value1; this.ProjectId = original.ProjectId; this.Id = original.Id; this.Visible = original.Visible; this.Author = original.Author; this.Time = original.Time; }
/// <summary> /// /// </summary> /// <param name="external"></param> /// <param name="visible"></param> /// <exception cref="ConnectionException" /> internal static void SetVisability(Value external, bool visible) { ProjectPropertiesEntities db = new ProjectPropertiesEntities(); if (db.Connection.State != System.Data.ConnectionState.Open) { db.Connection.Open(); } try { Value original = db.Values.FirstOrDefault(x => x.Id == external.Id); original.Visible = visible; db.Refresh(System.Data.Objects.RefreshMode.ClientWins, original); db.SaveChanges(); } catch (Exception e) { throw new ConnectionException(e); } finally { } }
/// <summary> /// Saves old version into History table and modifies existing value. /// </summary> /// <param name="entity">New values of existing project properties.</param> /// <param name="author">Author of modification.</param> /// <returns>If operation was done.</returns> internal static bool ModifyWithHistory(Value entity) { bool operationSuccess = false; ProjectPropertiesEntities db = new ProjectPropertiesEntities(); if (db.Connection.State != System.Data.ConnectionState.Open) { db.Connection.Open(); } DbTransaction transaction = db.Connection.BeginTransaction(); try { Value oldVersion = db.Values.FirstOrDefault(x => x.Id == entity.Id); if (oldVersion == null) { throw new IllegalDBOperationException(entity); } if (oldVersion.Value1.Equals(entity.Value1)) { return true; } History forOldVersion = new History(oldVersion); db.AddToHistories(forOldVersion); if (entity.Important) { Project currentProject = db.Projects.FirstOrDefault(x => x.Id == entity.ProjectId); if (currentProject == null) { throw new IllegalDBOperationException(entity); } db.SaveChanges(); currentProject.LastChanged = forOldVersion.Id; db.Refresh(RefreshMode.ClientWins, currentProject); } oldVersion.ModifyItself(entity); db.Refresh(RefreshMode.ClientWins, oldVersion); db.SaveChanges(); transaction.Commit(); operationSuccess = true; } catch(IllegalDBOperationException e) { transaction.Rollback(); } catch (Exception e) { transaction.Rollback(); } finally { db.Connection.Close(); } return operationSuccess; }
/// <summary> /// Deprecated Method for adding a new object to the Values EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToValues(Value value) { base.AddObject("Values", value); }
/// <summary> /// Create a new Value object. /// </summary> /// <param name="systemName">Initial value of the SystemName property.</param> /// <param name="value1">Initial value of the Value1 property.</param> /// <param name="projectId">Initial value of the ProjectId property.</param> /// <param name="id">Initial value of the Id property.</param> /// <param name="visible">Initial value of the Visible property.</param> /// <param name="important">Initial value of the Important property.</param> /// <param name="author">Initial value of the Author property.</param> /// <param name="time">Initial value of the Time property.</param> public static Value CreateValue(global::System.String systemName, global::System.String value1, global::System.Int32 projectId, global::System.Int32 id, global::System.Boolean visible, global::System.Boolean important, global::System.String author, global::System.DateTime time) { Value value = new Value(); value.SystemName = systemName; value.Value1 = value1; value.ProjectId = projectId; value.Id = id; value.Visible = visible; value.Important = important; value.Author = author; value.Time = time; return value; }