Пример #1
0
        public ActionResult Compose(string id)
        {
            DraftPost post = new DraftPost();

            if (!string.IsNullOrEmpty(id))
            {
                post = DraftComp.Load(id);
                this.Session["Post"] = post;
            }
            else
            {
                if (this.Session["Post"] == null)
                {
                    TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(SettingsComp.GetSettings().Timezone);
                    post.Time = LocalTime.GetCurrentTime(tzi);
                    post.Type = PostType.New;
                    this.Session["Post"] = post;
                }
                else
                {
                    post = this.Session["Post"] as DraftPost;
                }
            }

            ComposePostModel model = new ComposePostModel();
            model.Title = post.Title;
            model.PublishDate = post.Time.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);
            List<string> catList = new List<string>();
            if (!string.IsNullOrEmpty(post.CatID))
            {
                string[] catIDs = post.CatID.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string catID in catIDs)
                {
                    catList.Add(catID);
                }
            }

            model.CatID = catList;
            model.Content = post.Contents;
            model.DraftID = post.DraftID;
            model.Post = post;

            this.Response.Cache.SetCacheability(HttpCacheability.NoCache);

            this.ViewData.Model = model;
            return this.View();
        }
Пример #2
0
        /// <summary>
        /// Strange method, got to look into it
        /// </summary>
        /// <param name="model">
        /// The model
        /// </param>
        private void UpdatePost(ComposePostModel model)
        {
            DraftPost post = new DraftPost();
            if (this.Session["Post"] != null)
            {
                post = this.Session["Post"] as DraftPost;
            }

            model.Title = model.Title ?? string.Empty;
            post.Title = model.Title;
            post.CatID = string.Empty;
            if (model.CatID != null)
            {
                foreach (string catID in model.CatID)
                {
                    post.CatID += catID + ",";
                }

                post.CatID = post.CatID.Substring(0, post.CatID.Length - 1);
            }

            if (post.Type == PostType.New)
            {
                try
                {
                    if (!string.IsNullOrEmpty(model.PublishDate))
                    {
                        post.Time = DateTime.ParseExact(model.PublishDate, "MM/dd/yyyy", CultureInfo.InvariantCulture);
                        TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(SettingsComp.GetSettings().Timezone);
                        DateTime now = LocalTime.GetCurrentTime(tzi);
                        post.Time = post.Time.AddHours(now.Hour);
                        post.Time = post.Time.AddMinutes(now.Minute);
                    }
                }
                catch
                {
                }
            }

            // To avoid exception in syntax highlighter
            post.Contents = model.Content ?? string.Empty;
            post.Author = this.User.Identity.Name;
            model.Post = post;

            this.Session["Post"] = post;
        }
Пример #3
0
        public ActionResult Upload(ComposePostModel model)
        {
            this.UpdatePost(model);

            for (int i = 0; i < this.Request.Files.Count; i++)
            {
                HttpPostedFileBase file = this.Request.Files[i];
                if (file.ContentLength > 0)
                {
                    string docPath = this.Server.MapPath(this.Url.Content("~/Docs/"));
                    string fileName = DraftComp.StoreDocument(file, docPath);
                    Document doc = new Document();
                    doc.Path = this.Url.Content(string.Format("~/Docs/{0}", fileName));
                    model.Post.Documents.Add(doc);
                }
            }

            this.Session["Post"] = model.Post;
            return this.RedirectToAction("Compose", new { id = string.Empty });
        }
Пример #4
0
        public ActionResult Save(ComposePostModel model)
        {
            this.UpdatePost(model);

            // if (ModelState.IsValid)
            // {
            // SavePost(model.Post);
            // }

            // ViewData.Model = model;
            // return View();
            this.SavePost(model.Post);
            DateTime now =
                LocalTime.GetCurrentTime(TimeZoneInfo.FindSystemTimeZoneById(SettingsComp.GetSettings().Timezone));
            return this.PartialView("AutoSaveControl", now);
        }
Пример #5
0
 public ActionResult Close(ComposePostModel model)
 {
     this.Session.Remove("Post");
     return this.RedirectToAction("ManageDraft");
 }
Пример #6
0
        public ActionResult Publish(ComposePostModel model)
        {
            this.UpdatePost(model);

            if (this.ModelState.IsValid)
            {
                model.Post = this.SavePost(model.Post);
                PublisherComp.Publish(model.Post);
                this.Session.Remove("Post");
                this.TempData["Message"] = "发布成功";
                return this.RedirectToAction("Manage");
            }

            this.ViewData.Model = model;
            return this.View();
        }
Пример #7
0
        public ActionResult Preview(ComposePostModel model)
        {
            this.UpdatePost(model);
            DraftPost post = model.Post;
            post.CategoriesText = PostComp.GetCategories(post.CatID);

            // get current user
            string author = this.User.Identity.Name;
            post.TimeText = PostComp.GetTime(post.Time, author);
            return View("Preview", model.Post);
        }