Пример #1
0
        public async Task <IActionResult> OnPost()
        {
            Console.WriteLine("Create method has been called");
            HttpResponseMessage result = await _crmClient.SendJsonAsync <Order4Creation>(HttpMethod.Post, Order4Creation.URI, dummy);

            if (result.StatusCode == System.Net.HttpStatusCode.NoContent)
            {
                string newOrderID = result.Headers.GetValues("OData-EntityId").FirstOrDefault();
                Console.WriteLine("New entity: {0}", newOrderID);
                // Use this id and Contact ID to create role in Connection
                // _record1id_value = order id
                // _record2id_value = contact id
                // record2objecttypecode = 2
                // name = person's name
                // _record2roleid_value = 8355863e-85fc-e611-810b-e0071b6685b1
                Connection conn = new Connection
                {
                    OrderID   = Utils.GetIdFromUrl(newOrderID),
                    ContactID = "5f880511-b362-e611-80e3-c4346bc43f98",
                    RoleID    = "8355863e-85fc-e611-810b-e0071b6685b1"
                };
                // This is an optional step?
                HttpResponseMessage cresult = await _crmClient.SendJsonAsync <Connection>(HttpMethod.Post, Connection.URI, conn);

                if (cresult.StatusCode != System.Net.HttpStatusCode.NoContent)
                {
                    Utils.DisplayResponse(cresult);
                }
                return(Redirect($"/Entities/Orders/?orderid={dummy.OrderID}"));
            }

            Utils.DisplayResponse(result);
            return(Redirect("/"));
        }
Пример #2
0
        public async Task <IActionResult> OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Console.WriteLine("Create method has been called without AccountID set");
            HttpResponseMessage result = await _crmClient.SendJsonAsync <JsonObject>(HttpMethod.Post, ContactBase.URI, Contact.Create());

            if (result.StatusCode == System.Net.HttpStatusCode.NoContent)
            {
                string newOrderID = result.Headers.GetValues("OData-EntityId").FirstOrDefault();
                Console.WriteLine("New entity: {0}", newOrderID);
            }
            else
            {
                Utils.DisplayResponse(result);
            }

            return(RedirectToPage("/Index"));
        }