예제 #1
0
 public ActionResult DeletePost(int id)
 {
     using (DbAccessEntity db = new DbAccessEntity())
     {
         return(View(db.Post_Table.Where(x => x.postid == id).FirstOrDefault()));
     }
 }
예제 #2
0
        public ActionResult ForgotPassword(string EmailID)
        {
            //Verify the emailid
            //Generate Reset Password Link
            //Send Email
            string message = "";
            bool   status  = false;

            using (DbAccessEntity db = new DbAccessEntity())
            {
                var account = db.Subscriber_Table.Where(x => x.email == EmailID).FirstOrDefault();
                if (account != null)
                {
                    //Send email for reset password
                    string resetCode = Guid.NewGuid().ToString();
                    SendVerificationLinkEmail(account.email, resetCode, "ResetPassword");
                    account.ResetPasswordCode = resetCode;

                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.SaveChanges();
                    message = "Reset Password Link has been sent to your Email ID";
                }
                else
                {
                    message = "Account Not Found";
                }
            }
            ViewBag.Message = message;
            return(View());
        }
예제 #3
0
        public ActionResult ResetPassword(ResetPasswordModel model)
        {
            var message = "";

            if (ModelState.IsValid)
            {
                using (DbAccessEntity db = new DbAccessEntity())
                {
                    var user = db.Subscriber_Table.Where(x => x.ResetPasswordCode == model.ResetCode).FirstOrDefault();
                    if (user != null)
                    {
                        user.password          = Crypto.Hash(model.NewPassword);
                        user.ResetPasswordCode = "";
                        db.Configuration.ValidateOnSaveEnabled = false;
                        db.SaveChanges();
                        message = "New password updated successfully";
                    }
                }
            }
            else
            {
                message = "Something invalid";
            }

            ViewBag.Message = message;
            return(View(model));
        }
예제 #4
0
        public ActionResult ManageUser()
        {
            using (DbAccessEntity db = new DbAccessEntity())
            {
                string            userid  = Session["userid"].ToString();
                List <Post_Table> article = db.Post_Table.Where(x => x.userid.Equals(userid) && x.category == true).ToList();
                List <Post_Table> blog    = db.Post_Table.Where(x => x.userid.Equals(userid) && x.category == false).ToList();

                if (article.Count > 0)
                {
                    ViewData["Articles"] = article;
                }
                else
                {
                    ViewData["Articles"]   = null;
                    ViewBag.ArticleMessage = "No articles published ";
                }

                if (blog.Count > 0)
                {
                    ViewData["Blogs"] = blog;
                }
                else
                {
                    ViewData["Blogs"]   = null;
                    ViewBag.BlogMessage = "No blogs posted ";
                }



                return(View());
            }
        }
예제 #5
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"));
            }
        }
예제 #6
0
        public ActionResult Create()
        {
            DbAccessEntity      db         = new DbAccessEntity();
            List <Domain_Table> DomainList = db.Domain_Table.ToList();

            ViewBag.DomainList = new SelectList(DomainList, "did", "domain");
            return(View());
        }
예제 #7
0
 public bool IsEmailExist(string emailid)
 {
     using (DbAccessEntity db = new DbAccessEntity())
     {
         var v = db.Subscriber_Table.Where(a => a.email == emailid).FirstOrDefault();
         return(v != null);
     }
 }
예제 #8
0
        public ActionResult Create(Post_Table post, Article article)
        {
            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 the Domain ID
                    int did = Convert.ToInt32(article.Post.domain);
                    //Get the Technology ID
                    int tid = Convert.ToInt32(article.Post.technology);


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

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

                    //Check for same title
                    int count = db.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;
                        db.Post_Table.Add(post);
                        db.SaveChanges();

                        return(View("ResultView"));
                    }
                }
            }
            catch
            {
                return(View());
            }
        }
예제 #9
0
        public JsonResult GetTechList(int did)
        {
            using (DbAccessEntity db = new DbAccessEntity())
            {
                db.Configuration.ProxyCreationEnabled = false;

                List <Technology_Table> TechList = db.Technology_Table.Where(x => x.did == did).ToList();
                return(Json(TechList, JsonRequestBehavior.AllowGet));
            }
        }
예제 #10
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));
            }
        }
예제 #11
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());
            }
        }
