本文整理汇总了C#中Article.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Article.Save方法的具体用法?C# Article.Save怎么用?C# Article.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Article
的用法示例。
在下文中一共展示了Article.Save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifySavingParentParentObjectPreservesDeepestChildren
public void VerifySavingParentParentObjectPreservesDeepestChildren()
{
SetUp();
User user = new User();
user.Username = "thomas";
Role role = new Role();
role.Name = "admin";
user.Roles.Add(role);
user.Save();
user = User.SelectFirst();
Assert.AreEqual(1, user.Roles.Count);
Assert.AreEqual("admin", user.Roles[0].Name);
Article a = new Article();
a.Header = "sdfihsdf";
a.Body = "sdfiojhsdf";
a.Followers.Add(user);
a.Author = user;
a.Save();
user = User.SelectFirst();
Assert.AreEqual(1, user.Roles.Count);
Assert.AreEqual("admin", user.Roles[0].Name);
}
示例2: Main
static void Main()
{
// RebuildTables();
Console.WriteLine("Relationship objects and Auto create table");
Console.WriteLine("============Has One============");
ShowHasOne(DbEntry.GetObject<Person>(1));
ShowHasOne(DbEntry.GetObject<Person>(2));
ShowHasOne(DbEntry.GetObject<Person>(3));
Console.WriteLine("============Has Many===========");
ShowHasMany(DbEntry.GetObject<Category>(1));
ShowHasMany(DbEntry.GetObject<Category>(2));
ShowHasMany(DbEntry.GetObject<Category>(3));
Console.WriteLine("===========Update One==========");
var p = DbEntry.GetObject<Person>(2);
Console.WriteLine(">>Before:");
ShowHasOne(p);
p.Name = "Neo";
p.PC.Name = "Matrix";
DbEntry.Save(p);
Console.WriteLine(">>After:");
ShowHasOne(DbEntry.GetObject<Person>(2));
Console.WriteLine(">>Delete:");
DbEntry.Delete(p);
ShowHasOne(DbEntry.GetObject<Person>(2));
Console.WriteLine("==========Update Many==========");
var c = DbEntry.GetObject<Category>(3);
Console.WriteLine(">>Before:");
ShowHasMany(c);
Console.WriteLine(">>After:");
c.Name = "Sport";
c.Books[0].Name = "Kungfu";
c.Books[1].Name = "Dodge the bullets";
DbEntry.Save(c);
ShowHasMany(DbEntry.GetObject<Category>(3));
Console.WriteLine(">>Delete:");
DbEntry.Delete(c);
ShowHasMany(DbEntry.GetObject<Category>(3));
Console.WriteLine("====Has Many And Belongs To====");
var a = new Article {Name = "fly away"};
a.Readers.Add(new Reader {Name = "Kingkong"});
a.Readers.Add(new Reader {Name = "Spiderman"});
a.Save();
var a1 = Article.FindById(a.Id);
ShowHasManyAndBelongsTo(a1);
Console.WriteLine("======Restoring Tables...======");
RebuildTables();
Console.WriteLine("============The End============");
Console.WriteLine("Done! Press Enter to exit.");
}
示例3: Application_Start
protected void Application_Start(object sender, EventArgs e)
{
Logger.System.Trace("Application Start");
if(Category.GetCount(Condition.Empty) == 0)
{
var root = new Category { Name = "Article", Alias = "" }; // 必须存在
var c1 = new Category { Name = "文章", Alias = "essay" };
var c2 = new Category { Name = "作品", Alias = "product" };
var c3 = new Category { Name = "转载", Alias = "reshipment" };
root.Children.Add(c1);
root.Children.Add(c2);
root.Children.Add(c3);
root.Save();
var links = new Category { Name = "Links", Alias = "" }; // 必须存在
var c5 = new Category { Name = "其它站点", Alias = "" };
var c6 = new Category { Name = "友情链接", Alias = "" };
links.Children.Add(c5);
links.Children.Add(c6);
links.Save();
// 缺省用户,用它创建真正的管理员后,用新管理员登录,删除此缺省用户。
var user = new User { Email = "[email protected]", Password = "123", ShowName = "创建管理员后删除",
Role = UserRole.Administrator, SessionId = Guid.NewGuid().ToString() };
user.Save();
var readmeFile = Path.Combine(SystemHelper.BaseDirectory, "../README.md");
var readme = File.Exists(readmeFile) ? StringHelper.ReadToEnd(readmeFile) : "没有找到 README.md";
var s = new Statistic();
var article = new Article
{
Title = "欢迎使用",
Alias = "readme",
SummaryIsEmpty = true,
Format = ArticleFormat.Markdown,
Writer = "梁利锋",
Content = readme,
Category = c1,
Statistic = s,
User = user,
};
article.Save();
}
}
示例4: ArticleRSSImport
protected void ArticleRSSImport(object sender, ActiveEventArgs e)
{
string url = e.Params["URL"].Get<string>();
if (url.IndexOf("http") != 0)
url = "http://" + url;
if (string.IsNullOrEmpty(url))
{
Node nodeMessage = new Node();
nodeMessage["Message"].Value =
Language.Instance[
"EmptyRSS",
null,
"You need to supply a valid URL to an RSS feed"];
nodeMessage["Duration"].Value = 2000;
ActiveEvents.Instance.RaiseActiveEvent(
this,
"ShowInformationMessage",
nodeMessage);
}
else
{
// We've got ourselves an apprently valid RSS feed...
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
XmlDocument doc = new XmlDocument();
doc.Load(response.GetResponseStream());
User user = User.SelectFirst(Criteria.Eq("Username", Users.LoggedInUserName));
Regex imgRegEx =
new Regex(
@"<img[^>]*src=""(?<src>[^""]*)""[^>]*/?>+",
RegexOptions.IgnoreCase |
RegexOptions.Compiled);
Regex htmlRegEx =
new Regex(
@"(?<tag><[^>]*>+)",
RegexOptions.IgnoreCase |
RegexOptions.Compiled);
foreach (XmlNode idxNode in doc.SelectNodes("/rss/channel/item"))
{
string title = idxNode.SelectNodes("title")[0].FirstChild.Value;
string content = idxNode.SelectNodes("description")[0].FirstChild.Value;
string dateStr = idxNode.SelectNodes("pubDate")[0].FirstChild.Value;
string artUrl = idxNode.SelectNodes("link")[0].FirstChild.Value;
string ingress = htmlRegEx.Replace(content, "");
artUrl = artUrl.Substring(artUrl.LastIndexOf('/') + 1);
if (artUrl.IndexOf(".") != -1)
artUrl = artUrl.Substring(0, artUrl.IndexOf('.'));
artUrl += ConfigurationManager.AppSettings["DefaultPageExtension"];
DateTime date =
DateTime.ParseExact(
dateStr.Substring(5),
"dd MMM yyyy HH:mm:ss",
CultureInfo.InvariantCulture);
Article art = new Article();
art.Header = title;
art.Ingress = ingress.Substring(0, 100) + "...";
bool foundImg = false;
foreach (Match idxMatch in imgRegEx.Matches(content))
{
if (foundImg)
{
// Any other [non-first] image...
string imgSrc = idxMatch.Groups["src"].Value;
string imgFileName = imgSrc.Substring(imgSrc.LastIndexOf('/') + 1);
imgFileName = imgFileName.Substring(0, imgFileName.IndexOf('.'));
HttpWebRequest reqImg = WebRequest.Create(imgSrc) as HttpWebRequest;
using (HttpWebResponse imgResp = reqImg.GetResponse() as HttpWebResponse)
{
Image img = Image.FromStream(imgResp.GetResponseStream());
string origPath = HttpContext.Current.Server.MapPath(
"~/Resources/Images/" + imgFileName + ".png");
img.Save(origPath);
}
content = content.Replace(imgSrc, "Resources/Images/" + imgFileName + ".png");
}
else
{
// First Image, being used as "Article Main Image"...
content = imgRegEx.Replace(content, "", 1);
foundImg = true;
string imgSrc = idxMatch.Groups["src"].Value;
string imgFileName = imgSrc.Substring(imgSrc.LastIndexOf('/') + 1);
imgFileName = imgFileName.Substring(0, imgFileName.IndexOf('.'));
HttpWebRequest reqImg = WebRequest.Create(imgSrc) as HttpWebRequest;
using (HttpWebResponse imgResp = reqImg.GetResponse() as HttpWebResponse)
{
Image img = Image.FromStream(imgResp.GetResponseStream());
string origPath = HttpContext.Current.Server.MapPath(
"~/Resources/Images/" + imgFileName + ".png");
string iconPath = HttpContext.Current.Server.MapPath(
"~/Resources/Images/Small/" + imgFileName + ".png");
string mainPath = HttpContext.Current.Server.MapPath(
"~/Resources/Images/Medium/" + imgFileName + ".png");
art.OriginalImage = "Resources/Images/" + imgFileName + ".png";
art.IconImage = "Resources/Images/Small/" + imgFileName + ".png";
art.MainImage = "Resources/Images/Medium/" + imgFileName + ".png";
// Saving original...
//.........这里部分代码省略.........
示例5: Demonstrate_Validation
public void Demonstrate_Validation()
{
var article = new Article {
Body = "Once upon a time...",
DatePosted = DateTime.Now,
Title = "A",
Comments = new List<Comment> {
new Comment { CommentersName = "Me", Body = "Some Message..." }
}
};
article.Save();
var fetched = Article.GetById(article.Id);
Assert.IsNull(fetched);
Assert.AreEqual(2, article.Errors.Count);
}
示例6: Demonstrate_SimpleLogging
public void Demonstrate_SimpleLogging()
{
var log = new List<string>();
NoRMaticConfig.SetLogListener(x => log.Add(x));
var article = new Article {
Author = "Eddie Bauer",
Body = "One, two, three, go"
};
article.Save();
var fetched = Article.All();
Assert.AreEqual(0, log.Count);
}