public ActionResult AddCollect(int id) { AjaxModel model = new AjaxModel(); Collect collect = new Collect(); try { collect = db.Collects.Where(u => u.TID == id && u.UserID == CurrentUser.ID && u.CollectTypeAsInt == 0).FirstOrDefault(); if (collect == null) { collect = new Collect(); collect.CollectType = CollectType.User; collect.UserID = CurrentUser.ID; collect.TID = id; collect.Time = DateTime.Now; collect.CollectTypeAsInt = 0; db.Collects.Add(collect); db.SaveChanges(); model.Statu = "ok"; } else { model.Statu = "err"; model.Msg = "该牛人已收藏!"; } } catch (Exception ex) { log.Error(new LogContent("牛人收藏出错", HttpHelper.GetIPAddress()), ex); model.Statu = "err"; model.Msg = "收藏失败!"; } return Json(model); }
/// <summary> /// 删除收藏 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult RemoveCollect(int id) { Collect collect = new Collect(); try { collect = db.Collects.Find(id); if (collect != null) { db.Collects.Remove(collect); db.SaveChanges(); return Content("ok"); } else { return Content("err"); } } catch (Exception ex) { log.Error(new LogContent("牛人删除收藏出错", HttpHelper.GetIPAddress()), ex); return Content("err"); } }
public ActionResult CollectShow(int id) { AjaxModel ajaxModel = new AjaxModel(); if (CurrentUser == null) { ajaxModel.Statu = "err"; ajaxModel.Msg = "请先登录"; } else { try { var collect = new Collect(); collect = db.Collects.Where(c => c.CollectTypeAsInt == 2 && c.TID == id && c.UserID == CurrentUser.ID).FirstOrDefault(); if (collect == null) { collect = new Collect(); collect.Time = DateTime.Now; collect.TID = id; collect.UserID = CurrentUser.ID; collect.CollectTypeAsInt = 2; db.Collects.Add(collect); db.SaveChanges(); ajaxModel.Statu = "ok"; ajaxModel.Msg = "关注成功"; } else { ajaxModel.Statu = "err"; ajaxModel.Msg = "已关注"; } } catch (Exception ex) { ajaxModel.Statu = "err"; ajaxModel.Msg = "关注出错"; log.Error(new LogContent("关注出错", Helpers.HttpHelper.GetIPAddress()), ex); } } return Json(ajaxModel); }
public ActionResult CancelCollect(int id) { AjaxModel model = new AjaxModel(); Collect collect = new Collect(); try { collect = db.Collects.Where(u => u.TID == id && u.UserID == CurrentUser.ID && u.CollectTypeAsInt == 0).FirstOrDefault(); if (collect != null) { db.Collects.Remove(collect); db.SaveChanges(); model.Statu = "ok"; } else { model.Statu = "err"; model.Msg = "未收藏!"; } } catch (Exception ex) { log.Error(new LogContent("牛人取消收藏出错", HttpHelper.GetIPAddress()), ex); model.Statu = "err"; model.Msg = "取消收藏失败!"; } return Json(model); }
public ActionResult CancelCollectForum(int id) { AjaxModel ajaxModel = new AjaxModel(); try { var collect = new Collect(); collect = db.Collects.Where(c => c.CollectTypeAsInt == 2 && c.TID == id && c.UserID == CurrentUser.ID).FirstOrDefault(); if (collect != null) { db.Collects.Remove(collect); db.SaveChanges(); ajaxModel.Statu = "ok"; ajaxModel.Msg = "取消关注成功"; } else { ajaxModel.Statu = "err"; ajaxModel.Msg = "未关注"; } } catch (Exception ex) { ajaxModel.Statu = "err"; ajaxModel.Msg = "取消关注出错"; log.Error(new LogContent("取消关注出错", Helpers.HttpHelper.GetIPAddress()), ex); } return Json(ajaxModel); }