Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Server Error in '/' Application.
- Object reference not set to an instance of an object.
- Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
- Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
- Source Error:
- Line 241: lobbyViewModel.lobby.name = lobbyViewModel.name;
- Line 242: lobbyViewModel.lobby.category.id = categoryId;
- Line 243: lobbyViewModel.lobby.isStarted = false;
- Line 244: lobbyClient.CreateLobby(lobbyViewModel.lobby);
- [DataContract(IsReference = true)]
- public class Category
- {
- [DataMember]
- public int id { get; set; }
- [DataMember]
- public string name { get; set; }
- [DataMember]
- public int amount { get; set; }
- [DataMember]
- public Quiz quiz { get; set; }
- [DataMember]
- public List<Question> question { get; set; }
- public Category()
- {
- question = new List<Question>();
- }
- }
- public class Lobby
- {
- [DataMember]
- public int id { get; set; }
- [DataMember]
- public string name { get; set; }
- [DataMember]
- public Category category { get; set; }
- [DataMember]
- public bool isStarted { get; set; }
- }
- public class LobbyViewModel
- {
- public LobbyReference.Lobby lobby { get; set; }
- public List<LobbyReference.Lobby> lobbies { get; set; }
- public LobbyViewModel()
- {
- lobby = new LobbyReference.Lobby();
- lobbies = new List<LobbyReference.Lobby>();
- }
- public int id { get; set; }
- public string name { get; set; }
- public int categoryId { get; set; }
- public bool isStarted { get; set; }
- }
- public void CreateLobby(Lobby lobby)
- {
- TransactionOptions options = new TransactionOptions();
- options.IsolationLevel = System.Transactions.IsolationLevel.Serializable;
- using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
- {
- using (var conn = new SqlConnection(connectionString))
- {
- using (SqlCommand command = conn.CreateCommand())
- {
- conn.Open();
- command.CommandText = "INSERT INTO Lobby(name, categoryId, isStarted)VALUES(@name, @categoryId, @isStarted)";
- command.Parameters.Add("name", SqlDbType.NVarChar).Value = lobby.name;
- command.Parameters.Add("categoryId", SqlDbType.Int).Value = lobby.category.id;
- command.Parameters.Add("isStarted", SqlDbType.Bit).Value = lobby.isStarted;
- command.ExecuteNonQuery();
- }
- scope.Complete();
- conn.Close();
- }
- }
- }
- // THIS IS MY WCF REFERENCE WHERE I CAN CALL MY METHODS FROM
- private LobbyServiceClient lobbyClient = new LobbyServiceClient();
- public ActionResult Lobby(int categoryId)
- {
- LobbyViewModel lobbyViewModel = new LobbyViewModel();
- lobbyViewModel.lobbies = lobbyClient.GetAllLobbiesWithCategoryId(categoryId);
- lobbyViewModel.categoryId = categoryId;
- return View(lobbyViewModel);
- }
- public ActionResult CreateLobby(int categoryId)
- {
- LobbyViewModel lobbyViewModel = new LobbyViewModel();
- lobbyViewModel.categoryId = categoryId;
- return View(lobbyViewModel);
- }
- [HttpPost]
- public ActionResult CreateLobby(LobbyViewModel lobbyViewModel, int categoryId)
- {
- lobbyViewModel.lobby.name = lobbyViewModel.name;
- lobbyViewModel.lobby.category.id = categoryId;
- lobbyViewModel.lobby.isStarted = false;
- lobbyClient.CreateLobby(lobbyViewModel.lobby);
- return RedirectToAction("Lobby");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement