Exemple #1
0
        public string uploadPost(Post_Table post_table)
        {
            string query_status = "failed";

            using (MlaDatabaseEntities context = new MlaDatabaseEntities())
            {
                try
                {
                    context.Post_Table.Add(post_table);
                    if (context.SaveChanges() > 0)
                    {
                        query_status = "ok";
                        return(query_status);
                    }
                    else
                    {
                        return(query_status);
                    }
                }
                catch (Exception e)
                {
                    query_status = "failed" + e.ToString();
                    return(query_status);
                }
            }
        }
Exemple #2
0
        public ActionResult Details(int id, Article article, Rate rate)
        {
            using (DbAccessEntity db = new DbAccessEntity())
            {
                Post_Table post = db.Post_Table.Where(x => x.postid == id).FirstOrDefault();
                if (post.comments != null)
                {
                    article.comments = JsonConvert.DeserializeObject <List <Comment> >(post.comments);
                }

                Rate.rateList.Clear();

                if (post.rating != null)
                {
                    Rate.rateList = JsonConvert.DeserializeObject <List <Rate> >(post.rating);
                    rate.rating   = Rate.getUserRating(Rate.rateList, Session["userid"].ToString());
                    if (rate.rating != 0)
                    {
                        rate.userId = Session["userid"].ToString();
                    }
                }

                ViewData["Article"]       = post;
                ViewData["Comments"]      = article;
                ViewData["Rate"]          = rate;
                ViewData["AverageRating"] = Rate.calculateAverageRating(Rate.rateList);
                return(View("../Post/ResultView"));
            }
        }
Exemple #3
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());
            }
        }
Exemple #4
0
 /// <summary>
 /// 添加职位
 /// </summary>
 /// <param name="obj">带入参数</param>
 /// <returns></returns>
 public int Insert_PostTableData(Post_Table obj)
 {
     return(DBHerlper.ExecuteNonQuery(GetSqlString("Insert"),
                                      CommandType.StoredProcedure,
                                      new SqlParameter[] {
         new SqlParameter("@Post_Name", obj.Post_Name)
     }));
 }
 public ActionResult Details(int id)
 {
     using (PostEntity pe = new PostEntity())
     {
         Post_Table post = pe.Post_Table.Where(x => x.postid == id).FirstOrDefault();
         ViewData["Article"] = post;
         return(View("../Post/ResultView"));
     }
 }
Exemple #6
0
        public ActionResult EditPost(int id)
        {
            using (DbAccessEntity db = new DbAccessEntity())
            {
                List <Domain_Table> DomainList = db.Domain_Table.ToList();
                ViewBag.DomainList = new SelectList(DomainList, "did", "domain");

                List <Technology_Table> TechnologyList = db.Technology_Table.ToList();
                ViewBag.TechnologyList = new SelectList(TechnologyList, "tid", "technology");

                Post_Table post = db.Post_Table.Where(x => x.postid == id).FirstOrDefault();
                return(View(post));
            }
        }
Exemple #7
0
        public ActionResult EditPost(int id, Post_Table post)
        {
            StreamWriter stream = null;

            try
            {
                using (DbAccessEntity db = new DbAccessEntity())
                {
                    List <Domain_Table> DomainList = db.Domain_Table.ToList();
                    ViewBag.DomainList = new SelectList(DomainList, "did", "domain");

                    db.Configuration.ProxyCreationEnabled = false;

                    List <Technology_Table> TechnologyList = db.Technology_Table.ToList();
                    ViewBag.TechnologyList = new SelectList(TechnologyList, "tid", "technology");

                    //Get all the values of article/blog
                    var postvalues = db.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);
                    var d   = db.Domain_Table.Where(x => x.did == did).FirstOrDefault();
                    post.domain = d.domain;
                    var t = db.Technology_Table.Where(x => x.tid == tid).FirstOrDefault();
                    post.technology     = t.technology;
                    post.userid         = Session["userid"].ToString();
                    ViewData["Article"] = post;
                    db.Post_Table.AddOrUpdate(post);
                    db.SaveChanges();
                }
                return(View("../Post/ResultView"));
            }
            catch (Exception e)
            {
                stream = new StreamWriter(@"D:/EditException.txt");
                stream.WriteLine(e);
                stream.Close();
                return(View());
            }
        }
        public ActionResult DeletePost(int id, FormCollection form)
        {
            try
            {
                using (PostEntity pe = new PostEntity())
                {
                    Post_Table post = pe.Post_Table.Where(x => x.postid == id).FirstOrDefault();
                    pe.Post_Table.Remove(post);
                    pe.SaveChanges();
                }

                return(RedirectToAction("ManageUser"));
            }
            catch
            {
                return(View());
            }
        }
Exemple #9
0
        /// <summary>
        /// 获取全部的职位
        /// </summary>
        /// <returns></returns>
        public List <Post_Table> GetPostTableAll()
        {
            List <Post_Table> list = new List <Post_Table>();
            SqlDataReader     dr   = DBHerlper.ExecuteReader(GetSqlString("Select"),
                                                             CommandType.StoredProcedure);

            while (dr.Read())
            {
                Post_Table obj = new Post_Table()
                {
                    Post_id   = Convert.ToInt32(dr["Post_id"]),
                    Post_Name = dr["Post_Name"].ToString()
                };
                list.Add(obj);
            }
            dr.Close();
            return(list);
        }
        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());
            }
        }
