コード例 #1
0
        public BlogEntryModel(Store_NewsItem ni, bool expanded = false)
        {
            id = ni.sn_id;
            author_name = ni.User.firstName + " " + ni.User.lastName;
            title = ni.title;
            description = getSummary(ni);
            img = ni.img;
            is_draft = ni.is_draft == true;
            is_featured = ni.is_featured == true;

            if (ni.date_added.HasValue)
            {
                dateadded = ni.date_added.Value;
                dateadded_short = String.Format("{0:MMMM d}", ni.date_added.Value);
            }

            if (expanded)
            {
                body_text = ni.text;

                if (ni.last_modified.HasValue)
                {
                    lastmodified = ni.last_modified.Value;
                    lastmodified_short = String.Format("{0:MMMM d}", ni.last_modified.Value);
                }
            }
        }
コード例 #2
0
        public ActionResult UpdateBlog(BlogEntryModel update)
        {
            SIEBUEntities db = new SIEBUEntities();
            Store_NewsItem target_entry = db.Store_NewsItem.FirstOrDefault(ni => ni.sn_id == update.id);

            //if no id is given, create new blog entry
            bool add_new = false;
            if (target_entry == null)
            {
                add_new = true;
                target_entry = new Store_NewsItem();
                target_entry.store_id = update.store_id;
                target_entry.author_id = WebSecurity.CurrentUserId;
                target_entry.date_added = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));
            }

            target_entry.title = update.title;
            target_entry.last_modified = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));
            target_entry.description = update.description;
            target_entry.text = update.body_text;

            target_entry.is_featured = update.is_featured;
            if (update.is_featured)
            {
                target_entry.featured_since = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));

            }
            else
            {
                target_entry.featured_since = null;
            }

            target_entry.is_draft = update.is_draft;

            if (add_new)
            {
                db.Store_NewsItem.Add(target_entry);
                db.SaveChanges();
            }

            //if the update is not equal to the target image
            if (target_entry.img == null || !(update.img + "").Contains(target_entry.img)) //target_entry.img != update.img)
                target_entry.img = update.img != null ? ImageController.UploadFile(update.img, update.store_id + "" + target_entry.sn_id) : null; //no unique file name required  + "" + target_entry.last_modified.Value.ToString("ffffff")

            db.SaveChanges();
            return Json(target_entry.sn_id, JsonRequestBehavior.AllowGet);
        }
コード例 #3
0
 //create headline using blog object
 public HeadlineModel(Store_NewsItem ni)
 {
     title = ni.title;
     image = ni.img;
     body = BlogEntryModel.getSummary(ni, 500); //description unused
     url = String.Format("/{0}/blog?id={1}", ni.Store.name_space, ni.sn_id);
     if (ni.featured_since.HasValue) date = ni.featured_since.Value;
 }
コード例 #4
0
        /// <summary>
        /// This function takes a news item, and checks whether or not a preexisting description exists. If no description is found,
        /// the body text of the blog is stripped of HTML tags, and reduced to the closest length that ends
        /// on one of multiple provided delimiters.
        /// </summary>
        /// <param name="ni"></param>
        /// <param name="char_lim"></param>
        /// <returns></returns>
        public static string getSummary(Store_NewsItem ni, int char_lim = 250)
        {
            if (ni.description != null && ni.description.Length > 0) return ni.description;

            string output = ni.text;

            output = Regex.Replace(output, @"<(.|\n)*?>", string.Empty);

            int length = output.Length;
            if (length > char_lim)
            {
                string[] delimiters = { ", ", ". ", "</p>" };
                foreach (string delim in delimiters)
                {
                    if (output.Contains(delim) && output.LastIndexOf(delim, char_lim) > 0)
                        length = (output.LastIndexOf(delim, char_lim)) + delim.Length;
                }
                output = output.Substring(0, length);
            };

            return output;
        }