public HttpResponseMessage GetAll(HttpRequestMessage request, int id) { TinhTrang tinhTrang = null; try { tinhTrang = _tinhTrangService.GetById(id); if (tinhTrang != null) { Message = "thông tin tình trạng"; } else { throw new DbEntityValidationException(string.Format("Không tồn tại tình trạng với id {0}", id)); } } catch (DbEntityValidationException ex) { LogException(ex); } return(GetResponseMessage(IsSuccess, Message, 1, tinhTrang)); }
public HttpResponseMessage Delete(HttpRequestMessage request, int id) { ThuCung modelThuCung = null; try { var listCanNang = _canNangService.GetAll(); foreach (var item in listCanNang) { if (item.IdThuCung != id) { continue; } _canNangService.GetById(item.IdCanNang); _canNangService.Delete(item.IdCanNang); } _thuCungService.SaveChange(); var listTinhTrang = _tinhTrangService.GetAll(); foreach (var item in listTinhTrang) { if (item.IdThuCung != id) { continue; } _tinhTrangService.GetById(item.IdTinhTrang); _tinhTrangService.Delete(item.IdTinhTrang); } _thuCungService.SaveChange(); modelThuCung = _thuCungService.Delete(id); if (modelThuCung != null) { Message = "Xóa thú cưng thành công"; _thuCungService.SaveChange(); } else { throw new DbEntityValidationException("Xóa thú cưng không thành công"); } } catch (DbEntityValidationException ex) { LogException(ex); } return(GetResponseMessage(IsSuccess, Message, 1, modelThuCung)); }