Beispiel #1
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));
        }
Beispiel #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());
        }
Beispiel #3
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());
            }
        }
Beispiel #4
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());
            }
        }
Beispiel #5
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"));
        }
Beispiel #6
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());
            }
        }
Beispiel #7
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());
        }
Beispiel #8
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()));
            }
        }
Beispiel #9
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));
            }
        }
        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());
            }
        }
Beispiel #11
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));
        }