Example #1
0
        public async Task <string> AddShift(string userId, NewShift shift)
        {
            if (string.IsNullOrWhiteSpace(userId))
            {
                throw new ArgumentException($"'{nameof(userId)}' cannot be null or whitespace", nameof(userId));
            }

            if (shift is null)
            {
                throw new ArgumentNullException(nameof(shift));
            }

            await Initialise();

            var newShift = new Shift
            {
                Id       = Guid.NewGuid().ToString("N"),
                CrewMate = shift.CrewMate,
                Date     = shift.Date,
                Duration = shift.Duration,
                Event    = shift.Event,
                Location = shift.Location,
                Role     = shift.Role,
                UserId   = userId
            };

            var response = await _container.CreateItemAsync(newShift, new PartitionKey(userId));

            return(response.Resource.Id);
        }
        private async void AddBtn_Clicked(object sender, EventArgs e)
        {
            try
            {
                // If Firebase Cloud Messaging token exists, new shift data will be sent to backend
                var FCMToken = Application.Current.Properties.Keys.Contains("Fcmtoken");
                if (FCMToken)
                {
                    Apartment item = (Apartment)ApartmentPicker.SelectedItem;

                    // Kind property for datetime
                    // When the user does not change the date, the kind property is local as default -> the date will be wrong when it´s sent to backend in Azure
                    var unspecifiedDate = new DateTime(DatePicker.Date.Ticks, DateTimeKind.Unspecified);

                    NewShift newShift = new NewShift()
                    {
                        ApartmentId = item.ApartmentId,
                        Date        = unspecifiedDate
                    };

                    string        json    = JsonConvert.SerializeObject(newShift);
                    StringContent content = new StringContent(json, Encoding.UTF8, "application/json");

                    HttpClient          client   = new HttpClient();
                    HttpResponseMessage response = await client.PostAsync("https://isitmyturnapi.azurewebsites.net/api/completedshift", content);

                    int status = (int)response.StatusCode;

                    // Status codes:
                    // 200 - Everything OK
                    // 201 - A shift has added successfully. Some problems with notifications
                    if (status == 200)
                    {
                        await DisplayAlert("Is It My Turn", "Kirjauksen lisäys onnistui!", "OK");

                        await Navigation.PopToRootAsync();
                    }
                    else if (status == 201)
                    {
                        await DisplayAlert("Is It My Turn",
                                           "Kirjauksen lisäys onnistui, mutta ilmoitusten lähettämisessä käyttäjille ilmeni ongelmia.\r\n\r\n" +
                                           "Käytä WhatsApp-ryhmää vuoron vaihdon ilmoittamiseen ja ota yhteyttä sovelluksen ylläpitäjään.", "OK");

                        await Navigation.PopToRootAsync();
                    }
                    else
                    {
                        await DisplayAlert("Is It My Turn", "Tapahtui virhe lisätessä kirjausta. Ole hyvä ja yritä uudelleen.\r\nJos ongelma ei poistu, ota yhteyttä sovelluksen ylläpitäjään.", "OK");
                    }
                }
                else
                {
                    await DisplayAlert("Is It My Turn", "Tapahtui virhe lisätessä kirjausta. Ole hyvä ja yritä uudelleen.\r\nJos ongelma ei poistu, ota yhteyttä sovelluksen ylläpitäjään.", "OK");
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"######Error###### : {ex.Message}");
            }
        }
        private async void UpdateBtn_Clicked(object sender, EventArgs e)
        {
            // Updated data to database
            Apartment item = (Apartment)ApartmentPicker.SelectedItem;

            NewShift newShift = new NewShift()
            {
                ApartmentId = item.ApartmentId,
                Date        = DatePicker.Date
            };

            string        json    = JsonConvert.SerializeObject(newShift);
            StringContent content = new StringContent(json, Encoding.UTF8, "application/json");

            HttpClient          client   = new HttpClient();
            HttpResponseMessage response = await client.PutAsync("https://isitmyturnapi.azurewebsites.net/api/completedshift/" + shiftObject.ShiftId.ToString(), content);

            int status = (int)response.StatusCode;

            // Status codes:
            // 200 - Everything OK
            // 201 - A shift has updated successfully. Some problems with notifications
            if (status == 200)
            {
                await DisplayAlert("Is It My Turn", "Kirjaus päivitetty onnistuneesti!", "OK");

                var vUpdatedPage = new SeekAndDestroy();
                Navigation.InsertPageBefore(vUpdatedPage, this);
                NavigationPage.SetHasNavigationBar(vUpdatedPage, false);
                await Navigation.PopAsync();
            }
            else if (status == 201)
            {
                await DisplayAlert("Is It My Turn",
                                   "Kirjauksen päivitys onnistui, mutta ilmoitusten lähettämisessä käyttäjille ilmeni ongelmia.\r\n\r\n" +
                                   "Käytä WhatsApp-ryhmää vuoron vaihdon ilmoittamiseen ja ota yhteyttä sovelluksen ylläpitäjään.", "OK");

                var vUpdatedPage = new SeekAndDestroy();
                Navigation.InsertPageBefore(vUpdatedPage, this);
                NavigationPage.SetHasNavigationBar(vUpdatedPage, false);
                await Navigation.PopAsync();
            }
            else
            {
                await DisplayAlert("Is It My Turn", "Kirjauksen päivitys epäonnistui! Ole hyvä ja yritä uudelleen.\r\nJos ongelma ei poistu, ota yhteyttä sovelluksen ylläpitäjään.", "OK");
            }
        }
Example #4
0
        public void AddShift()
        {
            if (string.IsNullOrWhiteSpace(NewShift))
            {
                MessageBox.Show("Please do not leave any fields blank.", "Input Error",
                                MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }

            if (_assignedShifts.Add(Day, Job, NewShift.Trim(), NumAvailable))
            {
                MessageBox.Show($"The shift, {NewShift}, was added to the database.", "Operation Successful",
                                MessageBoxButton.OK, MessageBoxImage.Information);
                NewShift     = "";
                NumAvailable = 0;
                TryClose(true);
            }
            else
            {
                MessageBox.Show($"Unable to add the job, {NewShift}, to the database.", "Error",
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }