public async Task UpdateAdvertisementStatus(Advertisement advertisement, AdvertisementStatus newAdvertisementStatus) { advertisement.Status = newAdvertisementStatus; _dbContext.Advertisements.Update(advertisement); await _dbContext.SaveChangesAsync(); }
private IHttpActionResult ChangeAdStatus(int advertisementId, AdvertisementStatus newAdvertisementStatus, string message) { var ad = this.Data.Ads.All().FirstOrDefault(a => a.Id == advertisementId); if (ad == null) { return(this.BadRequest("Advertisement #" + advertisementId + " not found!")); } // Validate the current user ownership over the ad var currentUserId = User.Identity.GetUserId(); if (ad.OwnerId != currentUserId) { return(this.Unauthorized()); } ad.Status = newAdvertisementStatus; this.Data.SaveChanges(); return(this.Ok(new { message })); }
private IHttpActionResult ChangeAdStatus(int advertisementId, AdvertisementStatus newAdvertisementStatus, string message) { var ad = this.Data.Ads.All().FirstOrDefault(a => a.Id == advertisementId); if (ad == null) { return this.BadRequest("Advertisement #" + advertisementId + " not found!"); } // Validate the current user ownership over the ad var currentUserId = User.Identity.GetUserId(); if (ad.OwnerId != currentUserId) { return this.Unauthorized(); } ad.Status = newAdvertisementStatus; this.Data.SaveChanges(); return this.Ok(new { message }); }