示例#1
0
        public static SkinRegion ToAppModel(ServiceData.Models.SkinRegion given, bool includeBodyPart)
        {
            SkinRegion region = new SkinRegion
            {
                Id   = given.Id,
                Name = given.Name
            };

            if (includeBodyPart)
            {
                region.BodyPart = BodyPart.ToAppModel(given.BodyPart, false);
            }

            return(region);
        }
示例#2
0
        private void UpdateRegionPicker()
        {
            regionPicker.Items.Clear();

            for (int i = 0; i < selectedBp.GetSkinRegions().Count; i++)
            {
                regionPicker.Items.Add(selectedBp.GetSkinRegions()[i].DisplayName);

                if (editingCondition != null && selectedBp.Id == editingCondition.SkinRegion.BodyPart.Id)
                {
                    if (selectedBp.GetSkinRegions()[i].Id == editingCondition.SkinRegion.Id)
                    {
                        selectedSkinRegion         = selectedBp.GetSkinRegions()[i];
                        regionPicker.SelectedIndex = i;
                    }
                }
                else if (i == 0)
                {
                    selectedSkinRegion         = selectedBp.GetSkinRegions()[i];
                    regionPicker.SelectedIndex = 0;
                }
            }
        }
示例#3
0
        private async void CommitChanges(UserCondition existing)
        {
            if (string.IsNullOrWhiteSpace(conditionEntry.Text))
            {
                UserDialogs.Instance.Alert(AppResources.ConditionEdit_conditionNameError);
                return;
            }

            selectedSkinRegion          = GetSRFromName(regionPicker.Items[regionPicker.SelectedIndex]);
            selectedSkinRegion.BodyPart = selectedBp;

            UserCondition newCondition = new UserCondition
            {
                Owner      = App.user,
                StartDate  = startDatePicker.Date,
                SkinRegion = selectedSkinRegion,
                Condition  = conditionEntry.Text
            };

            if (passcodeSwitch.IsToggled)
            {
                newCondition.Passcode = int.Parse(code);
            }

            if (existing != null)
            {
                if (activeSwitch != null)
                {
                    newCondition.Finished = activeSwitch.IsToggled;
                }

                newCondition.Id     = existing.Id;
                newCondition.Photos = existing.Photos;
                newCondition.Owner  = existing.Owner;

                UserDialogs.Instance.ShowLoading(AppResources.Dialog_loading);

                string json = JsonConvert.SerializeObject(newCondition,
                                                          new JsonSerializerSettings
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                });

                ServerResponse <Photo> photoResp = await NetworkUtils.PutRequest <Photo>("api/UserConditions/" + existing.Id, json);

                UserDialogs.Instance.HideLoading();

                if (photoResp.Response == null || !photoResp.Response.IsSuccessStatusCode)
                {
                    UserDialogs.Instance.Alert(AppResources.ConditionEdit_updateError, AppResources.Error_update);
                    return;
                }

                newCondition.reminder = (UserCondition.ReminderType)reminderTypePicker.SelectedIndex;
                UpdateLocalDB(newCondition);

                UserDialogs.Instance.HideLoading();
                App.ShouldUpdate = true;

                await UserDialogs.Instance.AlertAsync(AppResources.ConditionEdit_updateSuccess, AppResources.Dialog_success);

                await App.Homepage.Navigation.PopAsync();

                App.Homepage.Navigation.PopAsync();
            }
            else
            {
                string message = string.Format(AppResources.ConditionEdit_confirm, conditionEntry.Text, selectedSkinRegion.DisplayName);

                if (!await UserDialogs.Instance.ConfirmAsync(message, AppResources.ConditionEdit_confirmTitle, AppResources.Dialog_confirm, AppResources.Dialog_cancel))
                {
                    return;
                }

                UserDialogs.Instance.ShowLoading(AppResources.Dialog_loading);

                ServerResponse <UserCondition> userResp = await NetworkUtils.PostRequest <UserCondition>("api/UserConditions",
                                                                                                         JsonConvert.SerializeObject(newCondition, new JsonSerializerSettings
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                }));

                UserDialogs.Instance.HideLoading();

                if (userResp.Response == null || !userResp.Response.IsSuccessStatusCode)
                {
                    await UserDialogs.Instance.AlertAsync(AppResources.ConditionEdit_submitError + userResp.Response.ReasonPhrase, AppResources.Dialog_error);

                    return;
                }

                newCondition.reminder = (UserCondition.ReminderType)reminderTypePicker.SelectedIndex;
                UpdateLocalDB(newCondition);

                App.ShouldUpdate = true;

                App.Homepage.Navigation.PopAsync();
            }
        }