Esempio n. 1
0
        public ActionResult ChangeState(int id)
        {
            var ad = AdsService.GetById(id) ?? throw new NotFoundException("广告不存在!");

            ad.Status = ad.Status == Status.Available ? Status.Unavailable : Status.Available;
            return(ResultData(null, AdsService.SaveChanges() > 0, ad.Status == Status.Available ? $"【{ad.Title}】已上架!" : $"【{ad.Title}】已下架!"));
        }
Esempio n. 2
0
        public ActionResult ChangeState(int id)
        {
            var ad = AdsService.GetById(id);
            if (ad != null)
            {
                ad.Status = ad.Status == Status.Available ? Status.Unavailable : Status.Available;
                return ResultData(null, AdsService.SaveChanges() > 0, ad.Status == Status.Available ? $"【{ad.Title}】已上架!" : $"【{ad.Title}】已下架!");
            }

            return ResultData(null, false, "广告不存在");
        }