예제 #12
0
        public ActionResult PostRating(Article article, Rate rate, string rating, string postId)
        {
            using (DbAccessEntity postEntity = new DbAccessEntity())
            {
                var postIdInt = Convert.ToInt32(postId);

                var post = postEntity.Post_Table.Where(x => x.postid == postIdInt).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());
                    rate.userId   = Session["userid"].ToString();
                }

                if (rate.rating == 0)
                {
                    rate        = new Rate();
                    rate.rating = Convert.ToInt32(rating);
                    rate.userId = Session["userid"].ToString();

                    Rate.rateList.Add(rate);

                    var jsonRatingList = JsonConvert.SerializeObject(Rate.rateList);

                    post.rating = jsonRatingList;

                    postEntity.Post_Table.AddOrUpdate(post);
                    postEntity.SaveChanges();
                }

                ViewData["Article"]       = post;
                ViewData["Comments"]      = article;
                ViewData["Rate"]          = rate;
                ViewData["AverageRating"] = Rate.calculateAverageRating(Rate.rateList);
            }
            return(View("ResultView"));
        }
예제 #13
0
        public ActionResult GenerateTestReport(TestUser u, string answer, string inp, string answercat, string Search)
        {
            int            i         = 0;
            DbAccessEntity tec       = new DbAccessEntity();
            var            domainvar = (from p in tec.Domain_Table
                                        select p.domain);
            var count = (from p in tec.Domain_Table
                         select p.domain).Count();

            u.Domaincount = count;
            foreach (var p in domainvar)
            {
                u.Domaindroplist[i] = p;
                i++;
            }
            ViewBag.domainlistname = u.Domainlist;
            return(View(u));
        }
예제 #14
0
        //To search for the post/author/tags based on input
        public ActionResult SearchPost(string term)
        {
            using (DbAccessEntity db = new DbAccessEntity())
            {
                List <Post_Table> searchlist = db.Post_Table.Where(x => x.tags.Contains(term) || x.title.Contains(term) || x.userid.Contains(term)).ToList();

                if (searchlist.Count > 0)
                {
                    ViewData["searchlist"] = searchlist;
                }
                else
                {
                    ViewData["searchlist"] = null;
                    ViewBag.SearchMessage  = "No results found";
                }
            }
            return(View("ResultView"));
        }
예제 #15
0
        public ActionResult DeletePost(int id, FormCollection form)
        {
            try
            {
                using (DbAccessEntity db = new DbAccessEntity())
                {
                    Post_Table post = db.Post_Table.Where(x => x.postid == id).FirstOrDefault();
                    db.Post_Table.Remove(post);
                    db.SaveChanges();
                }

                return(RedirectToAction("ManageUser"));
            }
            catch
            {
                return(View());
            }
        }
예제 #16
0
        public ActionResult Login(SubscriberLogin login, string ReturnUrl)
        {
            string message = "";

            using (DbAccessEntity db = new DbAccessEntity())
            {
                var v = db.Subscriber_Table.Where(a => a.email == login.email).FirstOrDefault();
                if (v != null)
                {
                    if (string.Compare(Crypto.Hash(login.password), v.password) == 0)
                    {
                        int    timeout   = login.RememberMe ? 525600 : 20; //525600 minutes equals 1 year
                        var    ticket    = new FormsAuthenticationTicket(v.name, login.RememberMe, timeout);
                        string encrypted = FormsAuthentication.Encrypt(ticket);
                        var    cookie    = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
                        cookie.Expires  = DateTime.Now.AddMinutes(timeout);
                        cookie.HttpOnly = true;
                        Response.Cookies.Add(cookie);
                        Session["userid"] = v.userid;
                        Session.Timeout   = timeout;

                        if (Url.IsLocalUrl(ReturnUrl))
                        {
                            return(Redirect(ReturnUrl));
                        }
                        else
                        {
                            return(RedirectToAction("ManageUser"));
                        }
                    }
                    else
                    {
                        message = "Invalid credentials provided";
                    }
                }
                else
                {
                    message = "Invalid credentials provided";
                }
            }

            ViewBag.Message = message;
            return(View(login));
        }
