Пример #1
0
 public ActionResult edit(Text model)
 {
     var text = uow.tc.Texts.Where(d => d.Id == model.Id).FirstOrDefault();
     UpdateModel(text);
     if (ModelState.IsValid)
     {
         uow.tc.SaveChanges();
         ViewData["readyControl"] = true;
         return PartialView("_SingleText", text);
     }
     else
         return PartialView("_TextEdit", text);
 }
Пример #2
0
 public static void PullTextFiles()
 {
     try
     {
         string filePath = FilePath;
         string repoPath = RepoPath;
         if (Directory.Exists(filePath) && Directory.Exists(repoPath))
         {
             logger.Debug("Pulling texts from " + filePath);
             using (UnitOfWork uow = new UnitOfWork())
             {
                 string headSha = GitHelper.GetHeadCommitSha(repoPath);
                 if (uow.tc.Settings.First().HeadSha != headSha)
                 {
                     foreach (var file in Directory.GetFiles(filePath))
                     {
                         try
                         {
                             string fileData = File.ReadAllText(file);
                             string urlTitle = Path.GetFileNameWithoutExtension(file);
                             Text model = fileData.ToText();
                             var text = uow.tc.Texts.Where(d => d.UrlTitle == urlTitle).FirstOrDefault();
                             if (text != null)
                             {
                                 text.Posted = model.Posted;
                                 text.Title = model.Title;
                                 text.Article = model.Article;
                                 text.Updated = DateTime.Now;
                                 logger.Debug("Updated " + text.Title);
                             }
                             else
                             {
                                 Text newText = new Text()
                                 {
                                     Article = model.Article,
                                     Posted = model.Posted,
                                     Title = model.Title,
                                     UrlTitle = urlTitle,
                                     Updated = DateTime.Now
                                 };
                                 uow.tc.Texts.Add(newText);
                                 logger.Debug("Added " + newText.Title);
                             }
                         }
                         catch (Exception ex)
                         {
                             logger.ErrorException("Failed to update text file " + file, ex);
                         }
                     }
                     uow.tc.Settings.First().HeadSha = headSha;
                     uow.tc.SaveChanges();
                     logger.Debug("Successfully completed pull");
                 }
                 else
                     logger.Debug("HEAD is same as last pull");
             }
         }
         else
             logger.Debug("Missing TextFiles path or git repo");
     }
     catch (Exception ex)
     {
         logger.ErrorException("Failed to update text files", ex);
     }
 }
Пример #3
0
        public static Text ToText(this string fileData)
        {
            Text text = new Text();
            StringReader sr = new StringReader(fileData);
            sr.ReadLine();
            string posted = sr.ReadLine();
            string title = sr.ReadLine();
            sr.ReadLine();
            string article = sr.ReadToEnd();

            posted = posted.Replace("Posted: ", "");
            text.Posted = DateTime.Parse(posted);
            text.Title = title.Replace("Title: ", "");
            text.Article = article;
            return text;
        }