Exemple #1
0
        private async Task SubmitAsync()
        {
            HttpClient Http = new HttpClient();

            Http.DefaultRequestHeaders.Add("Accept", "application/json");
            Http.DefaultRequestHeaders.Add("X-RequestDigest", await VCSTools.GetDigestAsync(Navigator.BaseUri));
            Item     data     = new Item();
            Metadata metadata = new Metadata();

            metadata.Type             = Config.MainListType;
            data.Metadata             = metadata;
            data.OfficeId             = office.GetItemId();
            data.MeterViolationTypeId = form1Vald.MeterViolationType;
            data.ViolationDate        = form1Vald.ViolationDate;
            data.Region                 = form1Vald.Region;
            data.City                   = form1Vald.City;
            data.Colony                 = form1Vald.Colony;
            data.Street                 = form1Vald.Street;
            data.House                  = form1Vald.House;
            data.AccountNumber          = form1Vald.AccountNumber;
            data.ViolationDetails       = form1Vald.ViolationDetails;
            data.DamageDetails          = form1Vald.DamageDetails;
            data.DiscovererNameId       = peoplePicker.GetValue();
            data.ViolatorName           = form1Vald.ViolatorName;
            data.ViolatorType           = form1Vald.ViolatorType;
            data.ViolatorNationalID     = form1Vald.ViolatorNationalID;
            data.ViolatorNationalIDType = form1Vald.ViolatorNationalIDType;
            data.ViolatorMobile         = form1Vald.ViolatorMobile;
            data.ViolatorStatement      = form1Vald.ViolatorStatement;
            data.Stage                  = 0;
            var myContent   = JsonConvert.SerializeObject(data);
            var buffer      = System.Text.Encoding.UTF8.GetBytes(myContent);
            var byteContent = new ByteArrayContent(buffer);
            var mediaType   = new MediaTypeWithQualityHeaderValue("application/json");

            MediaTypeWithQualityHeaderValue.TryParse("application/json;odata=verbose", out mediaType);
            byteContent.Headers.ContentType = mediaType;
            var response = await Http.PostAsync(Navigator.BaseUri + Config.BaseURL + "_api/web/lists(guid'" + Config.MainListGuid + "')/items", byteContent);

            if (response.StatusCode == HttpStatusCode.Created)
            {
                root = JsonConvert.DeserializeObject <Root>(await response.Content.ReadAsStringAsync());
                await SetViolationIdAsync(root.Id);
            }
        }
Exemple #2
0
        private async Task SetViolationIdAsync(int id)
        {
            string     vid  = VCSTools.GetVid(id);
            HttpClient Http = new HttpClient();

            Http.DefaultRequestHeaders.Add("Accept", "application/json");
            Http.DefaultRequestHeaders.Add("X-RequestDigest", await VCSTools.GetDigestAsync(Navigator.BaseUri));
            Http.DefaultRequestHeaders.Add("IF-MATCH", "*");
            Http.DefaultRequestHeaders.Add("X-HTTP-Method", "MERGE");
            Item     data     = new Item();
            Metadata metadata = new Metadata();

            metadata.Type = Config.MainListType;
            data.Metadata = metadata;
            data.Title    = vid;
            var myContent   = JsonConvert.SerializeObject(data);
            var buffer      = System.Text.Encoding.UTF8.GetBytes(myContent);
            var byteContent = new ByteArrayContent(buffer);
            var mediaType   = new MediaTypeWithQualityHeaderValue("application/json");

            MediaTypeWithQualityHeaderValue.TryParse("application/json;odata=verbose", out mediaType);
            byteContent.Headers.ContentType = mediaType;
            var response = await Http.PostAsync(Navigator.BaseUri + Config.BaseURL + "_api/web/lists(guid'" + Config.MainListGuid + "')/items('" + id + "')", byteContent);

            if (response.StatusCode == HttpStatusCode.NoContent)
            {
                result = "سجل بنجاح باستخدام رقم التعريف: #" + vid;
                bool x = await jsRun.InvokeAsync <bool>("alertx");

                Navigator.NavigateTo("default.aspx/forms/workflow/" + id);
            }
            else
            {
                result = "فشل السجل في الحفظ";
                Console.WriteLine(result + " : " + JsonConvert.SerializeObject(data));
            }
        }