예제 #1
0
        /// <summary>
        /// Automatically parses the input string and insert the corresponding tag to db with the relation
        /// </summary>
        /// <param name="RelationId">The ID of thre related Item (might be PageId, AlbumId, ImageId) make sure that you change the type depending on your relation</param>
        /// <param name="TagType">The type of the Tag relation.</param>
        /// <param name="InputString">The input string to be parsed.</param>
        public void UpdateTags(int RelationId, HashTagTypes TagType, string InputString)
        {
            Regex r = new Regex(lw.CTE.RegularExpressions.HashTagMatcher, RegexOptions.IgnoreCase);

            StringBuilder sb = new StringBuilder();

            string sep = "";

            foreach (var tag in r.Matches(InputString))
            {
                sb.Append(sep);
                string temp = tag.ToString().Substring(1);
                if (!string.IsNullOrWhiteSpace(temp))
                {
                    sb.Append(temp);
                    sep = ",";
                }
            }
            ;

            HashTagsData.HashTags_Update(StringUtils.SQLEncode(sb.ToString()), RelationId, (short)TagType);
        }
예제 #2
0
        /// <summary>
        /// Adds the media depending on it's type
        /// </summary>
        /// <param name="Status">bool true = 1, false = 0</param>
        /// <param name="Caption">
        /// caption if coming from request
        /// or file name if caption was null
        /// or null if request file and caption were null
        /// </param>
        /// <param name="MediaFile">the media file to be added i.e.(image, video, download...)</param>
        /// <param name="MediaObject">the media object to be added i.e.(youtube link, vimeo link...)</param>
        /// <param name="Sort">int number to set the sorting</param>
        /// <param name="CreatedBy">id of the user that added the media</param>
        /// <param name="ModifiedBy">id of the user that modified/added the media</param>
        /// <param name="Tags">string of tags</param>
        /// <param name="MediaType">the type of the media, found in the Enum DefaultMediaTypes</param>
        /// <returns>data.Media records</returns>
        public data.Media AddMedia(bool?Status, string Caption, Stream MediaFile, string FileName,
                                   string MediaObject, int?Sort, int?CreatedBy, int?ModifiedBy, string Tags, DefaultMediaTypes?MediaType)
        {
            var modifier = ModifiedBy != null?ModifiedBy.GetValueOrDefault() : WebContext.Profile.UserId;

            var creator = CreatedBy != null?CreatedBy.GetValueOrDefault() : WebContext.Profile.UserId;

            byte         status      = Status.GetValueOrDefault() ? (byte)1 : (byte)0;
            string       caption     = !String.IsNullOrWhiteSpace(Caption) ? Caption : null;
            Stream       mediaFile   = MediaFile != null ? MediaFile : null;
            string       mediaObject = !String.IsNullOrWhiteSpace(MediaObject) ? MediaObject : null;
            string       tags        = !String.IsNullOrWhiteSpace(Tags) ? Tags : null;
            string       ext         = !String.IsNullOrWhiteSpace(FileName) ? Path.GetExtension(FileName) : ".jpg";
            HashTagTypes mediaType   = new HashTagTypes();

            if (caption == null && MediaFile != null)
            {
                FileStream fs = MediaFile as FileStream;
                caption = fs.Name;
            }

            data.Media media = new data.Media
            {
                Status       = status,
                Caption      = caption,
                MediaObject  = mediaObject,
                Sort         = Sort,
                ModifiedBy   = modifier,
                Tags         = tags,
                DateAdded    = DateTime.Now,
                DateModified = DateTime.Now,
                CreatedBy    = WebContext.Profile.UserId
            };

            WidgetsData.Media.InsertOnSubmit(media);
            WidgetsData.SubmitChanges();

            var mediaImage = from M in WidgetsData.Media
                             where M.Id == media.Id
                             select M;

            if (MediaType != null)
            {
                var m   = mediaImage.Single();
                int mId = media.Id;

                if (mediaFile != null)
                {
                    switch (MediaType)
                    {
                    ///adds the image itself
                    case DefaultMediaTypes.Image:
                        FileResponses image = AddImage(caption, mediaFile, ext, mId, MediaType);
                        if (image == FileResponses.Success || image == FileResponses.FileExist)
                        {
                            m.MediaFile = mediaFile != null?caption.IndexOf(ext) != -1 ? mId + "-" + caption : StringUtils.ToURL(mId + "-" + caption) + ext : null;
                        }
                        mediaType = HashTagTypes.MediaImages;
                        break;

                    ///adds the image of the video
                    case DefaultMediaTypes.Video:
                        FileResponses video = AddImage(caption, mediaFile, ext, mId, MediaType);
                        if (video == FileResponses.Success || video == FileResponses.FileExist)
                        {
                            m.MediaFile = mediaFile != null?caption.IndexOf(ext) != -1 ? mId + "-" + caption : StringUtils.ToURL(mId + "-" + caption) + ext : null;
                        }
                        mediaType = HashTagTypes.MediaVideos;
                        break;

                    ///adds the image of the embed object
                    case DefaultMediaTypes.EmbedObject:
                        FileResponses embeded = AddImage(caption, mediaFile, ext, mId, MediaType);
                        if (embeded == FileResponses.Success || embeded == FileResponses.FileExist)
                        {
                            m.MediaFile = mediaFile != null?caption.IndexOf(ext) != -1 ? mId + "-" + caption : StringUtils.ToURL(mId + "-" + caption) + ext : null;
                        }
                        mediaType = HashTagTypes.MediaEmbedObject;
                        break;

                    ///adds the download
                    case DefaultMediaTypes.Download:
                        FileResponses download = AddDownloadFile(caption, mediaFile, ext, mId);
                        if (download == FileResponses.Success || download == FileResponses.FileExist)
                        {
                            m.MediaFile = mediaFile != null?caption.IndexOf(ext) != -1 ? mId + "-" + caption : StringUtils.ToURL(mId + "-" + caption) + ext : null;
                        }
                        mediaType = HashTagTypes.MediaDownloads;
                        break;

                    case DefaultMediaTypes.PopUp:
                        FileResponses popup = AddImage(caption, mediaFile, ext, mId, MediaType);
                        if (popup == FileResponses.Success || popup == FileResponses.FileExist)
                        {
                            m.MediaFile = mediaFile != null?caption.IndexOf(ext) != -1 ? mId + "-" + caption : StringUtils.ToURL(mId + "-" + caption) + ext : null;
                        }
                        mediaType = HashTagTypes.MediaPopups;
                        break;

                    default:
                        break;
                    }
                }

                m.Type = (int)MediaType;
                WidgetsData.SubmitChanges();
            }

            HashTagsManager htMgr = new HashTagsManager();

            htMgr.UpdateTags(media.Id, mediaType, media.Caption + " " + media.Tags);
            return(media);
        }