Esempio n. 1
0
        public ActionResult CreateQuestion(Question data, string tags)
        {
            if (Request.IsAuthenticated && (!tags.Equals("")))
            {
                //Create a list for the tags
                var tagList = new List<String>();
                var manager = new QuestionManager();

                //Split the given string by commas
                var boxtags = tags.Split(',');

                //If the last character is a comma, create a list without that
                if (boxtags[boxtags.Length - 1].Equals(" "))
                    tagList = boxtags.Take(boxtags.Length - 1).ToList();
                else
                    tagList = boxtags.ToList();

                //Remove all leading and trailing whitespaces from the tage
                var tagsWithoutWhitespaces = new List<String>();
                foreach (var item in tagList)
                {
                    tagsWithoutWhitespaces.Add(item.Trim());
                }

                //If the created question is valid, add a new question to the database
                if (ModelState.IsValid)
                {
                    manager.AddQuestion(data, WebSecurity.GetUserId(User.Identity.Name), tagsWithoutWhitespaces);
                }
            }

            return RedirectToAction("Index");
        }
Esempio n. 2
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);
     }
 }
Esempio n. 3
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);

            }
        }
Esempio n. 4
0
        public ActionResult EditQuestion(Question data, string QuesID)
        {
            data.Id = Int32.Parse(QuesID);
            var manager = new QuestionManager();
            data.UserId = WebSecurity.CurrentUserId;
            if (ModelState.IsValid)
            {
                manager.EditQuestion(data);
            }

            return RedirectToAction("Index");
        }