public void Update(Favorite model) { var target = Find(model.ID); db.Attach<Favorite>(target); target.Status = model.Status; db.Commit(); }
public void Create(Favorite model) { db.Add<Favorite>(model); db.Commit(); }
public void Delete(Favorite model) { var target = Find(model.ID); db.Remove<Favorite>(target); db.Commit(); }
public ActionResult AddFavorite(int id) { ServiceResult result = new ServiceResult(); var MemberID = CookieHelper.MemberID; if (!FavoriteService.GetALL().Any(x => x.MemberID == MemberID && x.MediaID == id)) { try { Favorite entity = new Favorite() { MediaID = id, MemberID = MemberID, AddTime = DateTime.Now }; FavoriteService.Create(entity); } catch (Exception ex) { result.Message = "添加收藏失败!"; result.AddServiceError(Utilities.GetInnerMostException(ex)); LogHelper.WriteLog("用户:" + CookieHelper.MemberID + "添加收藏失败!", ex); } } else { result.Message = "已经收藏了该媒体"; result.AddServiceError("已经收藏了该媒体"); } return Json(result, JsonRequestBehavior.AllowGet); }