예제 #17
0
 public ActionResult ResetPassword(string id)
 {
     //Verify the reset password link
     //Find accound associated with this link
     //redirect to reset password page
     using (DbAccessEntity db = new DbAccessEntity())
     {
         var user = db.Subscriber_Table.Where(x => x.ResetPasswordCode == id).FirstOrDefault();
         if (user != null)
         {
             ResetPasswordModel model = new ResetPasswordModel();
             model.ResetCode = id;
             return(View(model));
         }
         else
         {
             return(HttpNotFound());
         }
     }
 }
예제 #18
0
        // GET: Admin
        public ActionResult Index(string UserID, string Password, string Login)
        {
            if (Login != null)
            {
                using (DbAccessEntity db = new DbAccessEntity())
                {
                    var user = db.Admin_Table.Where(x => x.Username == UserID && x.Password == Password).FirstOrDefault();

                    if (user != null)
                    {
                        return(View("GenerateUserReport"));
                    }
                    else
                    {
                        return(View("Index", null, model: "Wrong Credentials"));
                    }
                }
            }
            else
            {
                return(View());
            }
        }
예제 #19
0
        public ActionResult VerifyAccount(string id)
        {
            bool Status = false;

            using (DbAccessEntity db = new DbAccessEntity())
            {
                db.Configuration.ValidateOnSaveEnabled = false; //This line is added to avoid
                                                                //confirm password does not match issue
                var v = db.Subscriber_Table.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault();

                if (v != null)
                {
                    v.IsEmailVerified = true;
                    db.SaveChanges();
                    Status = true;
                }
                else
                {
                    ViewBag.Message = "Invalid Request";
                }
            }
            ViewBag.Status = Status;
            return(View());
        }
예제 #20
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());
        }
예제 #21
0
        public ActionResult Create(Post_Table post, Blog blog, Comment comment)
        {
            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 the Domain ID
                    int did = Convert.ToInt32(blog.Post.domain);
                    //Get the Technology ID
                    int tid = Convert.ToInt32(blog.Post.technology);



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

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

                    //Check for same title
                    int count = db.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;
                        db.Post_Table.Add(post);


                        db.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());
            }
        }
