Exemplo n.º 1
0
        public static string Update(int ID, string Title, string Content, string Image, int Featured, int CategoryID, int Status, string PostSlug, string ModifiedBy, DateTime ModifiedDate)
        {
            using (var dbe = new inventorymanagementEntities())
            {
                tbl_Post ui = dbe.tbl_Post.Where(a => a.ID == ID).SingleOrDefault();
                if (ui != null)
                {
                    ui.Title        = Title;
                    ui.Content      = Content;
                    ui.Image        = Image;
                    ui.Featured     = Featured;
                    ui.CategoryID   = CategoryID;
                    ui.Status       = Status;
                    ui.ModifiedBy   = ModifiedBy;
                    ui.ModifiedDate = ModifiedDate;
                    ui.Slug         = checkSlug(Slug.ConvertToSlug(PostSlug != "" ? PostSlug : Title), ui.ID);

                    int kq = dbe.SaveChanges();
                    return(ui.ID.ToString());
                }
                else
                {
                    return(null);
                }
            }
        }
Exemplo n.º 2
0
        public static List <Tag> insert(List <TagModel> tagList, tbl_Account acc)
        {
            using (var con = new inventorymanagementEntities())
            {
                var now      = DateTime.Now;
                var textInfo = new CultureInfo("vi-VN", false).TextInfo;

                var tagNew = tagList.Where(x =>
                                           x.slug.StartsWith(String.Format("tag-new-{0:yyyyMMdd}", now))
                                           )
                             .Select(x => new Tag
                {
                    Name        = textInfo.ToLower(x.name.Trim()),
                    Slug        = Slug.ConvertToSlug(x.name.Trim()),
                    CreatedBy   = acc.ID,
                    CreatedDate = now
                })
                             .ToList();

                // Check unique slug
                foreach (var tag in tagNew)
                {
                    var tagLast = con.Tags.Where(x => x.Slug.StartsWith(tag.Slug))
                                  .OrderByDescending(o => o.ID)
                                  .FirstOrDefault();

                    if (tagLast != null)
                    {
                        var strIndex = Regex.Match(tagLast.Slug, @"\d+$").Value;
                        if (!String.IsNullOrEmpty(strIndex))
                        {
                            tag.Slug = String.Format("{0}-{1}", tag.Slug, Convert.ToInt32(strIndex) + 1);
                        }
                        else
                        {
                            tag.Slug = String.Format("{0}-{1}", tag.Slug, 1);
                        }
                    }
                }

                con.Tags.AddRange(tagNew);
                con.SaveChanges();

                return(tagNew);
            }
        }