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}】已下架!")); }
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, "广告不存在"); }
public async Task<IActionResult> Redirect(int id) { var ad = AdsService.GetById(id) ?? throw new NotFoundException("广告不存在"); if (!HttpContext.Request.IsRobot() && string.IsNullOrEmpty(HttpContext.Session.Get<string>("ads" + id))) { HttpContext.Session.Set("ads" + id, id.ToString()); ad.ViewCount++; await AdsService.SaveChangesAsync(); } return RedirectPermanent(ad.Url); }
public async Task<IActionResult> Save(AdvertisementDto model) { model.CategoryId = model.CategoryId?.Replace("null", ""); var entity = AdsService.GetById(model.Id); if (entity != null) { Mapper.Map(model, entity); bool b1 = await AdsService.SaveChangesAsync() > 0; return ResultData(null, b1, b1 ? "修改成功" : "修改失败"); } bool b = AdsService.AddEntitySaved(model.Mapper<Advertisement>()) != null; return ResultData(null, b, b ? "添加成功" : "添加失败"); }