예제 #22
0
        public ActionResult Registration([Bind(Exclude = "IsEmailVerified,ActivationCode")] Subscriber_Table subscriber)
        {
            bool         Status  = false;
            string       message = "";
            StreamWriter stream  = null;

            //Model Validation
            if (ModelState.IsValid)
            {
                #region Email is already existing
                var isExist = IsEmailExist(subscriber.email);
                if (isExist)
                {
                    ModelState.AddModelError("EmailExist", "Email already exist");
                    return(View(subscriber));
                }
                #endregion

                #region Activation Code Generation
                subscriber.ActivationCode = Guid.NewGuid();
                #endregion

                #region Password Hashing
                subscriber.password        = Crypto.Hash(subscriber.password);
                subscriber.confirmpassword = Crypto.Hash(subscriber.confirmpassword);
                #endregion
                subscriber.IsEmailVerified = false;

                #region Save data to database
                using (DbAccessEntity db = new DbAccessEntity())
                {
                    db.Subscriber_Table.Add(subscriber);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (DbEntityValidationException dbEx)
                    {
                        stream = new StreamWriter(@"D:\Exception.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();
                    }
                    finally
                    {
                        //stream.Close();
                    }


                    //Send Email to user
                    SendVerificationLinkEmail(subscriber.email, subscriber.ActivationCode.ToString());
                    message = "Registration successfully done. Account activation link has been sent to your emailid " + subscriber.email;

                    Status = true;
                }
                #endregion
            }
            else
            {
                message = "Invalid request";
            }

            ViewBag.Message = message;
            ViewBag.Status  = Status;


            return(View(subscriber));
        }
예제 #23
0
        public ActionResult TakeTest(Test_Table test, string searchtest, string submittechnology, string technology, string submitdomain, QuestionBank qu, string domain, string checkscore, string _1, string _2, string _3, string _4, string _5, string _6, string _7, string _8, string _9, string _10)
        {
            /*provides dropdown to select domain*/

            /*Lists the technologies after selecting the respective domain*/
            if (domain != null && submittechnology == null)
            {
                DbAccessEntity tec = new DbAccessEntity();



                //fetch technology id
                var techlist = (from p in tec.Technology_Table
                                join q in tec.Domain_Table
                                on p.did equals q.did
                                where q.domain == domain
                                select new
                {
                    Technology = p.technology,
                }).ToList();

                Session["Domain"] = domain;
                var domainlist = (from p in tec.Domain_Table
                                  where p.domain != domain
                                  select new
                {
                    domain = p.domain                           //gets the domain list
                }).ToList();

                List <QuestionBank> li = new List <QuestionBank>();

                foreach (var p in techlist)
                {
                    QuestionBank q = new QuestionBank();
                    q.techlist = p.Technology;
                    li.Add(q);
                }
                qu.domainlist = domain;


                li.Add(qu);
                foreach (var p in domainlist)
                {
                    QuestionBank q = new QuestionBank();
                    q.domainlist = p.domain;
                    li.Add(q);
                }


                return(View(li));                                   //returns the list of domain and technology
            }
            /*submitting the technology and domain and starting the test*/
            else if (submittechnology != null)
            {
                DbAccessEntity db = new DbAccessEntity();

                //fetch technologyID
                var techidquery = (from p in db.Technology_Table
                                   where p.technology == technology
                                   select new
                {
                    Technology = p.tid
                });


                foreach (var p in techidquery)
                {
                    qu.idtech = p.Technology;
                }


                Session["TechnologyID"] = qu.idtech;


                //fetch the questions and options based on TechnologyID
                var query = (from p in db.Question_Bank_Table
                             where p.TechnologyId == qu.idtech
                             select new
                {
                    Question = p.Question,
                    QuestionID = p.QuestionID,
                    Options = p.Options,
                    CorrectAnswer = p.CorrectAnswer
                });
                List <QuestionBank> li = new List <QuestionBank>();
                int no = 1;
                foreach (var p in query)
                {
                    QuestionBank qi = new QuestionBank();
                    qi.QuestionID    = p.QuestionID;
                    qi.Question      = p.Question;
                    qi.qno           = no;
                    qi.CorrectAnswer = p.CorrectAnswer;
                    string[] tempsplit = p.Options.Split(',');
                    qi.Options = tempsplit;
                    li.Add(qi);
                    no++;
                }
                Session["listOfObjects"] = li;
                return(View("TestPage", li));
            }


            /*Checking the score after end of test*/
            else if (checkscore != null)
            {
                qu.idtech = Int32.Parse(Session["TechnologyID"].ToString());
                DbAccessEntity db = new DbAccessEntity();

                //Fetch Domain ID
                var iddomain = (from p in db.Technology_Table
                                where p.tid == qu.idtech
                                select new
                {
                    DomainID = p.did
                });

                foreach (var p in iddomain)
                {
                    qu.count = p.DomainID;
                }


                //Based on the technology ID retrieve the correct answers
                var query = (from p in db.Question_Bank_Table
                             where p.TechnologyId == qu.idtech
                             select new
                {
                    Question = p.Question,
                    QuestionID = p.QuestionID,
                    Options = p.Options,
                    Answer = p.CorrectAnswer
                });

                List <string> correctanswer = new List <string>();


                //Append the selected options and enter into test_table
                string selectedoptions = "";

                foreach (var p in query)
                {
                    qu.qid = qu.qid + p.QuestionID + ",";
                    correctanswer.Add(p.Answer);
                }
                selectedoptions            = _1 + "," + _2 + "," + _3 + "," + _4 + "," + _5 + "," + _6 + "," + _7 + "," + _8 + "," + _9 + "," + _10;
                Session["selectedoptions"] = selectedoptions;



                /*evaluate the score by checking each of radio button with the correct answer*/
                if (_1 == correctanswer[0])
                {
                    qu.score += 1;
                }
                if (_2 == correctanswer[1])
                {
                    qu.score += 1;
                }
                if (_3 == correctanswer[2])
                {
                    qu.score += 1;
                }
                if (_4 == correctanswer[3])
                {
                    qu.score += 1;
                }
                if (_5 == correctanswer[4])
                {
                    qu.score += 1;
                }
                if (_6 == correctanswer[5])
                {
                    qu.score += 1;
                }
                if (_7 == correctanswer[6])
                {
                    qu.score += 1;
                }
                if (_8 == correctanswer[7])
                {
                    qu.score += 1;
                }
                if (_9 == correctanswer[8])
                {
                    qu.score += 1;
                }
                if (_10 == correctanswer[9])
                {
                    qu.score += 1;
                }

                string userid = Session["userid"].ToString();
                test.UserId = userid;

                test.TechnologyID    = (qu.idtech);
                test.DomainID        = (qu.count);
                test.SelectedOptions = selectedoptions;
                test.Score           = qu.score;
                db.Test_Table.Add(test);

                db.SaveChanges();

                //saving the results of the test in the database
                return(View("TestResult", qu));
            }
            else
            {
                DbAccessEntity tec        = new DbAccessEntity();
                int            i          = 0;
                var            domainlist = (from p in tec.Domain_Table

                                             select new
                {
                    domain = p.domain                       //select domain from domain table
                }).ToList();


                List <QuestionBank> li = new List <QuestionBank>();
                foreach (var p in domainlist)
                {
                    QuestionBank q = new QuestionBank();
                    if (i == 0)
                    {
                        q.domainlist           = p.domain;
                        Session["domaintrack"] = p.domain;
                        li.Add(q);
                    }
                    else
                    {
                        q.domainlist = p.domain;
                        li.Add(q);
                    }
                    i++;
                }
                string firstdomain = Session["domaintrack"].ToString();
                var    techlist    = (from p in tec.Technology_Table
                                      join q in tec.Domain_Table
                                      on p.did equals q.did
                                      where q.domain == firstdomain
                                      select new
                {
                    Technology = p.technology,
                }).ToList();
                foreach (var q in techlist)
                {
                    QuestionBank que = new QuestionBank();
                    que.techlist = q.Technology;
                    li.Add(que);
                }


                return(View(li));
            }
        }
예제 #24
0
        public ActionResult DomainSelect(string domlist, TestUser u, String show, string showtech, string technolist)
        {
            if (show != null)
            {
                DbAccessEntity tec        = new DbAccessEntity();
                var            domainlist = (from p in tec.Domain_Table
                                             join q in tec.Test_Table
                                             on p.did equals q.DomainID
                                             where p.domain == domlist
                                             select new
                {
                    domain = p.domain,
                    UserID = q.UserId,
                    TestID = q.TestId,
                    Score = q.Score
                }).ToList();
                Session["domainlist"] = domlist;
                u.domainsession       = Session["domainlist"].ToString();
                List <QuestionBank> li = new List <QuestionBank>();
                int i = 0;
                foreach (var p in domainlist)
                {
                    u.Domainlist[i] = p.domain;
                    u.UserId[i]     = p.UserID;
                    u.TestId[i]     = p.TestID;
                    u.Score[i]      = p.Score;
                    i++;
                }
                u.count = i;
                var techlist = (from p in tec.Domain_Table
                                join q in tec.Technology_Table
                                on p.did equals q.did
                                where p.domain == domlist
                                select new
                {
                    Technology = q.technology
                }).ToList();
                i = 0;
                foreach (var p in techlist)
                {
                    u.Technologydroplist[i] = p.Technology;
                    i++;
                }
                u.techcount = i;


                i = 0;

                var domainvar = (from p in tec.Domain_Table
                                 select p.domain);
                var count = (from p in tec.Domain_Table
                             select p.domain).Count();
                u.Domaincount = count;
                foreach (var p in domainvar)
                {
                    u.Domaindroplist[i] = p;
                    i++;
                }
                return(View("GenerateTestReport", u));
            }
            else if (showtech != null)
            {
                DbAccessEntity tec = new DbAccessEntity();
                u.techsession = technolist;
                var techlist = (from p in tec.Technology_Table
                                join q in tec.Test_Table
                                on p.tid equals q.TechnologyID
                                where p.technology == technolist
                                select new
                {
                    technology = p.technology,
                    UserID = q.UserId,
                    TestID = q.TestId,
                    Score = q.Score
                }).ToList();

                List <QuestionBank> li = new List <QuestionBank>();
                int i = 0;
                foreach (var p in techlist)
                {
                    u.Technologylist[i] = p.technology;
                    u.UserId[i]         = p.UserID;
                    u.TestId[i]         = p.TestID;
                    u.Score[i]          = p.Score;
                    i++;
                }
                u.count = i;

                i = 0;

                var domainvar = (from p in tec.Domain_Table
                                 select p.domain);
                var count = (from p in tec.Domain_Table
                             select p.domain).Count();
                u.Domaincount = count;
                foreach (var p in domainvar)
                {
                    u.Domaindroplist[i] = p;
                    i++;
                }
                u.domainsession = Session["domainlist"].ToString();
                var techdropdownlist = (from p in tec.Domain_Table
                                        join q in tec.Technology_Table
                                        on p.did equals q.did
                                        where p.domain == u.domainsession
                                        select new
                {
                    Technology = q.technology
                }).ToList();
                i = 0;
                foreach (var p in techdropdownlist)
                {
                    u.Technologydroplist[i] = p.Technology;
                    i++;
                }
                u.techcount = i;

                return(View("GenerateTestReport", u));
            }
            return(View("GenerateTestReport"));
        }
예제 #25
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()));
            }
        }
