コード例 #1
0
ファイル: DBUtil.cs プロジェクト: jessegoraya/FunctionTaskApp
        public GroupTaskSet GetGroupTaskSetByID(string id)
        {
            var option = new FeedOptions {
                EnableCrossPartitionQuery = true
            };

            dynamic doc = Client.CreateDocumentQuery <Document>(CollectionLink, option)
                          .Where(x => x.Id == id).AsEnumerable().FirstOrDefault();

            GroupTaskSet convertedGTS = null;

            if (doc != null)
            {
                convertedGTS = doc;
            }

            return(convertedGTS);
        }
コード例 #2
0
ファイル: DBUtil.cs プロジェクト: jessegoraya/FunctionTaskApp
        /*
         *
         * [AcceptVerbs("GET")]
         * [HttpGet]
         * public async Task<List<Models.Person>> GetActivePeopleByTenantandAppandType(string tenant, string appname, string objecttype)
         * {
         *  var query = from doc in Client.CreateDocumentQuery<Models.Person>(CollectionLink)
         *              where (doc.Tenant == tenant) && (doc.App == appname) && (doc.Type == objecttype)
         *              select doc;
         *
         *  var people = await QueryPeople(query);
         *
         *  List<Person.Models.Person> convertedPeople = people.ToList();
         *
         *  return convertedPeople;
         *
         * }
         *
         * [AcceptVerbs("GET")]
         * [HttpGet]
         * public async Task<List<Models.Person>> GetPeronsByName(string tenant, string appname, string objecttype, string Name)
         * {
         *
         *  //if the entity returned by Luis contains 2 names then split the name so that a query is done by first and last name
         *  if (Name.Contains(' ') == true)
         *  {
         *      string[] names = Name.Split(' ');
         *      var query = from doc in Client.CreateDocumentQuery<Models.Person>(CollectionLink)
         *                  where (doc.Tenant == tenant) && (doc.App == appname) && (doc.Type == objecttype) && (doc.FName == names[0]) && (doc.LastName == names[1])
         *                  select doc;
         *
         *      var people = await QueryPeople(query);
         *      List<Person.Models.Person> convertedPeople = people.ToList();
         *
         *      return convertedPeople;
         *  }
         *  else
         *  //if the entity returned by LUIS contains only 1 name then search the last name
         *  {
         *      var query = from doc in Client.CreateDocumentQuery<Models.Person>(CollectionLink)
         *                  where (doc.Tenant == tenant) && (doc.App == appname) && (doc.Type == objecttype) && (doc.LastName == Name)
         *                  select doc;
         *
         *      var people = await QueryPeople(query);
         *      List<Person.Models.Person> convertedPeople = people.ToList();
         *
         *      return convertedPeople;
         *  }
         *
         *
         * } */

        //private static async Task<IEnumerable<Person>> QueryPeople<Person>(IQueryable<Person> query)
        //{
        //    //this was added to support GetActivePeopleByTenantandAppandType method so that query can be done asynchronously
        //    var docQuery = query.AsDocumentQuery();
        //    var batches = new List<IEnumerable<Person>>();

        //    do
        //    {
        //        var batch = await docQuery.ExecuteNextAsync<Person>();
        //        batches.Add(batch);
        //    }

        //    while (docQuery.HasMoreResults);

        //    var docs = batches.SelectMany(b => b);
        //    return docs;
        //}


        public async Task <Boolean> UpdateGTSById(GroupTaskSet updatedGTS)
        {
            try
            {
                Boolean result = false;
                string  id     = updatedGTS.id;
                var     option = new FeedOptions {
                    EnableCrossPartitionQuery = true
                };

                dynamic doc = Client.CreateDocumentQuery <Document>(CollectionLink, option)
                              .Where(d => d.Id == id).AsEnumerable().FirstOrDefault();

                if (doc != null)
                {
                    ResourceResponse <Document> x = await Client.ReplaceDocumentAsync(doc.SelfLink, updatedGTS);

                    if (x.StatusCode.ToString() == "OK")
                    {
                        result = true;
                    }
                    else
                    {
                        result = false;
                    }
                }
                else
                {
                    result = false;
                }

                return(result);
            }
            catch (Exception e)
            {
                Boolean errResult = false;
                return(errResult);
            }
        }
