コード例 #1
0
 public ActionResult Edit(int? id) {
     Tag tag = new Tag();
     if (string.IsNullOrEmpty(id.ToString()))
         return View(tag);
     using (club = new ClubEntities()) {
         tag = club.Tags.Single(t => t.Id ==id);   
     }
     return View(tag);
 }
コード例 #2
0
 public ActionResult Modify(int id, string tagName) {
     Tag tag = new Tag();
     using (club = new ClubEntities()) {
         tag = club.Tags.Single(t => t.Id == id);
         tag.TagName = tagName;
         if (club.SaveChanges() > 0)
             ViewBag.StatusStr = HtmlCommon.GetHitStr("标签更新成功!",Status.success);
         else
             ViewBag.StatusStr = HtmlCommon.GetHitStr("标签未修改!", Status.error);
         return View("~/areas/bwum/views/tag/edit.cshtml",tag);
     }
 }
コード例 #3
0
 public ActionResult Tags(int? tid,int? p) {
     tId = tid ?? 0;
     int rowsCount = 0;
     int page = p ?? 1;
     List<ViewArticle> viewArticles = new List<ViewArticle>();
     Tag tag = new Tag();
     using (club = new ClubEntities()) {
         tag = club.Tags.Where(t => t.Id == tId).FirstOrDefault();
         if (tag == null) { 
            return RedirectToAction("NotFound", new { Controller = "Error" });
         }
         ViewBag.tagName = tag.TagName;
         ViewBag.newArticles = club.Articles.OrderByDescending(a => a.VarDate).Take(7).ToList<Article>();
         ViewBag.hotQuestions = club.Questions.OrderByDescending(a => a.Views).Take(7).ToList<Question>();
         rowsCount = club.ViewArticles.Where(v => v.Tags.Contains(tag.TagName) && v.Status > 0).Count();
         viewArticles =club.ViewArticles.Where(v => v.Tags.Contains(tag.TagName)&&v.Status > 0).OrderByDescending(v=>v.VarDate).Skip((page - 1) * ClubConst.WebQuestionPageSize).Take(ClubConst.WebQuestionPageSize).ToList();
         ViewBag.PageStr = new PagingHelper(ClubConst.WebQuestionPageSize, page, rowsCount, 5).GetPageStringPro("/column/tags/"+tId+"-", false);
     }
     return View(viewArticles);
 }
コード例 #4
0
 public ActionResult Edit(string tagName) {
     Tag tag = new Tag();
     if (string.IsNullOrEmpty(tagName)){
         ViewBag.statusStr = HtmlCommon.GetHitStr("标签不能空!",Status.error);
         return View(tag);
     }
     if (CheckController.IsRepeate(CheckController.CheckType.TagName,tagName))
     {
         ViewBag.statusStr = HtmlCommon.GetHitStr("该标签已重复!", Status.error);
         return View(tag);
     }
     using (club = new ClubEntities()) {
         tag.TagName= tagName;
         club.Tags.Add(tag);
         if (club.SaveChanges() > 0)
             ViewBag.statusStr = HtmlCommon.GetHitStr("保存成功!", Status.error);
         else
             ViewBag.statusStr = HtmlCommon.GetHitStr("系统异常,请稍后重试!", Status.error);
     }
     return View(tag);
 }
コード例 #5
0
 public static string SetTags(ClubEntities club,string tags){
     StringBuilder str = new StringBuilder();
     Tag tag;
     if (tags != null) {
         string[] tagArray = tags.Split(',');
         foreach (string t in tagArray) {
             if (!string.IsNullOrEmpty(t)){
                 tag = club.Tags.Where(ta => ta.TagName == t).FirstOrDefault();
                 if (tag != null){
                     str.Append(tag.Id + ",");
                 }
                 else{
                     tag = new Tag() { TagName = t };
                     club.Tags.Add(tag);
                     club.SaveChanges();
                     str.Append(tag.Id + ",");
                 }
             }
         }
     }
     str = str.Length > 0 ? str.Remove(str.Length - 1, 1) : str;
     return str.ToString();
 }
コード例 #6
0
 public ActionResult Tags(int? tid,int? p) {
     int tId = tid ?? 0;
     List<ViewQuestion> vquestion = new List<ViewQuestion>();
     Tag tag = new Tag();
     int rowsCount = 0;
     int page = p ?? 1;
     using (club = new ClubEntities()){
          tag = club.Tags.Where(t => t.Id == tid).FirstOrDefault();
         if (tag == null) { 
            return RedirectToAction("NotFound", new { Controller = "Error" });
         }
         ViewBag.tagName = tag.TagName;
         ViewBag.newArticles = club.Articles.OrderByDescending(a => a.VarDate).Take(7).ToList<Article>();
         ViewBag.hotQuestions = club.Questions.OrderByDescending(a => a.Views).Take(7).ToList<Question>();
         rowsCount = club.ViewQuestions.OrderByDescending(q => q.VarDate).Where(t => t.Tags.Contains(tag.TagName)).Count();
         vquestion = club.ViewQuestions.OrderByDescending(q => q.VarDate).Where(t => t.Tags.Contains(tag.TagName)).Skip((page - 1) * ClubConst.WebPageSize).Take(ClubConst.WebPageSize).ToList<ViewQuestion>();
     }
     ViewBag.PageStr = GetPageStr(ClubConst.WebQuestionPageSize, page, rowsCount, ClubConst.WebQuestionPageShow, "/ask/tags/"+tId+"-", false);
     return View(vquestion);
 }
コード例 #7
0
 public ActionResult SetCheck(int? id,string title,string context,string tags) {
     vId=id??0;
     StringBuilder str = new StringBuilder();
     Tag tag = new Tag();
     using (club = new ClubEntities()) {
         article = club.Articles.Where(t => t.Id == vId).FirstOrDefault();
         if (article != null) {
             article.Tags = tags;
             article.TagIds =App_Start.CommonMethod.SetTags(club, tags);
             if (article.Status == 1)
                 article.Status = 0;
             else
                 article.Status = 1;
             if (club.SaveChanges() >= 0) {
                 hitStr = "状态修改成功!";
                 status = Status.success;
             }
             else {
                 hitStr = "系统异常,请稍后重试!";
             }
         }
         else
         {
             return RedirectToAction("notfound","error");
         }
     }
     ViewBag.StatusStr = HtmlCommon.GetHitStr(hitStr, status);
     return View("~/areas/bwum/views/contribute/show.cshtml", article);
 } 
コード例 #8
0
 private JsonResult DelTag(int id){
     Tag tag = new Tag();
     object obj;
     using (club = new ClubEntities()) {
         tag = club.Tags.Where(t => t.Id == id).FirstOrDefault();
         if (tag.Id > 0) {
             club.Tags.Remove(tag);
             club.SaveChanges();
             obj = new { status = state.ToString(), content = HtmlCommon.GetHitStr("标签删除成功!", state) };
         }
         else {
             state = Status.error;
             obj = new { status = state, content = HtmlCommon.GetHitStr("标签删除失败,请稍后重试!", state) };
         }
     }
     return Json(obj,JsonRequestBehavior.AllowGet);
 }