Example #1
0
        public ActionResult Create(Topic topic, HttpPostedFileBase[] TopicFile, string[] TitleFile, string KeyWords)
        {
            if (ModelState.IsValid)
            {

                topic.ID = Guid.NewGuid();
                topic.DateIn = DateTime.Now;
                var userID = new AccountController().GetonlineUser_ID();
                topic.UserID = userID;
                topic.CountVisit = 0;
                topic.LikeCount = 0;
                topic.UnlikeCount = 0;
                db.Topics.Add(topic);
                var user = db.MembershipOfSites.Where(x => x.ID == userID).FirstOrDefault();
                var grade = db.Assistances.Select(x => x.GradeForTopic).FirstOrDefault();
                user.Grade += grade;
                db.SaveChanges();
                if (!string.IsNullOrEmpty(KeyWords))
                {
                    string[] KeyWordComponnets = KeyWords.Split(',');
                    foreach (var item in KeyWordComponnets)
                    {
                        try
                        {
                            var KeyWordId = int.Parse(item);
                            db.KeywordOfPosts.Add(new KeywordOfPost() { ID = Guid.NewGuid(), keyWordID = KeyWordId, topicID = topic.ID });
                        }
                        catch
                        {
                            KeyWord K = new KeyWord() { title = item };
                            db.KeyWords.Add(K);
                            db.SaveChanges();
                            db.KeywordOfPosts.Add(new KeywordOfPost() { ID = Guid.NewGuid(), keyWordID = K.ID, topicID = topic.ID });
                        }
                    }
                    db.SaveChanges();
                }
                if (TopicFile != null && TopicFile.Length > 0 && TopicFile[0] != null)
                {
                    for (int i = 0; i < TopicFile.Length; i++)
                    {
                        string filename = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(TopicFile[i].FileName);
                        TopicFile[i].SaveAs(Server.MapPath("~/Files/TopicAttachments/" + filename));
                        db.TopicAttachments.Add(new TopicAttachment() { filename = filename, ID = Guid.NewGuid(), title = TitleFile[i], topicID = topic.ID });
                    }
                    db.SaveChanges();
                }
                new UserLogsController().Create(new Log() { ActivityType = ActivityType.Create, CaseActivity = CaseActivity.Topic, TopicID = topic.ID });
                return RedirectToAction("details", "SubCategory", new { id = topic.SubCategoryID });
            }

            ViewBag.SubCategoryID = new SelectList(db.SubCategories, "ID", "SubCategorySub", topic.SubCategoryID);
            return View(topic);
        }
Example #2
0
        public ActionResult Create(Question question, HttpPostedFileBase[] questionFile, string[] titleofFile, string KeyWords)
        {
            if (ModelState.IsValid)
            {
                question.ID = Guid.NewGuid();
                question.createDate = DateTime.Now;
                var userID = new AccountController().GetonlineUser_ID();
                question.userID = userID;
                var user = db.MembershipOfSites.Where(x => x.ID == userID).FirstOrDefault();
                var grade = db.Assistances.Select(x => x.GradeForQuestion).FirstOrDefault();
                user.Grade += grade;
                db.SaveChanges();
                if (!string.IsNullOrEmpty(KeyWords))
                {
                    string[] KeyWordComponnets = KeyWords.Split(',');
                    foreach (var item in KeyWordComponnets)
                    {
                        try
                        {
                            var KeyWordId = int.Parse(item);
                            db.KeywordOfPosts.Add(new KeywordOfPost() { ID = Guid.NewGuid(), keyWordID = KeyWordId, questionID = question.ID });
                        }
                        catch
                        {
                            KeyWord K = new KeyWord() { title = item };
                            db.KeyWords.Add(K);
                            db.SaveChanges();
                            db.KeywordOfPosts.Add(new KeywordOfPost() { ID = Guid.NewGuid(), keyWordID = K.ID, questionID = question.ID });
                        }
                    }
                    db.SaveChanges();
                }
                if (questionFile != null && questionFile.Length > 0 && questionFile[0] != null)
                {
                    for (int i = 0; i < questionFile.Length; i++)
                    {
                        string filename = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(questionFile[i].FileName);
                        questionFile[i].SaveAs(Server.MapPath("~/Files/QuestionAttachments/" + filename));
                        db.QuestionAttachments.Add(new QuestionAttachment() { ID = Guid.NewGuid(), filename = filename, questionID = question.ID, title = titleofFile[i] });
                    }

                }
                db.Questions.Add(question);
                db.SaveChanges();
                new UserLogsController().Create(new Log() { ActivityType = ActivityType.Create, CaseActivity = CaseActivity.Question, QuestionID = question.ID });
                return RedirectToAction("details", "subcategory", new { id = question.subCategoryID }); ;
            }

            ViewBag.subCategoryID = new SelectList(db.SubCategories, "ID", "SubCategorySub", question.subCategoryID);
            return View(question);
        }
