Exemplo n.º 1
0
 public static async Task SaveBikeAsync(Models.Bike Bike)
 {
     try
     {
         Container c = m_cdb.GetContainer(DAL.COSMOS_CONTAINER, DAL.COSMOS_BIKE_TABLE);
         await c.ReplaceItemAsync <Models.Bike>(Bike, Bike.ID);
     }
     catch (Exception exError)
     { }
 }
Exemplo n.º 2
0
 public static async Task CreateBikeAsync(Models.Bike Bike)
 {
     try
     {
         Container c = m_cdb.GetContainer(DAL.COSMOS_CONTAINER, DAL.COSMOS_BIKE_TABLE);
         await c.CreateItemAsync <Models.Bike>(Bike);
     }
     catch (Exception ex)
     {
     }
 }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            switch (req.Method.ToString())
            {
            case "GET":
            {
                Models.Bike bk = new Models.Bike();
                try
                {
                    string strID        = req.Query["ID"];
                    string strPartition = req.Query["Partition"];
                    bk = await DAL.GetBikeByIDAsync(strID, strPartition);
                }
                catch (Exception exError)
                {
                    return(new StatusCodeResult(500));
                }

                return(new JsonResult(bk));
            }

            case "POST":
            {
                try
                {
                    string      strBody = await new StreamReader(req.Body).ReadToEndAsync();
                    Models.Bike bk      = JsonConvert.DeserializeObject <Models.Bike>(strBody);

                    if (bk.ID == null || bk.ID == string.Empty)
                    {
                        bk.ID = Guid.NewGuid().ToString();
                        await DAL.CreateBikeAsync(bk);
                    }
                    else
                    {
                        await DAL.SaveBikeAsync(bk);
                    }
                }
                catch (Exception exError)
                {
                    return(new StatusCodeResult(500));
                }

                break;
            }
            }

            return(new OkResult());
        }
Exemplo n.º 4
0
    public static async Task <Models.Bike> GetBikeByIDAsync(string ID, string Partition)
    {
        Models.Bike bkReturn = null;

        try
        {
            Container c = m_cdb.GetContainer(DAL.COSMOS_CONTAINER, DAL.COSMOS_BIKE_TABLE);

            bkReturn = await c.ReadItemAsync <Models.Bike>(ID, new PartitionKey(Partition));
        }
        catch (Exception ex)
        {
        }

        return(bkReturn);
    }