public override MixPost ParseModel(MixCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            if (Id == 0)
            {
                Id = Repository.Max(c => c.Id, _context, _transaction).Data + 1;
                CreatedDateTime = DateTime.UtcNow;
            }
            LastModified      = DateTime.UtcNow;
            PublishedDateTime = PublishedDateTime?.ToUniversalTime();

            //  Parsing Extra Fields to json string
            var arrField = Columns != null?JArray.Parse(
                Newtonsoft.Json.JsonConvert.SerializeObject(Columns.OrderBy(c => c.Priority).Where(
                                                                c => !string.IsNullOrEmpty(c.Name)))) : new JArray();

            ExtraFields = arrField.ToString(Newtonsoft.Json.Formatting.None);

            // Parsing Extra Properties value
            if (Properties != null && Properties.Count > 0)
            {
                JArray arrProperties = new JArray();
                foreach (var p in Properties.Where(p => !string.IsNullOrEmpty(p.Value) && !string.IsNullOrEmpty(p.Name)))
                {
                    arrProperties.Add(JObject.FromObject(p));
                }
                ExtraProperties = arrProperties.ToString(Formatting.None)?.Trim();
            }

            Template = View != null?string.Format(@"{0}/{1}{2}", View.FolderType, View.FileName, View.Extension) : Template;

            if (ThumbnailFileStream != null)
            {
                string folder = CommonHelper.GetFullPath(new string[]
                {
                    MixConstants.Folder.UploadFolder, "Posts", DateTime.UtcNow.ToString("dd-MM-yyyy")
                });
                string filename      = CommonHelper.GetRandomName(ThumbnailFileStream.Name);
                bool   saveThumbnail = CommonHelper.SaveFileBase64(folder, filename, ThumbnailFileStream.Base64);
                if (saveThumbnail)
                {
                    CommonHelper.RemoveFile(Thumbnail);
                    Thumbnail = CommonHelper.GetFullPath(new string[] { folder, filename });
                }
            }
            if (ImageFileStream != null)
            {
                string folder = CommonHelper.GetFullPath(new string[]
                {
                    MixConstants.Folder.UploadFolder, "Posts", DateTime.UtcNow.ToString("dd-MM-yyyy")
                });
                string filename  = CommonHelper.GetRandomName(ImageFileStream.Name);
                bool   saveImage = CommonHelper.SaveFileBase64(folder, filename, ImageFileStream.Base64);
                if (saveImage)
                {
                    CommonHelper.RemoveFile(Image);
                    Image = CommonHelper.GetFullPath(new string[] { folder, filename });
                }
            }

            if (!string.IsNullOrEmpty(Image) && Image[0] == '/')
            {
                Image = Image.Substring(1);
            }
            if (!string.IsNullOrEmpty(Thumbnail) && Thumbnail[0] == '/')
            {
                Thumbnail = Thumbnail.Substring(1);
            }
            Tags = ListTag.ToString(Newtonsoft.Json.Formatting.None);
            GenerateSEO();

            return(base.ParseModel(_context, _transaction));
        }
Example #2
0
 public override string ToString()
 {
     return(String.Format(FootballScoreStringFormat, HomeName, AwayName, HomeScore,
                          AwayScore, Description, PublishedDateTime.ToString("r")));
 }