コード例 #1
0
    private string UpdateTarget(string targetID, string targetName, float width, string imagePath, bool active, string metaData)
    {
        string requestPath = "/targets/" + targetID;
        string serviceURI  = url + requestPath;
        string httpAction  = "PUT";
        string contentType = "application/json";

        //Upload target as json. Image needs to be base64 string
        string imageEncode64 = null;

        if (imagePath != null)
        {
            byte[] imgBytes = File.ReadAllBytes(imagePath);
            imageEncode64 = Convert.ToBase64String(imgBytes);
        }
        JsonPost targetPost = new JsonPost(targetName, width, imageEncode64, active, metaData);
        //The object being posted, but also the body that forms the request.
        string requestBody = "{" + (targetName != null ? @"""name"":""" + targetName + @"""," : "") + @"""width"":" + width +
                             (imageEncode64 != null ? @",""image"":""" + imageEncode64 + @""",""active_flag"":" : @",""active_flag"":") + active.ToString().ToLower() +
                             (metaData != null ? @",""application_metadata"":""" + metaData + @"""}" : "}");

        UnityWebRequest webRequest   = UnityWebRequest.Put(serviceURI, System.Text.Encoding.UTF8.GetBytes(requestBody));
        string          returnString = VuforiaRequest(requestPath, httpAction, contentType, requestBody, webRequest);

        UpdateTargetInformation(targetID);
        return(returnString);
    }
コード例 #2
0
        // Create
        public void AddPost(JsonPost post)
        {
            var author = _context.Authors
                         .Include(auth => auth.Posts)
                         .FirstOrDefault(auth => auth.AuthorId == post.AuthorId);
            var postToAdd = new Post
            {
                Title   = post.Title,
                Content = post.Content
            };

            author.Posts.Add(postToAdd);
            _context.SaveChanges();
        }
コード例 #3
0
    public void TestPerformAsyncPOST()
    {
        var restHandler = new RestHandler("http://jsonplaceholder.typicode.com");

        // Setup
        var data = new JsonPost();

        data.value = "hello";
        var payload      = JsonUtility.ToJson(data);
        var responseJson = new JsonPost();

        // Response
        Task.Run(async() => {
            var response = await restHandler.PerformAsyncPost("/posts", payload);
            responseJson = JsonUtility.FromJson <JsonPost>(response);
        }).GetAwaiter().GetResult();

        Assert.That(responseJson.value, Is.EqualTo("hello"));
    }
コード例 #4
0
    private bool UploadTarget(string targetName, float width, string imagePath, bool active, string metaData)
    {
        string requestPath = "/targets";
        string serviceURI  = url + requestPath;
        string httpAction  = "POST";
        string contentType = "application/json";

        byte[]   imgBytes      = File.ReadAllBytes(imagePath);
        string   imageEncode64 = Convert.ToBase64String(imgBytes);
        JsonPost targetPost    = new JsonPost(targetName, width, imageEncode64, active, metaData);
        string   requestBody   = JsonUtility.ToJson(targetPost);

        //Post request requires string input, but the requestBody will cause a 401 unauthorized error,
        //so you need to use kHttpVerbPost, then set the upload handler separately
        UnityWebRequest  webRequest      = UnityWebRequest.Post(serviceURI, UnityWebRequest.kHttpVerbPOST);
        UploadHandlerRaw MyUploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(requestBody));

        webRequest.uploadHandler = MyUploadHandler;

        string returnString = VuforiaRequest(requestPath, httpAction, contentType, requestBody, webRequest);

        VtTargetSummary    newItem = new VtTargetSummary();
        VtUploadResultCode code    = JsonUtility.FromJson <VtUploadResultCode>(returnString);

        newItem.target_id = code.target_id;
        vtc.targetSummaryList.Add(newItem);
        UpdateTargetInformation(code.target_id);
        if (returnString == "fail")
        {
            return(false);
        }
        else
        {
            return(true);
        }
    }
コード例 #5
0
 public IActionResult AddPost([FromBody] JsonPost post)
 {
     _repository.AddPost(post);
     return(Json(post));
 }
コード例 #6
0
        public static bool AddnewReport(DateTime dt)
        {
            using (var context = new ControllerModel())
            {
                try
                {
                    var check = context.Reports.Where(o => o.datereport.Day == dt.Day &&
                                                      o.datereport.Month == dt.Month &&
                                                      o.datereport.Year == dt.Year).Count();

                    var amountofcustomers = context.Histories.Include("Customers").Where(o => o.dayadd.Day == dt.Day &&
                                                                                         o.dayadd.Month == dt.Month &&
                                                                                         o.dayadd.Year == dt.Year &&
                                                                                         o.Customers.available == true).Select(o => o.Customers).Distinct().ToList();

                    var newCustomer = context.Customers.Where(o => o.dayadd.Day == dt.Day &&
                                                              o.dayadd.Month == dt.Month &&
                                                              o.dayadd.Year == dt.Year && o.available == true).Count();

                    context.Histories.Where(o => o.dayadd.Day == dt.Day &&
                                            o.dayadd.Month == dt.Month &&
                                            o.dayadd.Year == dt.Year).ToList().ForEach(o => o.ischeck = true);

                    if (check == 0)
                    {
                        var report = new Reports
                        {
                            amountofactivecustomer = amountofcustomers.Count(),
                            amountofnewcustomer    = newCustomer,
                            serverreport           = false,
                            datereport             = dt,
                            dayadd    = DateTime.Now,
                            dayupdate = DateTime.Now
                        };

                        context.Reports.Add(report);

                        var listtype = TypeController.getList();
                        foreach (Types ty in listtype)
                        {
                            int count = 0;
                            var test  = amountofcustomers.Where(o => o.typeid == ty.typeid).ToList();
                            if (test.Count > 0)
                            {
                                count = test.Count();
                                var tr = new SNI.Models.TypesReports
                                {
                                    Types     = context.Types.Where(o => o.typeid == ty.typeid).FirstOrDefault(),
                                    Reports   = report,
                                    amounts   = count,
                                    dayadd    = DateTime.Now,
                                    dayupdate = DateTime.Now
                                };
                                context.TypesReports.Add(tr);
                            }
                        }
                        context.SaveChanges();
                    }
                    else
                    {
                        var report1 = context.Reports.Where(o => o.datereport.Day == dt.Day &&
                                                            o.datereport.Month == dt.Month &&
                                                            o.datereport.Year == dt.Year).FirstOrDefault();

                        report1.amountofactivecustomer = amountofcustomers.Count();
                        report1.amountofnewcustomer    = newCustomer;
                        report1.serverreport           = false;
                        report1.datereport             = dt;
                        report1.dayupdate = DateTime.Now;


                        var listtype = TypeController.getList();
                        foreach (Types ty in listtype)
                        {
                            int count = 0;
                            var test  = amountofcustomers.Where(o => o.typeid == ty.typeid).ToList();

                            if (test.Count > 0)
                            {
                                var check1 = context.TypesReports.Where(o => o.typeid == ty.typeid && o.reportid == report1.reportid).Count();
                                count = test.Count();

                                if (check1 == 0)
                                {
                                    var tr = new SNI.Models.TypesReports
                                    {
                                        Types     = context.Types.Where(o => o.typeid == ty.typeid).FirstOrDefault(),
                                        Reports   = report1,
                                        amounts   = count,
                                        dayadd    = DateTime.Now,
                                        dayupdate = DateTime.Now
                                    };
                                    context.TypesReports.Add(tr);
                                }
                                else
                                {
                                    var typer = context.TypesReports.Where(o => o.typeid == ty.typeid && o.reportid == report1.reportid).FirstOrDefault();
                                    typer.amounts = count;
                                }
                            }
                            else
                            {
                                var gettpyr = context.TypesReports.Where(o => o.typeid == ty.typeid && o.reportid == report1.reportid).FirstOrDefault();
                                if (gettpyr != null)
                                {
                                    context.TypesReports.Remove(gettpyr);
                                }
                            }
                        }
                        context.SaveChanges();
                    }
                    JsonPost.PostAPI(dt);
                    return(true);
                }
                catch (Exception ex)
                {
                    return(false);
                }
            }
        }