public void CleanUp(bool keepHousehold) { DeleteHouseholdRequest request = new DeleteHouseholdRequest { KeepHousehold = keepHousehold }; HttpRequestMessage requestMessage = new HttpRequestMessage { Content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"), Method = HttpMethod.Delete, RequestUri = new Uri(_fakeSever.BaseAddress, "Api/v2/Household") }; var result = _fakeSever.SendAsync(requestMessage).Result; var responseBody = result.Content.ReadAsStringAsync().Result; }
public CommunicationResponse DeleteHousehold([FromBody] DeleteHouseholdRequest deleteHouseholdRequest) { var response = new CommunicationResponse(); try { if (_userService.AuthenticateSession(Request.Headers["Authorization"].ToString()) == false) { response.AddError("The authorization credentails were invalid", ErrorCode.SESSION_INVALID); return(response); } string sessionId = Request.Headers["Authorization"].ToString(); ActiveUser user = _userService.GetUserInformationFromAuthHeader(sessionId); if (user.HouseId == 0) { response.AddError("You must belong to a household", ErrorCode.USER_NOT_IN_HOUSEHOLD); return(response); } _billRepository.DeleteHouseholdBills(user.HouseId); _shoppingRepository.DeleteHouseholdShoppingItems(user.HouseId); _toDoRepository.DeleteHouseholdToDoTask(user.HouseId); if (deleteHouseholdRequest.KeepHousehold == false) { _houseRepository.DeleteHousehold(user.HouseId); _userService.DeleteSession(sessionId); _userService.UpdateHouseholdForUser(sessionId, -1); } response.Notifications = new List <string> { $"The data for the household (ID: {user.HouseId}) have been deleted" }; } catch (ErrorCodeException exception) { response.AddError($"An unexpected exception occured: {exception}", deleteHouseholdRequest, exception.Code); } catch (Exception exception) { response.AddError($"An unexpected exception occured: {exception}", deleteHouseholdRequest); } return(response); }