Example #3
0
        public ActionResult Edit(Topic topic, HttpPostedFileBase[] TopicFile, string[] TitleFile, string KeyWords)
        {
            if (ModelState.IsValid)
            {
                db.Entry(topic).State = EntityState.Modified;
                db.SaveChanges();
                new UserLogsController().Create(new Log() { ActivityType = ActivityType.Edit, CaseActivity = CaseActivity.Topic, TopicID = topic.ID });
                if (!string.IsNullOrEmpty(KeyWords))
                {
                    string[] KeyWordComponnets = KeyWords.Split(',');
                    foreach (var item in KeyWordComponnets)
                    {
                        try
                        {
                            var KeyWordId = int.Parse(item);
                            db.KeywordOfPosts.Add(new KeywordOfPost() { ID = Guid.NewGuid(), keyWordID = KeyWordId, topicID = topic.ID });
                        }
                        catch
                        {
                            KeyWord K = new KeyWord() { title = item };
                            db.KeyWords.Add(K);
                            db.SaveChanges();
                            db.KeywordOfPosts.Add(new KeywordOfPost() { ID = Guid.NewGuid(), keyWordID = K.ID, topicID = topic.ID });
                        }
                    }
                    db.SaveChanges();
                }
                if (TopicFile != null && TopicFile.Length > 0 && TopicFile[0] != null)
                {
                    for (int i = 0; i < TopicFile.Length; i++)
                    {
                        string filename = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(TopicFile[i].FileName);
                        TopicFile[i].SaveAs(Server.MapPath("~/Files/TopicAttachments/" + filename));
                        db.TopicAttachments.Add(new TopicAttachment() { filename = filename, ID = Guid.NewGuid(), title = TitleFile[i], topicID = topic.ID });
                    }
                    db.SaveChanges();
                }
                if (Roles.IsUserInRole("Admin"))
                {
                    return RedirectToAction("Index", "Topic");
                }
                else
                    return RedirectToAction("UserTopic", "Users", new { SuccessMessage = "ویرایش انجام شد" });
            }

            return View(topic);
        }
Example #4
0
        public ActionResult Edit(Question question, HttpPostedFileBase[] questionFile, string[] titleofFile, string KeyWords)
        {
            if (ModelState.IsValid)
            {
                db.Entry(question).State = EntityState.Modified;
                db.SaveChanges();
                new UserLogsController().Create(new Log() { ActivityType = ActivityType.Edit, CaseActivity = CaseActivity.Question, QuestionID = question.ID });
                if (!string.IsNullOrEmpty(KeyWords))
                {
                    string[] KeyWordComponnets = KeyWords.Split(',');
                    foreach (var item in KeyWordComponnets)
                    {
                        try
                        {
                            var KeyWordId = int.Parse(item);
                            db.KeywordOfPosts.Add(new KeywordOfPost() { ID = Guid.NewGuid(), keyWordID = KeyWordId, questionID = question.ID });
                        }
                        catch
                        {
                            KeyWord K = new KeyWord() { title = item };
                            db.KeyWords.Add(K);
                            db.SaveChanges();
                            db.KeywordOfPosts.Add(new KeywordOfPost() { ID = Guid.NewGuid(), keyWordID = K.ID, questionID = question.ID });
                        }
                    }

                }
                if (questionFile != null && questionFile.Length > 0 && questionFile[0] != null)
                {
                    for (int i = 0; i < questionFile.Length; i++)
                    {
                        string filename = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(questionFile[i].FileName);
                        questionFile[i].SaveAs(Server.MapPath("~/Files/QuestionAttachments/" + filename));
                        db.QuestionAttachments.Add(new QuestionAttachment() { ID = Guid.NewGuid(), filename = filename, questionID = question.ID, title = titleofFile[i] });
                    }

                }
                db.SaveChanges();
                if (Roles.IsUserInRole("Admin"))
                {
                    return RedirectToAction("Index", "Topic");
                }
                else
                    return RedirectToAction("UserQuestion", "Users", new { SuccessMessage = "ویرایش انجام شد" });
            }
            ViewBag.subCategoryID = new SelectList(db.SubCategories, "ID", "SubCategorySub", question.subCategoryID);
            return View(question);
        }