Beispiel #1
0
        public HistoryModel Create(History history)
        {
            return new HistoryModel
            {
                Url = _urlHelper.Link("HistoryApi", new { id = history.Id }),
                Body = history.Body,
                Date = history.Date,
                UserId = history.UserId

            };
        }
 /// <summary>
 /// Create a new History object.
 /// </summary>
 /// <param name="valueId">Initial value of the ValueId property.</param>
 /// <param name="time">Initial value of the Time property.</param>
 /// <param name="value">Initial value of the Value property.</param>
 /// <param name="author">Initial value of the Author property.</param>
 /// <param name="id">Initial value of the Id property.</param>
 public static History CreateHistory(global::System.Int32 valueId, global::System.DateTime time, global::System.String value, global::System.String author, global::System.Int32 id)
 {
     History history = new History();
     history.ValueId = valueId;
     history.Time = time;
     history.Value = value;
     history.Author = author;
     history.Id = id;
     return history;
 }
        /// <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 Histories EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToHistories(History history)
 {
     base.AddObject("Histories", history);
 }