Example #1
0
        // On navigated to event handler
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            _event = (Event) e.Parameter;

            int[] startDate = ParseDate(_event.StartDate);
            int[] endDate = ParseDate(_event.EndDate);
            startDatePicker.Date = new DateTimeOffset(new DateTime(startDate[2], startDate[1], startDate[0]));
            endDatePicker.Date = new DateTimeOffset(new DateTime(endDate[2], endDate[1], endDate[0]));

            base.OnNavigatedTo(e);
        }
Example #2
0
        // Insert event to database, clear all fields
        private async void InsertEvent(object sender, RoutedEventArgs e)
        {
            if(ValidateForm())
            {
                // Dismiss the save button, show progress ring
                SaveButton.Visibility = Visibility.Collapsed;
                progressRing.Visibility = Visibility.Visible;

                Event _event = new Event()
                {
                    UserId = App.MobileService.CurrentUser.UserId,
                    Id = Guid.NewGuid().ToString(),
                    Title = titleTextBox.Text,
                    Location = locationTextBox.Text,
                    StartDate = startDatePicker.Date.ToString("dd/MM/yyyy"),
                    EndDate = endDatePicker.Date.ToString("dd/MM/yyyy"),
                    Desc = descTextBox.Text,
                    Category = categoryComboBox.SelectedItem.ToString(),
                    Fee = Int32.Parse(feeTextBox.Text)
                };
                
                // Begin upload process
                string errorString = string.Empty;
                if (image != null)
                {
                    // Set blob properties of the event
                    _event.ContainerName = "eventimages";

                    // Use a unigue GUID to avoid collisions.
                    _event.ResourceName = Guid.NewGuid().ToString();
                }

                try
                {
                    await eventTable.InsertAsync(_event);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.StackTrace);
                    MessageDialog msg = new MessageDialog("Problem occured, please retry again");
                    await msg.ShowAsync();
                }

                // If we have a returned SAS, then upload the blob
                if (!string.IsNullOrEmpty(_event.SasQueryString))
                {
                    // Get the URI generated that contains the SAS 
                    // and extract the storage credentials
                    StorageCredentials cred = new StorageCredentials(_event.SasQueryString);
                    var imageUri = new Uri(_event.ImageUri);

                    // Instantiate a Blob store container based on the info in the returned item
                    CloudBlobContainer container = new CloudBlobContainer(
                        new Uri(string.Format("https://{0}/{1}",
                            imageUri.Host, _event.ContainerName)), cred);

                    // Get the new image as a stream
                    using (var inputStream = await image.OpenReadAsync())
                    {
                        // Upload the new image as a BLOB from the stream
                        CloudBlockBlob blobFromSASCredential =
                            container.GetBlockBlobReference(_event.ResourceName);
                        await blobFromSASCredential.UploadFromStreamAsync(inputStream);
                    }
                    
                    MessageDialog msg = new MessageDialog("The Event is successfully created");
                    ResetFields();
                    await msg.ShowAsync();
                }
                else
                {
                    // Failed to upload image, delete the previously created event
                    await eventTable.DeleteAsync(_event);

                    MessageDialog msg = new MessageDialog("Problem occured, please retry again");
                    await msg.ShowAsync();
                }
                
                // Dismiss the progress ring, bring back the save button
                SaveButton.Visibility = Visibility.Visible;
                progressRing.Visibility = Visibility.Collapsed;
            }
        }
Example #3
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     _event = (Event) e.Parameter;
     base.OnNavigatedTo(e);
 }