public void CreateAdventureTest() { Adventure adventure = new Adventure() { Active = true, Date = DateTime.Now, Logbook = "The war has yet to end, and will be continued in the next mission", MaxPlayers = 3, Name = "War At The Riverside" }; adventureClient.Create(adventure); Assert.AreEqual(adventure.Name, adventureClient.Find(adventure.Name).Name); }
public ActionResult CreateAdventure(CreateAdventureVM model) { if (model.MaxPlayers <= 0) { ModelState.AddModelError("", "Max players must be more than 0."); return(View("CreateAdventure", model)); } if (model.Date < DateTime.Today) { ModelState.AddModelError("", "please choose a date from today and onwards."); return(View("CreateAdventure", model)); } UserClient client = new UserClient(); User Auser = client.Find(User.Identity.Name); if (adventureClient.Find(model.Name) != null) { ModelState.AddModelError("", "An Adventure with that name already exists."); return(View("CreateAdventure")); } try { { Adventure adventure = new Adventure { Name = model.Name, Date = model.Date, MaxPlayers = model.MaxPlayers, Players = new List <User>() }; adventure.Players.Add(Auser); adventureClient.Create(adventure); } /* * adventure - har user - tag user ID sæt user ID reference på adventure. */ return(RedirectToAction("AdventureScreen")); } catch (Exception ex) { Console.WriteLine(ex); ModelState.AddModelError("", "Adventure was not created. See exception for details."); return(View()); } }