public async Task <HttpResponseMessage> DeleteAsync(AdvertisementModel _param) { var Res = Request.CreateResponse(); var Result = new Res(); try { if (_param != null) { await Task.Run(() => _advertisementService.Delete(_param)); Result.Status = true; Result.Message = "Xóa thành công"; Result.StatusCode = HttpStatusCode.OK; } else { Result.Status = false; Result.Message = "Xóa thất bại"; Result.StatusCode = HttpStatusCode.BadRequest; } Res.Content = new StringContent(JsonConvert.SerializeObject(Result)); return(Res); } catch (Exception ex) { Result.Status = false; Result.Message = "Có lỗi xảy ra trong quá trình xóa " + ex.Message; Result.StatusCode = HttpStatusCode.BadRequest; throw new Exception(ex.Message); } }
public async Task DeleteShouldReturnDbWithoutThatItem() { // Arrange var db = this.Context; this.PopulateData(db); var advertisementsService = new AdvertisementService(db); var advertisementId = 1; // Act await advertisementsService.Delete(advertisementId); // Assert db .Advertisements .Where(a => a.Id == advertisementId) .FirstOrDefault() .Should() .Be(null); db .Advertisements .Count() .Should() .Be(2); }
public ActionResult Delete(Advertisement adv) { _advService.Delete(adv); return(RedirectToAction("Index")); }