Example #1
0
        /// <summary>
        /// Updates the media
        /// </summary>
        /// <param name="MediaId">Id of the media to be updated</param>
        /// <param name="MediaType">the type of the media, found in the Enum DefaultMediaTypes</param>
        /// <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="DeleteOldFile">bool to determin if we should delete the old file or not</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="ModifiedBy">id of the user that modified/added the media</param>
        /// <param name="Tags">string of tags</param>
        /// <returns>true if success, false if not</returns>
        public bool UpdateMedia(int MediaId, DefaultMediaTypes?MediaType, bool?Status, string Caption, HttpPostedFile MediaFile, bool DeleteOldFile, string MediaObject, int?Sort, int?ModifiedBy, string Tags)
        {
            data.Media thisMedia = GetMedia(MediaId);

            if (thisMedia == null)
            {
                return(false);
            }

            var modifier = ModifiedBy != null?ModifiedBy.GetValueOrDefault() : WebContext.Profile.UserId;

            byte   status  = Status.GetValueOrDefault() ? (byte)1 : (byte)0;
            string caption = !String.IsNullOrWhiteSpace(Caption) ? Caption : MediaFile != null?Path.GetFileNameWithoutExtension(MediaFile.FileName) : null;

            HttpPostedFile mediaFile   = MediaFile != null ? MediaFile : null;
            string         mediaObject = !String.IsNullOrWhiteSpace(MediaObject) ? MediaObject : null;
            string         tags        = !String.IsNullOrWhiteSpace(Tags) ? Tags : null;

            if (MediaType != null)
            {
                int mId = thisMedia.Id;

                if (mediaFile != null)
                {
                    string OldFileName    = thisMedia.MediaFile;
                    string FileDateFolder = string.Format("{0:MM-yyyy}", thisMedia.DateAdded);

                    switch (MediaType)
                    {
                    ///adds the image itself
                    case DefaultMediaTypes.Image:
                        FileResponses image = UpdateFile(mediaFile, mId, DeleteOldFile, OldFileName, FileDateFolder, MediaType);
                        if (image == FileResponses.Success)
                        {
                            thisMedia.MediaFile = mediaFile != null ? mId + "-" + mediaFile.FileName : null;
                        }
                        break;

                    ///adds the image of the video
                    case DefaultMediaTypes.Video:
                        FileResponses video = UpdateFile(mediaFile, mId, DeleteOldFile, OldFileName, FileDateFolder, MediaType);
                        if (video == FileResponses.Success)
                        {
                            thisMedia.MediaFile = mediaFile != null ? mId + "-" + mediaFile.FileName : null;
                        }
                        break;

                    ///adds the download
                    case DefaultMediaTypes.Download:
                        FileResponses download = UpdateFile(mediaFile, mId, DeleteOldFile, OldFileName, FileDateFolder, MediaType);
                        if (download == FileResponses.Success)
                        {
                            thisMedia.MediaFile = mediaFile != null ? mId + "-" + mediaFile.FileName : null;
                        }
                        break;

                    default:
                        break;
                    }
                }
                thisMedia.Type = (int)MediaType;
            }

            thisMedia.Status       = status;
            thisMedia.Caption      = caption;
            thisMedia.MediaObject  = mediaObject;
            thisMedia.Sort         = Sort;
            thisMedia.DateModified = DateTime.Now;
            thisMedia.ModifiedBy   = modifier;
            thisMedia.Tags         = tags;

            WidgetsData.SubmitChanges();

            HashTagsManager htMgr = new HashTagsManager();

            htMgr.UpdateTags(thisMedia.Id, HashTagTypes.Media, thisMedia.Caption + " " + thisMedia.Tags);
            return(true);
        }
Example #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);
        }