protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            byte[] blob = new byte[] { };
            string ContentType = string.Empty;
            BlogEntities be = new BlogEntities();
            try
            {

                if (Request.QueryString["id"] != null)
                {
                    int bid = Convert.ToInt16(Request.QueryString["id"]);

                    if (bid > 0)
                    {
                        Response.ContentType = BlogManager.getMimeType(bid);
                        blob = BlogManager.getBlob(bid);
                        Response.OutputStream.Write(blob, 0, blob.Length);
                        //Response.BinaryWrite(blob);
                        Response.End();
                    }
                }

            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }

        }
    }
Example #2
0
    /*************************************************************
    *  @type: gets connection string
    *  @usage: we will must provide the connection name to get the connection string
    *  @return: string
    *
    **************************************************************/
    public static byte[] getBlob(int bid)
    {
        byte[] blob = new byte[] { };

        List<byte[]> qry;
        try
        {
            using (BlogEntities be = new BlogEntities())
            {

                    qry = (from vid in be.binaries
                          where vid.binID == bid
                          select vid.Content).ToList();
                    blob = qry.First();
                    //foreach (byte[] m in qry)
                    //{
                    //    blob = m;
                    //}

            }
        }
        catch
        {
            throw new UnableToAccessVideo();
        }
        return blob;
    }
    private DataTable retVideo(object id)
    {
        DataTable dt = new DataTable();
        BlogEntities be= new BlogEntities();

        var qry = (from q in be.binaries
                                  where q.binID == (int)id
                                  select q).ToList();
        foreach (var item in qry)
        {
         //TO BE CONTINUED...

        }
        return dt;
    }
Example #4
0
    /*************************************************************
     *  @type: file upload
     *  @usage: this will be used on the next stage of my project
     *  @return: returns true if everything is successful
     *
     **************************************************************/
    public bool UploadVideo(FileUpload fu)
    {
        bool rtn = false;
        try
        {
            if (fu.PostedFile != null && fu.PostedFile.FileName != string.Empty)
            {

                using (BlogEntities be = new BlogEntities())
                {
                    byte[] blob = new byte[fu.PostedFile.ContentLength];
                    Stream fill = fu.FileContent;
                    fill.Read(blob, 0, fu.PostedFile.ContentLength);
                    video vinit = video.Createvideo(be.posts.Max(i => i.post_id) + 1, fu.PostedFile.FileName, blob, be.posts.Max(i => i.post_id) + 1, DateTime.Now);
                    be.AddTovideos(vinit);
                    be.SaveChanges();

                }

                rtn = true;
            }
            else
            {
                throw new UnableToUploadFile();
            }
        }
        catch
        {

            throw new UnableToAddObject();
        }

        return rtn;
    }
Example #5
0
    /*************************************************************
     *  @type: file upload
     *  @usage: this will be used on the next stage of my project
     *  @return: returns true if everything is successful
     *
     **************************************************************/
    public bool Upload(FileUpload fu)
    {
        bool rtn = false;
        try
        {
            if (fu.PostedFile != null && fu.PostedFile.FileName != string.Empty)
            {

                using (BlogEntities be = new BlogEntities())
                {
                    byte[] blob = new byte[fu.PostedFile.ContentLength];
                    Stream fill = fu.FileContent;
                    fill.Read(blob, 0, fu.PostedFile.ContentLength);
                    be.AddTobinaries(binary.Createbinary(DateTime.Now, fu.FileName, blob, fu.PostedFile.ContentType, be.binaries.Max(i => i.binID) + 1));
                    be.SaveChanges();
                }

                rtn = true;
            }
        }
        catch
        {

            throw new UnableToAddObject();
        }

        return rtn;
    }
Example #6
0
    /*************************************************************
     *  @type: method
     *  @usage: initializes the properties
     *  @return: it will return a string which contains the div that will be displayed on the blog.
     *
     **************************************************************/
    public string[] PrintBlogEntry(string categoryId, bool partial = false)
    {
        int i = 0;
        string blogtitle = string.Empty;
        string blogcontent = string.Empty;
        string[] sb = new string[] { };

        try
        {
            using (BlogEntities be = new BlogEntities())
            {

                var bcontent = from z in be.posts
                               where z.cat_id.Equals(categoryId)
                               select z;

                blogDiv(bcontent, ref sb, partial);

            }
        }
        catch
        {
            throw new UnableToAccessBlogEntry();
        }

        return sb;
    }
