public IHttpActionResult PutHappening(int id, Happening happening)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != happening.HappeningId)
            {
                return BadRequest();
            }

            db.Entry(happening).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HappeningExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Ejemplo n.º 2
0
        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>
 /// Populates the page with content passed during navigation. Any saved state is also
 /// provided when recreating a page from a prior session.
 /// </summary>
 /// <param name="sender">
 /// The source of the event; typically <see cref="NavigationHelper"/>
 /// </param>
 /// <param name="e">Event data that provides both the navigation parameter passed to
 /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
 /// a dictionary of state preserved by this page during an earlier
 /// session. The state will be null the first time a page is visited.</param>
 private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
 {
     var happening = await new HssTicketing.DataSource.HappeningDataSource().GetHappeningAsync((int)e.NavigationParameter);
     this.DefaultViewModel["Happening"] = happening;
     this.DefaultViewModel["Tickets"] =  happening.Tickets;
     this.happening = happening;
 }
        public IHttpActionResult PostHappening(Happening happening)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Happenings.Add(happening);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = happening.HappeningId }, happening);
        }
        /// <summary>
        /// Adds the happening.
        /// </summary>
        /// <param name="happening">The happening.</param>
        /// <returns></returns>
        public async Task<Boolean> AddHappening(Happening happening)
        {
            StringContent stringObject = new StringContent(JsonConvert.SerializeObject(happening), Encoding.UTF8, "application/json");
            HttpResponseMessage response = await _client.PostAsync("Happenings", stringObject);

            if (response.IsSuccessStatusCode)
            {
                _happenings.Add(happening);
                return true;
            }
            return false;
        }
 /// <summary>
 /// Populates the page with content passed during navigation. Any saved state is also
 /// provided when recreating a page from a prior session.
 /// </summary>
 /// <param name="sender">
 /// The source of the event; typically <see cref="NavigationHelper"/>
 /// </param>
 /// <param name="e">Event data that provides both the navigation parameter passed to
 /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
 /// a dictionary of state preserved by this page during an earlier
 /// session. The state will be null the first time a page is visited.</param>
 private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
 {
     try
     {
         var happening = await new HssTicketing.DataSource.HappeningDataSource().GetHappeningAsync((int)e.NavigationParameter);
         pageTitle.Text = happening.HappeningName;
         pageHappening = happening;
     }
     catch (Exception)
     {
         ExceptionMessages.DatabaseExceptionMessageAsync();
         this.Frame.Navigate(typeof(LogOnPage));
     }
 }
 /// <summary>
 /// Adds the event asynchronous.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
 private async void AddEventAsync(object sender, RoutedEventArgs e)
 {
     Happening happening = new Happening() { HappeningName = HappeningName.Text, Location = Location.Text, MaxParticipants = int.Parse(MaxParticipants.Text)};
     var resultHappening = await new HssTicketing.DataSource.HappeningDataSource().AddHappening(happening);
     if (resultHappening)
     {
         var dialog = new CoreWindowDialog(String.Format("The event '{0}' has been added successfully!", happening.HappeningName));
         await dialog.ShowAsync();
         this.Frame.Navigate(typeof (EventsPage));
     }
 }
        /// <summary>
        /// Puts the happening asynchronous.
        /// </summary>
        /// <param name="happening">The happening.</param>
        /// <returns></returns>
        public async Task<Boolean> PutHappeningAsync(Happening happening)
        {
            var buildString = JsonConvert.SerializeObject(happening, new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects, ReferenceLoopHandling = ReferenceLoopHandling.Serialize });
            StringContent stringObject = new StringContent(buildString, Encoding.UTF8, "application/json");
            HttpResponseMessage response = await _client.PutAsync(String.Format("Happenings/{0}", happening.HappeningId), stringObject);

            if (response.IsSuccessStatusCode)
            {
                _happenings.Add(happening);
                return true;
            }
            return false;
        }