public async Task TestCreateRecord()
        {
            var targetLayout = "cake_utility";

            Login();
            fms.SetLayout(targetLayout);
            var request = fms.NewRecordRequest();

            request.AddField("cake", RandomString(50, false));
            request.AddField("wine_pairing", RandomString(50, false));
            request.AddField("country", RandomString(50, false));

            // repeating field
            request.AddField("repeating_field", "9", 2);

            request.AddScript(ScriptTypes.before, "log", "parameter added, before request");
            request.AddScript(ScriptTypes.beforeSort, "log", "parameter added, before sort");
            request.AddScript(ScriptTypes.after, "log", "parameter added, after request");

            var id = await request.Execute();

            Logout();

            // default search with no other criteria returns 100 records
            Assert.True(request.Reply.messages[0].code == "0" && id > 0 && request.Reply.Response.ScriptError == "0");
        }
Beispiel #2
0
        //To add a new image against product/item
        private async Task CreateImage(string productRecordId, string fileName, object sender)
        {
            fmServer.SetLayout(productLayout);
            var newEditRequest = fmServer.EditRequest(Convert.ToInt32(productRecordId));

            newEditRequest.AddRelatedField("PositionNumber", "products||SPECGRAPHICS", "1", "graphicsportal");
            var editRequestResponse = await newEditRequest.Execute();

            var errorCheck = fmServer.lastErrorCode;

            var productPortalAndRecordId = await GetProductGraphicsPortalAndRecordID(Convert.ToInt32(productRecordId));

            var productPortalData = productPortalAndRecordId.GraphicsPortalData;

            var latestPortalRecordId = 0;

            if (productPortalData != null)
            {
                var portalDataRecordCount = productPortalData.records.Count();
                latestPortalRecordId = Convert.ToInt32(productPortalData.records.ElementAt(portalDataRecordCount - 1).recordId);
            }

            fmServer.SetLayout(graphicLayout);

            var graphicsRequest = fmServer.NewRecordRequest();

            graphicsRequest.AddField("GraphicURL", "");
            var newGraphicRecordId = await graphicsRequest.Execute();

            if (fmServer.lastErrorCode != 0)
            {
                MessageBox.Show($"Error: {fmServer.lastErrorMessage}");
            }

            FileInfo fileInfo = new FileInfo(fileName);

            fmServer.SetLayout(graphicLayout);

            int uploadContainerResponse = await fmServer.UploadFileIntoContainerField(newGraphicRecordId, "File", fileInfo);

            if (fmServer.lastErrorCode != 0)
            {
                MessageBox.Show(fmServer.lastErrorCode.ToString() + " - " + fmServer.lastErrorMessage);
            }

            var findGraphicRequest  = fmServer.FindRequest(newGraphicRecordId);
            var findGraphicResponse = await findGraphicRequest.Execute();

            var graphicFile = findGraphicResponse.data.foundSet.records.First().fieldsAndData["File"];

            fmServer.SetLayout(productLayout);

            newEditRequest = fmServer.EditRequest(Convert.ToInt32(productRecordId));
            newEditRequest.ModifyRelatedField("File", "products||SPECGRAPHICS||GRAPHICS", graphicFile, latestPortalRecordId, "graphicsportal");
            editRequestResponse = await newEditRequest.Execute();

            fmServer.SetLayout(graphicLayout);
            uploadContainerResponse = await fmServer.UploadFileIntoContainerField(newGraphicRecordId + 1, "File", fileInfo);

            errorCheck = fmServer.lastErrorCode;

            var base64String = string.Empty;

            using (Image image = Image.FromFile(fileName))
            {
                using (MemoryStream m = new MemoryStream())
                {
                    image.Save(m, image.RawFormat);
                    byte[] imageBytes = m.ToArray();
                    base64String = Convert.ToBase64String(imageBytes);
                }
            }

            var button = sender as Button;

            button.BackgroundImage       = Convertbase64ToImage(base64String);
            button.BackgroundImageLayout = ImageLayout.Stretch;
            button.Tag = $"{newGraphicRecordId + 1}, {productRecordId}";
        }