Пример #1
0
 /// <summary>
 /// Válasz szerkesztése
 /// </summary>
 /// <param name="data">Válasz adatai</param>
 public void EditAnswer(Answer data)
 {
     using (var db = new SoAContext())
     {
         var q = from a in db.Answers where a.Id == data.Id select a;
         var ans = q.SingleOrDefault();
         ans.Content = data.Content;
         db.SaveChanges();
         HttpContext.Current.Cache.UpdateCache("AnswersToQuestion" + data.QuestionId, data);
         HttpContext.Current.Cache.UpdateCache("AnswersToQuestion" + data.QuestionId + "User" + data.UserId, data);
     }
 }
Пример #2
0
        /// <summary>
        /// Az adott kérdésre az adott user által beírja az adott szavazatot
        /// </summary>
        /// <param name="questionid">Kérdés Id</param>
        /// <param name="userid">User Id</param>
        /// <param name="vote">Szavazat</param>
        public void Vote(int questionid, int userid, int vote)
        {
            using (var db=new SoAContext())
            {
                QuestionHasVote add = new QuestionHasVote();
                add.QuestionId=questionid;
                add.UserId=userid;
                add.Rating=vote;
                db.QuestionHasVotes.Add(add);
                db.SaveChanges();
                HttpContext.Current.Cache.UpdateCache("QuestionVote" + questionid, add);

            }
        }
Пример #3
0
        /// <summary>
        /// Válasz hozzáadása a DB-hez
        /// </summary>
        /// <param name="data">Válasz adatai</param>
        public void AddAnswer(Answer data, int questionID, int userid)
        {
            using (var db = new SoAContext())
            {
                data.Date = DateTime.Now;
                data.UserId = userid;
                data.QuestionId = questionID;
                db.Answers.Add(data);
                db.SaveChanges();

                HttpContext.Current.Cache.UpdateCache("AnsweredQuestions" + userid, data);
                HttpContext.Current.Cache.UpdateCache("AnswersToQuestion"+questionID, data);
                HttpContext.Current.Cache.UpdateCache("AnswersToQuestion" + questionID+"User"+userid, data);
            }
        }
Пример #4
0
 /// <summary>
 /// Kérdés szerkesztése
 /// </summary>
 /// <param name="data">Kérdés adatai</param>
 public void EditQuestion(Question data)
 {
     using (var db = new SoAContext())
     {
         var q = from question in db.Questions where (question.Id == data.Id) select question;
         var editableData = q.SingleOrDefault();
         editableData.Title = data.Title;
         editableData.Content = data.Content;
         db.SaveChanges();
         HttpContext.Current.Cache.UpdateCache("GetQuestion" + data.Id, data);
     }
 }
Пример #5
0
        /// <summary>
        /// Hozzáad egy kérdést az adatbázishoz
        /// </summary>
        /// <param name="data">Kérdés adatai</param>
        public void AddQuestion(Question data, int userID, List<string> tagList)
        {
            using (var db = new SoAContext())
            {
                //Beállítjuk az aktuális dátumot
                data.Date = DateTime.Now;
                data.UserId = userID;
                db.Questions.Add(data);
                db.SaveChanges();

                //Tagek kezelése
                //Megnézzük, h létezik-e az adott, tag, ha nem akkor beszúrunk
                Tag tag = null;
                foreach (var item in tagList)
                {
                    var q = (from t in db.Tags where item.Equals(t.Name) select t).ToArray();
                    //Ha nem létezik, beszúrunk
                    if (q.Length == 0)
                    {
                        tag = new Tag();
                        tag.Name = item;
                        db.Tags.Add(tag);
                        db.SaveChanges();

                        //Hozzárendeljük a tag-et a kérdéshez
                        var qt = new QuestionHasTag();
                        qt.QuestionId = data.Id;
                        qt.TagId = tag.Id;
                        db.QuestionHasTags.Add(qt);
                        db.SaveChanges();
                    }
                    //Létezik ilyen tag, hozzárendeleés
                    else
                    {
                        var query = from t in db.Tags where item.Equals(t.Name) select t;
                        tag = query.Single();
                        var qt = new QuestionHasTag();
                        qt.QuestionId = data.Id;
                        qt.TagId = tag.Id;
                        db.QuestionHasTags.Add(qt);
                        db.SaveChanges();
                    }
                    HttpContext.Current.Cache.UpdateCache("Tags", item);
                }

                db.SaveChanges();

                int pageCache = 5;

                HttpContext.Current.Cache.UpdateCache("AllQuestions", data);
                HttpContext.Current.Cache.UpdateCache("LatestQuestions", data);
                HttpContext.Current.Cache.UpdateCache("QuestionsByUser" + data.UserId, data);

                for (int i = 1; i < pageCache; i++)
                {
                    HttpContext.Current.Cache.UpdateCache("PageQuestions" + i, data);
                }

                foreach (var qht in data.QuestionHasTags)
                {
                    for (int i = 1; i < pageCache; i++)
                    {
                        HttpContext.Current.Cache.UpdateCache("QuestionsByTag" + qht.TagId + "Page" + i, data);
                    }
                }

                HttpContext.Current.Cache.UpdateCache("QuestionsByUser" + data.UserId, data);

            }
        }
Пример #6
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return RedirectToAction("Manage");
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (SoAContext db = new SoAContext())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile { UserName = model.UserName });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return RedirectToLocal(returnUrl);
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", Resources.Global.UsernameIsReserved);
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
Пример #7
0
        /// <summary>
        /// Az adott válaszra az adott user által beírja az adott szavazatot
        /// </summary>
        /// <param name="answerid">Válasz Id</param>
        /// <param name="userid">User Id</param>
        /// <param name="vote">Szavazat</param>
        public void VoteAnswer(int answerid, int userid, int vote)
        {
            using (var db = new SoAContext())
            {
                AnswerHasVote add = new AnswerHasVote();
                add.AnswerId = answerid;
                add.UserId = userid;
                add.Rating = vote;
                db.AnswerHasVotes.Add(add);
                db.SaveChanges();

                HttpContext.Current.Cache.UpdateCache("AnswerVote" + answerid, add);
            }
        }