private void AddDataToPost(Post post, PostItemModel model, UserItemModel curUser)
        {
            post.Title     = model.Title;
            post.StartDate = model.StartDate;
            post.EndDate   = model.EndDate;
            post.ShortDesc = model.ShortDesc;
            post.FullDesc  = model.FullDesc;

            #region Image
            if (CheckHaveNewImage(post, model))
            {
                var imageUrl          = new ImageURLModel();
                var imageOriganalUrl  = $"{ImageHelper.IMAGE_URL}{model.ID}/{ImageHelper.IMAGE_ORIGINAL_Folder}/";
                var imageThumbPathURL = $"{ImageHelper.IMAGE_URL}{model.ID}/{ImageHelper.IMAGE_THUMB_Folder}/";
                var imageThumbPath    = Server.MapPath(imageThumbPathURL);
                var imageOriganalPhy  = Server.MapPath(model.AvataImage);
                imageUrl.AvataImage = new AvataImageUrlModel()
                {
                    Original = model.AvataImage,
                    Medium   = imageThumbPathURL + ImageHelper.ResizeImageMedium(imageOriganalPhy, imageThumbPath),
                    Thumb    = imageThumbPathURL + ImageHelper.ResizeImageThumb(imageOriganalPhy, imageThumbPath)
                };
                imageUrl.ImageList = ImageHelper.GetImageInFolder(Server.MapPath(imageOriganalUrl));
                post.ImageURL      = JsonConvert.SerializeObject(imageUrl);
            }
            #endregion

            #region SEO
            post.SeoTitle       = model.SeoTitle;
            post.SeoDescription = model.SeoDescription;
            post.SeoKeyword     = model.SeoKeyword;
            #endregion

            #region Add Setting

            if (!post.IsShow && model.IsShow)
            {
                post.IsShow     = model.IsShow;
                post.PublicBy   = curUser.Id;
                post.PublicDate = DateTime.Now;
            }
            post.IsHot          = model.IsHot;
            post.IsAllowComment = model.IsAllowComment;
            #endregion

            #region Add Category
            post.Categories.Clear();
            //var cat = ol.Posts.Where(model.CategoriesID.);
            #endregion
        }
 private bool CheckHaveNewImage(Post post, PostItemModel model)
 {
     if (string.IsNullOrEmpty(post.ImageURL))
     {
         return(true);
     }
     try
     {
         var oldImage = JsonConvert.DeserializeObject <ImageURLModel>(post.ImageURL);
         if (oldImage.AvataImage != null && oldImage.AvataImage.Original == model.AvataImage)
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         return(true);
     }
     return(true);
 }
        public ActionResult Create(PostItemModel model)
        {
            //var post = ol.Posts.FirstOrDefault(x => x.Id == model.ID);
            //using (var transaction = ol.Database.BeginTransaction())
            //{
            //var user = ol.Users.FirstOrDefault(x=>x.Id==model.ID);
            //try
            //{
            //    if (User.IsInRole("User") && !User.IsInRole("Admin") && !User.IsInRole("Manager"))
            //    {
            //if(post.CreateBy != User.id)
            //{
            //    return RedirectToAction("List", new { id = model.ID });
            //}
            //            }
            //        }
            //        catch (Exception ex)
            //        {

            //            throw;
            //        }
            //    }
            return(View());
        }
Ejemplo n.º 4
0
        // input vào là các giá trị của Post output là các giá trị của PostItemModel
        public static PostItemModel Convert(
            this Post post,
            bool withFullDesc = true,
            bool withUser     = false,
            bool withTag      = false,
            string catURL     = null
            )
        {
            var _return = new PostItemModel()
            {
                Id         = post.Id,
                URL        = post.URL,
                CreateDate = post.StartDate ?? post.CreateDate,
                View       = post.View
            };

            if (!string.IsNullOrEmpty(post.ImageURL))
            {
                try
                {
                    _return.ImageURL = JsonConvert.DeserializeObject <ImageURLModel>(post.ImageURL);
                }
                catch (Exception ex)
                {
                }
            }
            var cat = post.Categories.FirstOrDefault(c =>
                                                     (string.IsNullOrEmpty(catURL) ? true : c.URL.CompareTo(catURL) == 0) &&
                                                     !c.IsDeleted &&
                                                     c.IsShow
                                                     );

            if (cat != null)
            {
                _return.Category = Convert(cat);
            }

            if (withFullDesc)
            {
                _return.Title          = post.Title;
                _return.ShortDesc      = post.ShortDesc;
                _return.FullDesc       = post.FullDesc;
                _return.SeoTitle       = post.SeoTitle;
                _return.SeoKeyword     = post.SeoKeyword;
                _return.SeoDescription = post.SeoDescription;
            }
            else
            {
                _return.Title     = post.Title;
                _return.ShortDesc = StringLength.TrimLenght(post.ShortDesc, 150);//HttpUtility.HtmlDecode(Utility.TrimLength(FPTShopUtils.RemoveHTMLTag((post.ShortDesc)), 220));
            }
            if (withUser)
            {
                _return.User = Convert(post.CreateUser, withDescription: withFullDesc);
            }
            if (withTag)
            {
                if (post.Tags.Any())
                {
                    _return.Tags = Convert(post.Tags.ToList());
                }
            }
            return(_return);
        }
Ejemplo n.º 5
0
        public static PostItemModel Convert
        (
            this Post post,
            bool withFullDesc = true,
            bool withUser     = false,
            bool withTag      = false,
            string catURL     = null
        )

        {
            var _return = new PostItemModel()
            {
                ID         = post.ID,
                UrlSlug    = post.UrlSlug,
                DateCreate = post.DateCreate,
                Viewed     = post.Viewed
            };

            // xử lý nếu có hình ảnh

            if (!string.IsNullOrEmpty(post.Image))
            {
                try
                {
                    _return.Image = post.Image;
                }
                catch (Exception)
                {
                    throw;
                }
            }


            //var cat = post.Categories.FirstOrDefault(
            //    c => (string.IsNullOrEmpty(catURL) ? true : c.UrlSlug.CompareTo(catURL) == 0));

            var lt = post.Category;

            if (lt != null)
            {
                _return.Category = Convert(lt);
            }
            //if (cat != null)
            //{
            //    _return.Category = Convert(cat);
            //}
            // nếu FullDecs=true

            if (withFullDesc)
            {
                _return.Title          = post.Title;
                _return.Content        = post.Content;
                _return.SEOTitle       = post.SEOTitle;
                _return.SEOKeyword     = post.SEOKeyword;
                _return.SEODescription = post.SEODescription;
                // _return.CategoryID = post.Categories.Select(c => c.ID).ToList();
            }
            else
            {
                _return.Title   = post.Title;
                _return.Content = Utility.TrimLength(post.Content, 150);
            }


            // tạm thời chưa dùng đến

            //if (withUser)
            //{
            //    _return.LastPostUser = Convert(post.LastPostUser, withFullDesc: true);
            //}


            if (withTag)
            {
                _return.Tags = Convert(post.Tags.ToList());
            }
            return(_return);
        }