Пример #1
0
        /// <summary>
        /// Deletes the media based on it's Id
        /// </summary>
        /// <param name="MediaId">Id of the media to be deleted</param>
        /// <returns>true if sucess, false if not</returns>
        public bool DeleteMedia(int MediaId)
        {
            var query = from M in WidgetsData.Media
                        where M.Id == MediaId
                        select M;

            if (query.Count() > 0)
            {
                var q = query.Single();

                DefaultMediaTypes T              = (DefaultMediaTypes)q.Type;
                string            FileName       = q.MediaFile;
                string            FileDateFolder = string.Format("{0:MM-yyyy}", q.DateAdded);

                FileResponses d = DeleteFile(FileName, T, FileDateFolder);
                if (d == FileResponses.Error || d == FileResponses.FileNotFound)
                {
                    return(false);
                }

                WidgetsData.Media.DeleteOnSubmit(q);
                WidgetsData.SubmitChanges();
                return(true);
            }
            return(false);
        }
Пример #2
0
        /// <summary>
        /// Deletes the record of the specified widget
        /// </summary>
        /// <param name="WidgetId">Id of the widget to be delted</param>
        /// <returns>Returns true if success and false on error</returns>
        public bool DeleteWidget(int WidgetId)
        {
            MediaManager mMgr = new MediaManager();

            data.Widget thisWidget = GetWidget(WidgetId);
            string      sql        = "Select MediaId From MediaWidgets Where WidgetId = {0}";

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

            int widgetId = thisWidget.Id;

            var d = DBUtils.GetDataSet(string.Format(sql, widgetId), cte.lib).Tables[0].Rows;

            int[] MediaIds = new int[d.Count];
            for (int i = 0; i < d.Count; i++)
            {
                MediaIds[i] = Int32.Parse(d[i]["MediaId"].ToString());
            }
            mMgr.DeleteMediaFromWidget(MediaIds, widgetId);

            WidgetsData.Widgets.DeleteOnSubmit(thisWidget);
            WidgetsData.SubmitChanges();

            return(true);
        }
Пример #3
0
        /// <summary>
        /// Updates the widget based on the given params, params are nullable,
        /// if all were null no update shall occur.
        /// </summary>
        /// <param name="WidgetId">WidgetId, used to get the required widget</param>
        /// <param name="PageId">Id of the page to wich the widget is attached</param>
        /// <param name="Status">Status of the widget, 1/0 => true/false</param>
        /// <param name="Type">Type of the widget, we get it from the enum "DefaultWidgetsTypes" under Media project => enum.cs</param>
        /// <param name="Title">Title of the widget</param>
        /// <returns>true if success and false if widget not found</returns>
        public bool UpdateWidget(int WidgetId, int?PageId, bool?Status, int?Type, string Title)
        {
            data.Widget thisWidget = GetWidget(WidgetId);

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

            byte status = Status.GetValueOrDefault() ? (byte)1 : (byte)0;
            int  pageid = PageId.GetValueOrDefault();

            thisWidget.PageId       = pageid;
            thisWidget.Status       = status;
            thisWidget.Type         = Type;
            thisWidget.Title        = Title;
            thisWidget.ModifiedBy   = WebContext.Profile.UserId;
            thisWidget.DateModified = DateTime.Now;

            WidgetsData.SubmitChanges();
            return(true);
        }
Пример #4
0
        /// <summary>
        /// Adds the widgets to the table having all needed parameters
        /// </summary>
        /// <param name="PageId">The Id of the Page to which the widget will be related</param>
        /// <param name="Status">Status of the widget (1=>true, 0=>false) with DB type bit/tinyint</param>
        /// <param name="Type">Type of widget, we get it from the enum "DefaultWidgetsTypes" under Media project => enum.cs</param>
        /// <param name="Title">Title of the widget</param>
        /// <param name="CreatedBy">CreatorId of the creator of the widget</param>
        /// <param name="ModifiedBy">CreatorId of the modifier of the widget</param>
        /// <returns></returns>
        public data.Widget AddWidget(int?PageId, bool?Status, int Type, string Title, int CreatedBy, int ModifiedBy, DateTime?ExpiratinDate)
        {
            byte status = Status.GetValueOrDefault() ? (byte)1 : (byte)0;
            int  pageid = PageId.GetValueOrDefault();

            data.Widget widget = new data.Widget
            {
                PageId         = pageid,
                Status         = status,
                Type           = Type,
                Title          = Title,
                DateAdded      = DateTime.Now,
                DateModified   = DateTime.Now,
                ExpirationDate = ExpiratinDate,
                CreatedBy      = CreatedBy,
                ModifiedBy     = ModifiedBy
            };

            WidgetsData.Widgets.InsertOnSubmit(widget);
            WidgetsData.SubmitChanges();

            return(widget);
        }
Пример #5
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);
        }
Пример #6
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);
        }