Example #7
0
    /*************************************************************
     *  @type: this is used for my search algorithm to find a specific string and if one is not provided it will sort the output.
     *  @usage: takes in a search string, category, type of sort required and if you would like to get part of a blog or the whole thing.
     *  @return: it will return a string which contains the div that will be displayed on the blog.
     *
     **************************************************************/
    public string[] printBlogAndSort(string search, string category, string sortType, bool partial = false)
    {
        string[] sb = new string[] { };
        IQueryable<post> qry;

        try
        {
            using (BlogEntities be = new BlogEntities())
            {

                if (sortType == "Date")
                {
                    if (search == string.Empty)
                    {
                        qry = from p in be.posts
                              orderby p.created
                              where p.cat_id.Contains(category)
                              select p;
                    }
                    else
                    {
                        DateTime date = DateTime.Parse(search);
                        qry = from p in be.posts
                              orderby p.created
                              where p.cat_id.Contains(category) && p.created.Day == date.Day && p.created.Month == date.Month
                              select p;
                    }
                }
                else
                {
                    if (search == string.Empty)
                    {

                        qry = from p in be.posts
                              orderby p.title
                              where p.cat_id.Contains(category)
                              select p;
                    }
                    else
                    {
                        qry = from p in be.posts
                              orderby p.title
                              where p.cat_id.Contains(category) && p.title.ToLower() == search.ToLower()
                              select p;

                    }

                }
                blogDiv(qry, ref sb, partial);

            }
        }
        catch
        {
            throw new UnableToSearchData();
        }

        return sb;
    }
Example #8
0
    /*************************************************************
     *  @type: Print an array of articles by searching linq query for post id
     *  @usage: just pass in a post_id
     *  @return: it will return a string which contains the div that will be displayed on the blog.
     *
     **************************************************************/
    public string[] PrintArticle(int post_id)
    {
        string[] strb = new string[] { };
        StringBuilder sb = new StringBuilder();

        try
        {
            using (BlogEntities be = new BlogEntities())
            {
                IQueryable<post> qry = from z in be.posts
                                       where z.post_id == post_id
                                       select z;
                blogDiv(qry, ref strb, false);

            }
        }
        catch
        {
            throw new UnableToAccessBlogEntry();
        }

        return strb;
    }
Example #9
0
    /*************************************************************
       *  @type: gets a commment entry to database using entities
       *  @usage: we will must provide the post id to get the database comments related to that comment
       *  @return: returns the comments for the article.
       *
       **************************************************************/
    public string getComments(int post_id)
    {
        //string[] sb = new string[] { };
        string str = string.Empty;
        try
        {
            using (BlogEntities be = new BlogEntities())
            {
                var bcomments = from p in be.posts
                                join c in be.Comments
                                on p.post_id equals c.post_id
                                where c.post_id == post_id
                                select c;

                foreach (var x in bcomments)
                {
                    str += "<div class='blogentry'><div class='socMedia'></div><div class='blogMedia'><p>" + x.comment1 +
                        "</p><h5>Edited By:" + x.author + "</h3>Date Added:" + x.date.ToString() + "</div><br /><br />";
                }

            }
        }
        catch
        {
            throw new UnableToAccessBlogEntry();
        }
        return str;
    }
