Пример #1
0
        /// <summary>
        /// Saves a wiki.
        /// </summary>
        /// <param name="wiki">The wiki.</param>
        /// <returns>
        /// A <see cref="ValidationResult"/> with any validation errors.
        /// </returns>
        public ValidationResult SaveWiki(Wiki wiki)
        {
            using (var transaction = Session.BeginTransaction(IsolationLevel.Serializable))
            {
                var validationResult = wiki.Validate();

                // Ensure WikiName is unique amongst active wikis
                if (Session.CreateCriteria(typeof(Wiki))
                    .Add(Restrictions.Like("Name", wiki.Name))
                    .Add(Restrictions.Not(Restrictions.Eq("Id", wiki.Id)))
                    .Add(Restrictions.Eq("IsActive", true))
                    .SetLockMode(LockMode.Upgrade)
                    .UniqueResult() != null)
                {
                    validationResult.FlagRule("OpenId", string.Format("The name '{0}' is already in use amongst active wikis.", wiki.Name));
                }

                // Commit the record
                if (validationResult.Valid)
                {
                    Session.SaveOrUpdate(wiki);
                    transaction.Commit();
                }
                return validationResult;
            }
        }
Пример #2
0
 private static Entry CreateNewEntry(string name, string title, Wiki wiki)
 {
     var entry = new Entry();
     entry.Wiki = wiki;
     entry.Name = name;
     entry.Title = title;
     entry.Summary = "";
     return entry;
 }
Пример #3
0
 private static Wiki CreateAndSaveWiki(ISession session, string name)
 {
     var wiki = new Wiki();
     wiki.Name = name;
     wiki.Title = "Hello";
     new WikiRepository(session).SaveWiki(wiki);
     return new WikiRepository(session).FindActiveWiki(name);
 }