Exemple #1
0
        public Media get_by_id(Int32 id)
        {
            media m = db.medias.Single(x => x.id == id);

            Media md = new Media();

            md.approved      = m.approved;
            md.createdate    = Convert.ToDateTime(m.createdate);
            md.description   = m.description;
            md.full_name     = m.full_name;
            md.latitude      = m.latitude;
            md.likes         = m.likes;
            md.link          = m.link;
            md.location_name = m.location_name;
            md.longitude     = m.longitude;
            md.profilepic    = m.profilepic;
            md.service       = m.service;
            md.username      = m.username;
            md.source_id     = m.source_id;
            md.width         = m.width;
            md.height        = m.height;
            md.is_video      = m.is_video;
            md.source        = m.source;
            md.tags          = m.tags;
            md.approved_by   = m.approved_by;
            md.approved_date = m.approved_date;
            md.id            = m.id;
            md.event_id      = m.event_id;
            md.template_id   = m.template_id;

            return(md);
        }
Exemple #2
0
        /// <summary>
        /// Thread body
        /// </summary>
        /// <param name="state"></param>
        private void StartWork_SaveAMedia(object state)
        {
            ShopproHelper.ShowBusyIndicator(this, "Saving this new media to libary...");

            MediaView mediaView  = state as MediaView;
            media     savedMedia = null;
            media     theMedia   = new media();

            mediaView.Merge(theMedia, DataFormMode.AddNew);

            // Get file content
            byte[] content = ShopproHelper.ReadFully(fileInfo.OpenRead());

            // Save to the backend
            EventHandler <createNew_MediaCompletedEventArgs> h1 = (s, e) =>
            {
                // TODO: handle error from server side
                savedMedia = e.Result;
                nextOneAutoResetEvent.Set();
            };

            Globals.WSClient.createNew_MediaCompleted += h1;
            Globals.WSClient.createNew_MediaAsync(theMedia, content);
            nextOneAutoResetEvent.WaitOne();
            Globals.WSClient.createNew_MediaCompleted -= h1;

            // Check return result. If failure, savedCategory will be null
            if (savedMedia != null)
            {
                this.ResultingImageUrl = savedMedia.myUrl;

                this.Dispatcher.BeginInvoke(delegate()
                {
                    mediaView.Restore(new MediaView(savedMedia));
                });
            }
            else
            {
                // Show error message
                ShopproHelper.ShowMessageWindow(this, "Error", "Fail to save this entry.", false);
            }

            this.fileInfo = null;

            // Hide busy indicator
            ShopproHelper.HideBusyIndicator(this);

            // Now close the window
            this.Dispatcher.BeginInvoke(delegate()
            {
                Debug.WriteLine("Going to call Close().");
                // This will close this window automatically: http://msdn.microsoft.com/en-us/library/system.windows.controls.childwindow.close%28VS.95%29.aspx
                this.DialogResult = true;
                Debug.WriteLine("Called Close().");
            });
        }
Exemple #3
0
 public MediaView(media origianl)
 {
     this.id          = origianl.id;
     this.title       = origianl.title;
     this.caption     = origianl.caption;
     this.description = origianl.description;
     this.updated     = origianl.updated;
     this.myUrl       = origianl.myUrl;
     this.fileName    = origianl.fileName;
 }
Exemple #4
0
        public Boolean unapprove(Int32 id)
        {
            media md = db.medias.Single(x => x.id == id);

            md.approved_date = null;
            md.approved      = false;
            md.approved_by   = null;

            db.SubmitChanges();

            return(true);
        }
Exemple #5
0
        public Media approve(Media m)
        {
            media md = db.medias.Single(x => x.id == m.id);

            md.approved      = true;
            md.approved_by   = m.approved_by;
            md.approved_date = DateTime.Now;

            db.SubmitChanges();

            m.approved_date = DateTime.Now;

            return(m);
        }
