private static void BuildTestData() { using (var data = new HssTicketingContext()) { var user = new User() { FirstName = "Nicolai", LastName = "Naglestad", UserName = "******", AccessLevel = 1, Password = "******" }; data.Users.Add(user); var user2 = new User() { FirstName = "Ola", LastName = "Nordman", UserName = "******", AccessLevel = 2, Password = "******" }; data.Users.Add(user2); var happening = new Happening() { HappeningName = "Neon Party", Location = "Remmen", MaxParticipants = 100}; data.Happenings.Add(happening); var happening2 = new Happening() { HappeningName = "Test Party", Location = "Fredrikstad", MaxParticipants = 50}; data.Happenings.Add(happening2); var ticket = new Ticket() { Happening = happening, UniqueId = "123456789", Scanned = true, TimeScanned = new DateTime(2015, 11, 12, 15, 25, 00) }; data.Tickets.Add(ticket); var ticket2 = new Ticket() { Happening = happening2, UniqueId = "987654321", Scanned = true, TimeScanned = new DateTime(2015, 11, 12, 17, 25, 00) }; data.Tickets.Add(ticket2); var ticket3 = new Ticket() { Happening = happening, UniqueId = "147258369" }; data.Tickets.Add(ticket3); var ticket4 = new Ticket() { Happening = happening2, UniqueId = "963852741" }; data.Tickets.Add(ticket4); data.SaveChanges(); } }
/// <summary> /// Adds the user. /// </summary> /// <param name="user">The user.</param> /// <returns></returns> public async Task<Boolean> AddUser(User user) { StringContent stringObject = new StringContent(JsonConvert.SerializeObject(user), Encoding.UTF8, "application/json"); HttpResponseMessage reply = await _client.PostAsync("Users", stringObject); if (reply.IsSuccessStatusCode) { _users.Add(user); return true; } return false; }
/// <summary> /// Puts the user asynchronous. /// </summary> /// <param name="user">The user.</param> /// <returns></returns> public async Task<Boolean> PutUserAsync(User user) { var buildString = JsonConvert.SerializeObject(user, new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects, ReferenceLoopHandling = ReferenceLoopHandling.Serialize }); StringContent stringObject = new StringContent(buildString, Encoding.UTF8, "application/json"); HttpResponseMessage response = await _client.PutAsync(String.Format("Users/{0}", user.UserName), stringObject); if (response.IsSuccessStatusCode) { _users.Add(user); return true; } return false; }