Example #10
0
    /*************************************************************
    *  @type: adds a comment entry to database using entities
    *  @usage: we will must provide he arguments to insert into the database
    *  @return: returns nothing
    *
    **************************************************************/
    public void AddComment(string content, int post_id, string user, DateTime date)
    {
        try
        {
            if (!string.IsNullOrEmpty(content) && !string.IsNullOrEmpty(user) && !post_id.Equals(0))
            {
                StringBuilder cstr = new StringBuilder();
                BlogEntities ice = new BlogEntities();
                var nl = Environment.NewLine;

                //var qry = ice.Comments.Select(x => x.comment_id).ToList().Max();
                //int num = int.Parse(qry.Substring(1, 1)) + 1;
                string pk = "a" + ice.Comments.Count()+1;
                ice.AddToComments(Comment.CreateComment(pk, content, post_id, user, date));

                ice.SaveChanges();
            }

        }
        catch
        {

            throw new UnableToAddObject();
        }

        #region DIRTY CODE LINQ
        /*
                     *
                     *
            var qry = from x in source.Foo
                     where x.SomeProp == "abc"
                        select x.Bar;

            var qry = source.Foo.Where(x => x.SomeProp == "abc").Select(x => x.Bar);

                     *
                     *
                     *
                     *
                     *
                IQueryable<string> comID= from cid in ice.Comments
                                          where

                     *
                     * StringBuilder ccomment = new StringBuilder();

                        BlogEntitiesModel.BlogEntities bec = new BlogEntitiesModel.BlogEntities();

                        IQueryable<string> bcomments = from p in bec.posts
                                                       join c in bec.Comments
                                                       on p.post_id equals c.post_id
                                                        select c.comment1;

                      IQueryable<string> bcauth = from p in bec.posts
                                                       join c in bec.Comments
                                                       on p.post_id equals c.post_id
                                                       select p.author;

                      foreach (var prtComm in bcomments) {
                            ccomment.Append(prtComm+nl);
                        }

                      foreach (var prtcauth in bcauth)
                      {
                          ccomment.Append(prtcauth+nl);
                      }

                 */
        #endregion
    }
Example #11
0
    /*************************************************************
     *  @type: adds a blog entry to database using entities
     *  @usage: we will must provide he arguments to insert into the database
     *  @return: returns nothing
     *
     **************************************************************/
    public bool AddBlogEntry(string title, string user, string content, string cat = "WEPHONE")
    {
        bool added = false;
        try
        {

            if (!string.IsNullOrEmpty(cat) && !string.IsNullOrEmpty(content))
            {

                using (BlogEntities be = new BlogEntities())
                {                               //This is auto increment using linq
                    post pt = post.Createpost(be.posts.Max(i => i.post_id) + 1, user, title, content, DateTime.Now);
                    pt.comments = false;
                    pt.cat_id = cat;
                    if (pt != null) added = true;

                    //var be = new BlogEntry();
                    be.AddToposts(pt);
                    be.SaveChanges();

                }
            }
        }
        catch
        {

            throw new UnableToAddObject();
        }

        return added;
    }
Example #12
0
    public static IQueryable<video> getVideoIdByName(string tit)
    {
        BlogEntities be = new BlogEntities();
        IQueryable<video> qry;
        try
        {
            qry = from vid in be.videos
                  where vid.Title.Contains(tit)
                  select vid;

        }
        catch
        {
            throw new UnableToAccessVideo();
        }

        return qry;
    }
Example #13
0
    public static byte[] getVideoBlob(int bid)
    {
        byte[] blob = new byte[] { };

        try
        {
            BlogEntities be = new BlogEntities();

            List<byte[]> qry = (from vid in be.videos
                                     where vid.videoID == bid
                                     select vid.Content).ToList();

            blob = qry.First();
            //foreach (var m in qry)
            //{
             //   blob = m.Content;
            //}

        }
        catch
        {
            throw new UnableToAccessVideo();
        }

        return blob;
    }
Example #14
0
    public static string getMimeType(int bid)
    {
        string ContentType = string.Empty;
        BlogEntities be = new BlogEntities();

        try
        {
            IQueryable<binary> qry = from vid in be.binaries
                                     where vid.binID == bid
                                     select vid;
            foreach (var m in qry)
            {
                ContentType = m.MimeType;
            }

        }
        catch
        {
            throw new UnableToAccessImage();
        }

        return ContentType;
    }
Example #15
0
 public void getBlogEntry()
 {
     var x = new BlogEntities();
     x.posts.Select(z => z.cat_id == "WEPHONE");
 }