Esempio n. 1
0
        public ActionResult Create(Post_Table post, Article article, Comment comment)
        {
            try
            {
                using (PostEntity pe = new PostEntity())
                {
                    DomainTech.DomainTechService dt         = new DomainTech.DomainTechService();
                    List <Domain_Table>          DomainList = dt.GetDomainList();
                    ViewBag.DomainList = new SelectList(DomainList, "did", "domain");

                    pe.Configuration.ProxyCreationEnabled = false;

                    List <Technology_Table> TechnologyList = dt.GetTechforDomain(post.domain);
                    ViewBag.TechnologyList = new SelectList(TechnologyList, "tid", "technology");

                    //Get the Domain ID
                    int did = Convert.ToInt32(article.Post.domain);
                    //Get the Technology ID
                    int tid = Convert.ToInt32(article.Post.technology);


                    DomainTechEntity dte = new DomainTechEntity();
                    //Convert the Domain ID to Domain Name
                    var d = dte.Domain_Table.Where(x => x.did == did).FirstOrDefault();
                    post.domain = d.domain;

                    //Convert the Technology ID to Technology Name
                    var t = dte.Technology_Table.Where(x => x.tid == tid).FirstOrDefault();
                    post.technology = t.technology;

                    //Check for same title
                    int count = pe.Post_Table.Where(x => x.title == article.Post.title && x.category == true).Count();

                    if (count > 0)
                    {
                        ViewBag.ErrorMessage = "Please modify the TITLE, Article found with same TITLE";
                        return(View(article));
                    }
                    else
                    {
                        post.title    = article.Post.title;
                        post.tags     = article.Post.tags;
                        post.content_ = article.Post.content_;
                        post.date     = DateTime.Now;
                        post.category = true;
                        post.userid   = Session["userid"].ToString();

                        ViewData["Article"] = post;
                        pe.Post_Table.Add(post);
                        pe.SaveChanges();

                        return(View("ResultView"));
                    }
                }
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 2
0
        public ActionResult Create()
        {
            DomainTech.DomainTechService dt         = new DomainTech.DomainTechService();
            List <Domain_Table>          DomainList = dt.GetDomainList();

            ViewBag.DomainList = new SelectList(DomainList, "did", "domain");
            return(View());
        }
        public ActionResult EditPost(int id, Post_Table post)
        {
            StreamWriter stream = null;

            DomainTech.DomainTechService   dt         = new DomainTech.DomainTechService();
            List <DomainTech.Domain_Table> DomainList = dt.GetDomainList();

            ViewBag.DomainList = new SelectList(DomainList, "did", "domain");
            try
            {
                using (PostEntity pe = new PostEntity())
                {
                    //Get all the values of article/blog
                    var postvalues = pe.Post_Table.Where(x => x.postid == id).FirstOrDefault();

                    //set all the values
                    post.postid   = postvalues.postid;
                    post.date     = postvalues.date;
                    post.category = postvalues.category;
                    post.userid   = postvalues.userid;

                    int did = Convert.ToInt32(post.domain);
                    int tid = Convert.ToInt32(post.technology);
                    DomainTechEntity dte = new DomainTechEntity();
                    var d = dte.Domain_Table.Where(x => x.did == did).FirstOrDefault();
                    post.domain = d.domain;
                    var t = dte.Technology_Table.Where(x => x.tid == tid).FirstOrDefault();
                    post.technology     = t.technology;
                    post.userid         = Session["userid"].ToString();
                    ViewData["Article"] = post;
                    pe.Post_Table.AddOrUpdate(post);
                    pe.SaveChanges();
                }
                return(View("../Post/ResultView"));
            }
            catch (Exception e)
            {
                stream = new StreamWriter(@"D:/EditException.txt");
                stream.WriteLine(e);
                stream.Close();
                return(View());
            }
        }
Esempio n. 4
0
        public ActionResult BrowseBlog(Post_Table post)
        {
            using (PostEntity pe = new PostEntity())
            {
                DomainTech.DomainTechService dt         = new DomainTech.DomainTechService();
                List <Domain_Table>          DomainList = dt.GetDomainList();
                ViewBag.DomainList = new SelectList(DomainList, "did", "domain");

                pe.Configuration.ProxyCreationEnabled = false;

                List <Technology_Table> TechnologyList = dt.GetTechforDomain(post.domain);
                ViewBag.TechnologyList = new SelectList(TechnologyList, "tid", "technology");

                int did = Convert.ToInt32(post.domain);
                int tid = Convert.ToInt32(post.technology);

                DomainTechEntity dte = new DomainTechEntity();
                var d = dte.Domain_Table.Where(x => x.did == did).FirstOrDefault();
                post.domain = d.domain;
                var t = dte.Technology_Table.Where(x => x.tid == tid).FirstOrDefault();
                post.technology = t.technology;


                List <Post_Table> browseblog = pe.Post_Table.Where(x => x.domain == post.domain && x.technology == post.technology && x.category == false).ToList();
                if (browseblog.Count > 0)
                {
                    ViewData["browseblog"] = browseblog;
                }
                else
                {
                    ViewData["browseblog"] = null;
                    ViewBag.Message        = "No blog found";
                }
            }

            return(View());
        }
Esempio n. 5
0
        public ActionResult Create(Post_Table post, Blog blog, Comment comment)
        {
            StreamWriter stream = null;

            try
            {
                using (PostEntity pe = new PostEntity())
                {
                    DomainTech.DomainTechService dt         = new DomainTech.DomainTechService();
                    List <Domain_Table>          DomainList = dt.GetDomainList();
                    ViewBag.DomainList = new SelectList(DomainList, "did", "domain");

                    pe.Configuration.ProxyCreationEnabled = false;

                    List <Technology_Table> TechnologyList = dt.GetTechforDomain(post.domain);
                    ViewBag.TechnologyList = new SelectList(TechnologyList, "tid", "technology");

                    //Get the Domain ID
                    int did = Convert.ToInt32(blog.Post.domain);
                    //Get the Technology ID
                    int tid = Convert.ToInt32(blog.Post.technology);


                    DomainTechEntity dte = new DomainTechEntity();
                    //Convert the Domain ID to Domain Name
                    var d = dte.Domain_Table.Where(x => x.did == did).FirstOrDefault();
                    post.domain = d.domain;

                    //Convert the Technology ID to Technology Name
                    var t = dte.Technology_Table.Where(x => x.tid == tid).FirstOrDefault();
                    post.technology = t.technology;

                    //Check for same title
                    int count = pe.Post_Table.Where(x => x.title == blog.Post.title && x.category == false).Count();

                    if (count > 0)
                    {
                        ViewBag.ErrorMessage = "Please modify the TITLE, Blog found with same TITLE";
                        return(View(blog));
                    }
                    else
                    {
                        // Add the date, category and
                        post.title       = blog.Post.title;
                        post.tags        = blog.Post.tags;
                        post.content_    = blog.Post.content_;
                        post.date        = DateTime.Now;
                        post.category    = false;
                        post.userid      = Session["userid"].ToString();
                        ViewData["Blog"] = post;
                        pe.Post_Table.Add(post);


                        pe.SaveChanges();
                        return(View("../Post/ResultView"));
                    }
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                stream = new StreamWriter(@"D:\BlogException.txt");
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        stream.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
                stream.Close();
                return(View());
            }
        }