Exemple #6
0
        /// <summary>
        /// View -> Model
        /// </summary>
        /// <param name="origianl"></param>
        public void Merge(media original, DataFormMode editMode)
        {
            if (editMode == DataFormMode.Edit)
            {
                original.id          = this.id;
                original.idSpecified = true;
            }
            else
            {
                original.idSpecified = false;
            }

            original.caption          = this.caption;
            original.description      = this.description;
            original.myUrl            = null; // myUrl is readonly. We set it as null here.
            original.title            = this.title;
            original.fileName         = this.fileName;
            original.updated          = this.updated;
            original.updatedSpecified = true;   // MUST
        }
        /// <summary>
        /// Thread body
        /// </summary>
        /// <param name="state"></param>
        private void StartWork(object state)
        {
            MediaView mediaView  = state as MediaView;
            media     savedMedia = null;
            media     theMedia   = new media();

            mediaView.Merge(theMedia, editMode);

            // Save to backend
            if (this.editMode == DataFormMode.Edit)
            {
                // Edit mode
                AutoResetEvent nextOneAutoResetEvent           = new AutoResetEvent(false);
                EventHandler <save_MediaCompletedEventArgs> h1 = (s, e) =>
                {
                    // TODO: handle error from server side
                    savedMedia = e.Result;
                    nextOneAutoResetEvent.Set();
                };
                Globals.WSClient.save_MediaCompleted += h1;
                Globals.WSClient.save_MediaAsync(theMedia);
                nextOneAutoResetEvent.WaitOne();
                Globals.WSClient.save_MediaCompleted -= h1;
            }
            else
            {
                //
                // Add new mode
                //

                // Get file content
                byte[] content = ShopproHelper.ReadFully(fileInfo.OpenRead());

                // Save to the backend
                AutoResetEvent nextOneAutoResetEvent = new AutoResetEvent(false);
                EventHandler <createNew_MediaCompletedEventArgs> h3 = (s, e) =>
                {
                    // TODO: handle error from server side
                    savedMedia = e.Result;
                    nextOneAutoResetEvent.Set();
                };
                Globals.WSClient.createNew_MediaCompleted += h3;
                Globals.WSClient.createNew_MediaAsync(theMedia, content);
                nextOneAutoResetEvent.WaitOne();
                Globals.WSClient.createNew_MediaCompleted -= h3;
            }

            // Check return result. If failure, savedCategory will be null
            if (savedMedia != null)
            {
                this.Dispatcher.BeginInvoke(delegate()
                {
                    mediaView.Restore(new MediaView(savedMedia));
                });
            }
            else
            {
                // Show error message
                ShopproHelper.ShowMessageWindow(this, "Error", "Fail to save this entry.", false);

                // Back to readonly mode
                this.Dispatcher.BeginInvoke(delegate()
                {
                    // Restore cached UI data
                    mediaView.CancelEdit();
                    this.mediaDataForm.CancelEdit();
                });
            }

            // No unsaved item
            this.editMode = DataFormMode.ReadOnly;
            this.fileInfo = null;

            // Hide busy indicator
            ShopproHelper.HideBusyIndicator(this);

            // Go to original page if necessary
            if (this.ContentPageCtx.GotoAddNewPage)
            {
                ShopproHelper.GoToContentPage(this, PageEnum.MediaListPage);
            }
        }
Exemple #8
0
        public Media add(Media m)
        {
            media md = new media();

            md.added_to_db_date = DateTime.Now;

            //if (!_settings.moderate_event())
            //{
            //    md.approved = true;
            //    md.approved_by = 1;
            //    md.approved_date = DateTime.Now;
            //}
            //else
            //{
            //    md.approved = false;
            //    md.approved_by = null;
            //    md.approved_date = null;
            //}

            if (m.approved == true)
            {
                md.approved      = true;
                md.approved_by   = m.approved_by;
                md.approved_date = m.approved_date;
            }
            else
            {
                md.approved      = false;
                md.approved_by   = null;
                md.approved_date = null;
            }

            md.createdate    = m.createdate;
            md.description   = m.description;
            md.full_name     = m.full_name;
            md.latitude      = m.latitude;
            md.likes         = m.likes;
            md.link          = m.link;
            md.location_name = m.location_name;
            md.longitude     = m.longitude;
            md.profilepic    = m.profilepic;
            md.service       = m.service;
            md.username      = m.username;
            md.source_id     = m.source_id;
            md.width         = m.width;
            md.height        = m.height;
            md.is_video      = m.is_video;
            md.source        = m.source;
            md.tags          = m.tags;
            md.event_id      = m.event_id;
            md.template_id   = m.template_id;

            var result = from med in db.medias
                         where med.source_id == md.source_id
                         select med;

            if (result.Count() == 0)
            {
                db.medias.InsertOnSubmit(md);

                db.SubmitChanges();
            }

            m.id = md.id;

            return(m);
        }