Exemple #1
0
        private async void Put()
        {
            if (Child != null)
            {
                var result = ChildValidator?.Validate(Child);
                if (result != null && result.IsValid)
                {
                    var      time     = DateTime.Now;
                    DateTime dateTime = new DateTime(Child.DOB.Year, Child.DOB.Month, Child.DOB.Day, time.Hour, time.Minute, time.Second, DateTimeKind.Utc);

                    Child.DOB = dateTime;

                    var jsonData = JsonConvert.SerializeObject(Child);
                    var data     = await DataService.Put(jsonData, $"Child/{FamilyId}/{Child.FId}");

                    if (data == "Submit")
                    {
                        StandardMessagesDisplay.EditDisplaymessage(Child.FullName);
                        var route = "..";
                        await Shell.Current.GoToAsync(route);
                    }
                    else
                    {
                        StandardMessagesDisplay.CanceledDisplayMessage();
                    }
                }
                else
                {
                    StandardMessagesDisplay.ValidationRulesViolation(result?.Errors[0].PropertyName, result?.Errors[0].ErrorMessage);
                }
            }
        }
        private async void Post()
        {
            if (Child != null)
            {
                Child.RegisteredBy = Guid.Parse(Preferences.Get("UserId", ""));
                Child.Id           = Guid.NewGuid();

                var      time     = DateTime.Now;
                DateTime dateTime = new DateTime(Child.DOB.Year, Child.DOB.Month, Child.DOB.Day, time.Hour, time.Minute, time.Second, DateTimeKind.Utc);

                Child.DOB = dateTime;

                var result = ChildValidator?.Validate(Child);
                if (result != null && result.IsValid)
                {
                    var jData = JsonConvert.SerializeObject(Child);

                    string postResponse = await DataService.Post(jData, $"Child/{Family?.Id}");

                    if (postResponse == "ConnectionError")
                    {
                        StandardMessagesDisplay.NoConnectionToast();
                    }
                    else if (postResponse == "Error")
                    {
                        StandardMessagesDisplay.Error();
                    }
                    else if (postResponse == "ErrorTracked")
                    {
                        StandardMessagesDisplay.ErrorTracked();
                    }
                    else
                    {
                        _ = await DataService.Put((++StaticDataStore.TeamStats.TotalChilds).ToString(), $"Team/{Preferences.Get("ClusterId", "")}/{Preferences.Get("TeamFId", "")}/TotalChilds");

                        StandardMessagesDisplay.EditDisplaymessage(Child.FullName);

                        var route = "..";
                        await Shell.Current.GoToAsync(route);
                    }
                }
                else
                {
                    StandardMessagesDisplay.ValidationRulesViolation(result?.Errors[0].PropertyName, result?.Errors[0].ErrorMessage);
                }
            }
        }