예제 #26
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());
        }
예제 #27
0
        public ActionResult GenerateCategoryReport(string domlist, TestUser u, String show, string showtech, string technolist)
        {
            if (show != null)
            {
                DbAccessEntity tec        = new DbAccessEntity();
                var            domainlist = (from p in tec.Post_Table
                                             where p.domain == domlist
                                             select new
                {
                    domain = p.domain,
                    Title = p.title,

                    UserID = p.userid
                }).ToList();
                Session["domainlist"] = domlist;
                u.domainsession       = Session["domainlist"].ToString();
                List <QuestionBank> li = new List <QuestionBank>();
                int i = 0;
                foreach (var p in domainlist)
                {
                    u.Domainlist[i] = p.domain;
                    u.Title[i]      = p.Title;
                    u.UserId[i]     = p.UserID;
                    i++;
                }
                u.count = i;
                var techlist = (from p in tec.Technology_Table
                                join q in tec.Domain_Table
                                on p.did equals q.did
                                where q.domain == domlist
                                select new
                {
                    Technology = p.technology
                }).ToList();
                i = 0;
                foreach (var p in techlist)
                {
                    u.Technologydroplist[i] = p.Technology;
                    i++;
                }
                u.techcount = i;


                i = 0;

                var domainvar = (from p in tec.Domain_Table
                                 select p.domain);
                var count = (from p in tec.Domain_Table
                             select p.domain).Count();
                u.Domaincount = count;
                foreach (var p in domainvar)
                {
                    u.Domaindroplist[i] = p;
                    i++;
                }
                return(View("GenerateCategoryReport", u));
            }
            else if (showtech != null)
            {
                DbAccessEntity tec = new DbAccessEntity();
                u.techsession = technolist;
                var techlist = (from p in tec.Technology_Table
                                join q in tec.Post_Table
                                on p.technology equals q.technology
                                where p.technology == technolist
                                select new
                {
                    technology = p.technology,
                    UserID = q.userid,
                    Title = q.title,
                }).ToList();

                List <QuestionBank> li = new List <QuestionBank>();
                int i = 0;
                foreach (var p in techlist)
                {
                    u.Technologylist[i] = p.technology;
                    u.UserId[i]         = p.UserID;
                    u.Title[i]          = p.Title;

                    i++;
                }
                u.count = i;

                i = 0;

                var domainvar = (from p in tec.Domain_Table
                                 select p.domain);
                var count = (from p in tec.Domain_Table
                             select p.domain).Count();
                u.Domaincount = count;
                foreach (var p in domainvar)
                {
                    u.Domaindroplist[i] = p;
                    i++;
                }
                u.domainsession = Session["domainlist"].ToString();
                var techdropdownlist = (from p in tec.Domain_Table
                                        join q in tec.Technology_Table
                                        on p.did equals q.did
                                        where p.domain == u.domainsession
                                        select new
                {
                    Technology = q.technology
                }).ToList();
                i = 0;
                foreach (var p in techdropdownlist)
                {
                    u.Technologydroplist[i] = p.Technology;
                    i++;
                }
                u.techcount = i;

                return(View("GenerateCategoryReport", u));
            }
            else
            {
                int            i         = 0;
                DbAccessEntity tz        = new DbAccessEntity();
                var            domainvar = (from p in tz.Domain_Table
                                            select p.domain);
                var count = (from p in tz.Domain_Table
                             select p.domain).Count();
                u.Domaincount = count;
                foreach (var p in domainvar)
                {
                    u.Domaindroplist[i] = p;
                    i++;
                }
                ViewBag.domainlistname = u.Domainlist;
                return(View(u));
            }
        }