Exemple #11
0
        /// <summary>
        /// 根据ID查询职位信息
        /// </summary>
        /// <param name="con"></param>
        /// <returns></returns>
        public Post_Table GetPostTableByConn(string con)
        {
            Post_Table    obj = null;
            SqlDataReader dr  = DBHerlper.ExecuteReader(
                "Select * from Post_Table where Post_id=@Post_id",
                CommandType.Text, new SqlParameter[] {
                new SqlParameter("@Post_id", con)
            });

            if (dr.Read())
            {
                obj = new Post_Table()
                {
                    Post_id   = Convert.ToInt32(dr["Post_id"]),
                    Post_Name = dr["Post_Name"].ToString()
                };
            }
            dr.Close();
            return(obj);
        }
        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());
        }
Exemple #13
0
        public ActionResult BrowseArticle(Post_Table post)
        {
            using (DbAccessEntity db = new DbAccessEntity())
            {
                List <Domain_Table> DomainList = db.Domain_Table.ToList();
                ViewBag.DomainList = new SelectList(DomainList, "did", "domain");

                db.Configuration.ProxyCreationEnabled = false;

                List <Technology_Table> TechnologyList = db.Technology_Table.ToList();
                ViewBag.TechnologyList = new SelectList(TechnologyList, "tid", "technology");

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


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

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


            return(View());
        }
Exemple #14
0
 /// <summary>
 /// 更改订单信息
 /// </summary>
 /// <param name="obj">带入参数</param>
 /// <returns></returns>
 public int Update_PostTableData(Post_Table obj)
 {
     return(relevanceClass.Update_PostTableData(obj));
 }
Exemple #15
0
 /// <summary>
 /// 添加订单信息
 /// </summary>
 /// <param name="obj">带入参数</param>
 /// <returns></returns>
 public int Insert_PostTableData(Post_Table obj)
 {
     return(relevanceClass.Insert_PostTableData(obj));
 }
Exemple #16
0
        public ActionResult GenerateUserReport(string answer, string inp, Subscriber_Table si, Post_Table ai, TestUser u)
        {
            if (answer != null)
            {
                DbAccessEntity te = new DbAccessEntity();

                var testsub = (from p in te.Subscriber_Table
                               join t in te.Test_Table
                               on p.userid equals t.UserId
                               where p.userid == inp
                               select new
                {
                    ID = p.userid,
                    Domain = t.DomainID,
                    Score = t.Score,
                    Technology = t.TechnologyID,
                    TesTID = t.TestId,
                }).ToList();
                int i = 0;
                foreach (var p in testsub)
                {
                    u.Name      = p.ID;
                    u.Domain[i] = p.Domain;
                    u.UserId[i] = p.ID;
                    u.Score[i]  = p.Score;
                    u.TestId[i] = p.TesTID;

                    if (u.Score[i] <= (0.4) * 10)
                    {
                        u.fail = u.fail + 1;
                    }
                    else
                    {
                        u.pass = u.pass + 1;
                    }
                    i++;
                }
                u.counttest = i;


                var artsubq = (from p in te.Subscriber_Table
                               join e in te.Post_Table
                               on p.userid equals e.userid
                               where p.userid == inp
                               select new
                {
                    ID = p.userid,
                    Name = p.name,
                    Title = e.title,
                    Rating = e.rating,
                    Technology = e.technology
                }).ToList();
                i = 0;
                double sum = 0;
                foreach (var p in artsubq)
                {
                    u.Title[i]          = p.Title;
                    u.Technologylist[i] = p.Technology;

                    i++;
                }
                u.countarticle = i;

                if (u.countarticle > 0)
                {
                    u.averagerating = (sum / u.countarticle);
                }
                else
                {
                    u.averagerating = 0;
                }
                return(View(u));
            }
            return(View());
        }
        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());
            }
        }
Exemple #18
0
        public ActionResult PostComment(Post_Table postTable, Comment comment, Article article, Rate rate, string postId, string commentId, string commentContent)
        {
            try
            {
                using (DbAccessEntity pe = new DbAccessEntity())
                {
                    var postIdInt = Convert.ToInt32(postId);

                    var post = pe.Post_Table.Where(x => x.postid == postIdInt).FirstOrDefault();

                    if (post.comments != null)
                    {
                        article.comments = JsonConvert.DeserializeObject <List <Comment> >(post.comments);
                    }

                    if (post.rating != null)
                    {
                        Rate.rateList.Clear();
                        Rate.rateList = JsonConvert.DeserializeObject <List <Rate> >(post.rating);
                        rate.rating   = Rate.getUserRating(Rate.rateList, Session["userid"].ToString());
                        rate.userId   = Session["userid"].ToString();
                    }

                    ViewData["Rate"]          = rate;
                    ViewData["AverageRating"] = Rate.calculateAverageRating(Rate.rateList);
                    ViewData["Article"]       = post;
                    ViewData["Comments"]      = article;

                    comment.userid = Session["userid"].ToString();
                    comment.date   = DateTime.Now;

                    if (commentContent == null)
                    {
                        if (comment.content_ != null)
                        {
                            if (article.comments.Count() < 10)
                            {
                                comment.postid = "0" + (article.comments.Count() + 1);
                            }
                            else
                            {
                                comment.postid = (article.comments.Count() + 1).ToString();
                            }
                            article.comments.Add(comment);
                        }

                        else
                        {
                            ViewData["EmptyComment"] = "Put something atleast!";
                            return(View("ResultView"));
                        }
                    }

                    else if (commentContent != null)
                    {
                        var foundParentComment = false;
                        while (!foundParentComment)
                        {
                            foundParentComment = AddCommentToParentComment(article.comments, commentId, commentContent);
                        }
                    }

                    var jsonCommentList = JsonConvert.SerializeObject(article.comments);

                    post.comments = jsonCommentList;

                    pe.Post_Table.AddOrUpdate(post);
                    pe.SaveChanges();

                    return(View("ResultView"));
                }
            }

            //TODO: Print exception in log
            catch (Exception e)
            {
                return(Content(e.ToString()));
            }
        }