コード例 #3
0
ファイル: DBUtil.cs プロジェクト: jessegoraya/FunctionTaskApp
        public async Task <Document> CreateGroupTaskSet(GroupTaskSet gts)
        {
            ResourceResponse <Document> doc = await Client.CreateDocumentAsync(CollectionLink, gts);

            return(doc);
        }
コード例 #4
0
        public static async Task <IActionResult> RunCreateGroupTaskAsync(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {   //create the post request to create the Case Tasks.  So send in new Case Task.
            //get send group task workflow  JSON from body
            string  requestBody = new StreamReader(req.Body).ReadToEnd();
            dynamic data        = JsonConvert.DeserializeObject <GroupTask>(requestBody);

            //get input variables for query variable or header to say the tenant and the
            string id = req.Query["id"];

            id = id ?? data?.id;

            //Document retDoc;

            if ((id != null))
            {
                try
                {
                    using (var client = new HttpClient())
                    {
                        //get the group task set where you will be inserting your new GT
                        DBUtil       dbRepo = new DBUtil();
                        GroupTaskSet gts    = dbRepo.GetGroupTaskSetByID(id);

                        //extract the new GT from the JSON
                        //GroupTaskSet newGTS = new GroupTaskSet();
                        //newGTS = data;


                        GroupTask newGT = new GroupTask();
                        newGT = data;
                        //newGT = newGTS.grouptask[0];

                        //set new IDs for Group Task, Invidivudal Task Set (if any), and Individual Tasks (if any)
                        SvcUtil util = new SvcUtil();
                        newGT = util.SetNewIDs(newGT);
                        //add new GT to host GTS

                        gts.grouptask.Add(newGT);

                        try
                        {
                            //update the GTS in DB with new GT
                            Boolean result = await dbRepo.UpdateGTSById(gts);

                            if (result == true)
                            {
                                return(new OkObjectResult(gts));
                            }
                        }
                        catch (Exception)
                        {
                            return((ActionResult) new BadRequestResult());
                        }

                        return((ActionResult) new BadRequestResult());
                    }
                }
                catch (Exception)


                {
                    //create a test if something goes wrong with the request to Cosmos
                    return((ActionResult) new BadRequestResult());
                }
            }
            else
            {
                //create a test if eiter tenant and customer are not provided
                return((ActionResult) new BadRequestResult());
            }
        }
コード例 #5
0
        public static async Task <IActionResult> RunCreateGroupTaskSetAsync(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            //create the post request to create the Case Tasks

            //get send group task workflow  JSON from body
            string  requestBody = new StreamReader(req.Body).ReadToEnd();
            dynamic data        = JsonConvert.DeserializeObject <GroupTaskSet>(requestBody);

            //get input variables for query variable or header to say the tenant and the
            string tenant = req.Query["tenant"];

            tenant = tenant ?? data?.tenantid;

            string caseid = req.Query["caseid"];

            caseid = caseid ?? data.caseid;

            Document retDoc;

            if ((tenant != null) && (caseid != null))
            {
                try
                {
                    using (var client = new HttpClient())
                    {
                        //extract the new GT from the JSON
                        GroupTaskSet newGTS = new GroupTaskSet();
                        newGTS = data;
                        GroupTask newGT = new GroupTask();
                        newGT = newGTS.grouptask[0];

                        //set new IDs for Group Task, Invidivudal Task Set (if any), and Individual Tasks (if any)
                        SvcUtil util = new SvcUtil();
                        newGT = util.SetNewIDs(newGT);

                        //add new GTS with new IDS to DB
                        DBUtil dbRepo = new DBUtil();
                        retDoc = await dbRepo.CreateGroupTaskSet(newGTS);

                        //return results
                        if (retDoc.Id != null)
                        {
                            //If the passed Case ID DOES NOT exist then create a new Group Task Set with its first Group Task
                            //create a test if tenant and customer are provided and JSON formated as GTS
                            return(new OkObjectResult(retDoc));
                        }
                        else
                        {
                            //create a test if tenant and customer are provided and JSON provided is not GTS
                            return((ActionResult) new BadRequestResult());
                        }
                    }
                }
                catch (Exception)
                {
                    //create a test if something goes wrong with the request to Cosmos
                    return((ActionResult) new BadRequestResult());
                }
            }
            else
            {
                //create a test if eiter tenant and customer are not provided
                return((ActionResult) new BadRequestResult());
            }
        }