当前位置: 首页>>代码示例>>C#>>正文


C# Source.Save方法代码示例

本文整理汇总了C#中Source.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Source.Save方法的具体用法?C# Source.Save怎么用?C# Source.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Source的用法示例。


在下文中一共展示了Source.Save方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UploadContent

        public static Content UploadContent()
        {
            try
            {
                Content content = (Content)Provider.CreateEntity("Content");
                content.SetFieldsByPostData(Provider.Request.Form);

                string authorName = Provider.Request.Form["Author"];
                if (!string.IsNullOrWhiteSpace(authorName))
                {
                    Author author = (Author)Provider.Database.Read(typeof(Author), "Name={0}", authorName);
                    bool authorVarAmaResmiYok = author != null && String.IsNullOrEmpty(author.Picture);
                    if (author == null || authorVarAmaResmiYok)
                    {
                        if (author == null)
                            author = new Author();
                        author.Name = authorName;
                        string authorPicture = Provider.Request.Form["AuthorPicture"];
                        if (authorPicture != null && authorPicture.StartsWith("http://"))
                        {
                            try
                            {
                                string imgFileName = Provider.AppSettings["authorDir"] + "/" + author.Name.MakeFileName() + "_" + (DateTime.Now.Millisecond % 1000) + authorPicture.Substring(authorPicture.LastIndexOf('.'));
                                WebClient wc = new WebClient();
                                wc.Proxy.Credentials = CredentialCache.DefaultCredentials;
                                wc.DownloadFile(authorPicture, Provider.MapPath(imgFileName));
                                author.Picture = imgFileName;
                            }
                            catch (Exception ex)
                            {
                                Provider.Log("Notice", "UploadContent", ex.Message + "\n (Yazar resmi:" + author.Picture + ")");
                                author.Picture = "";
                            }
                        }
                        author.Save();
                    }
                    content.AuthorId = author.Id;
                }

                string sourceName = Provider.Request.Form["Source"];
                if (!string.IsNullOrWhiteSpace(sourceName))
                {
                    Source source = (Source)Provider.Database.Read(typeof(Source), "Name={0}", sourceName);
                    if (source == null)
                    {
                        source = new Source();
                        source.Name = sourceName;
                        source.Save();
                    }
                    content.SourceId = source.Id;
                }

                string categoryTitle = Provider.Request.Form["Category"];
                if (!string.IsNullOrWhiteSpace(categoryTitle))
                {
                    Content category = (Content)Provider.Database.Read(typeof(Content), "Title={0}", categoryTitle);
                    if (category == null)
                    {
                        category = new Content();
                        category.ClassName = "Category";
                        category.CategoryId = 2; // int.Parse(Provider.AppSettings["newsParentCatId"]);
                        category.Title = categoryTitle;
                        category.Save();
                    }
                    content.CategoryId = category.Id;
                }

                content.Save();

                return Provider.Database.Read<Content>(content.Id);
            }
            catch (Exception ex)
            {
                Provider.Log("Error", "UploadContent", Provider.ToString(ex, true, true, true));
                return null;
            }
        }
开发者ID:fizikci,项目名称:Cinar,代码行数:77,代码来源:Provider.cs


注:本文中的Source.Save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。