Exemplo n.º 1
0
        public async Task <IActionResult> CreateDocumentCondition(string id, [FromBody] ProductPromoCondition productPromoCondition)
        {
            ResponseObject responseobject = new ResponseObject();

            try
            {
                ProductPromo productPromo = await _adapter.GetDataById("PromoDatabase", "PromoCollection", id);

                if (productPromo.conditions == null)
                {
                    List <ProductPromoCondition> newList = new List <ProductPromoCondition>();
                    newList.Add(productPromoCondition);
                    productPromo.conditions = newList;
                }
                else
                {
                    productPromo.conditions.Add(productPromoCondition);
                }
                var result = await _adapter.CreateDocumentCondition("PromoDatabase", "PromoCollection", productPromo);

                responseobject.correlationalId = Guid.NewGuid().ToString();
                responseobject.statusCode      = 201;
                responseobject.statusReason    = "Created";
                responseobject.success         = true;
                return(StatusCode(StatusCodes.Status201Created, responseobject));
            }
            catch (Exception ex)
            {
                responseobject.correlationalId = Guid.NewGuid().ToString();
                responseobject.statusCode      = 400;
                responseobject.statusReason    = "Bad Request";
                responseobject.success         = false;
                return(StatusCode(StatusCodes.Status400BadRequest, responseobject));
            }
        }
        public async Task <JsonResult> CreateDocument([FromBody] ProductPromo productpromo)
        {
            await _adapter.CreateDocument("PromoService", "ProductPromo", productpromo);

            return(new JsonResult(productpromo));
            // return Ok(result);
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "v1/promotions/{id}/conditions/all")] HttpRequestMessage req,
            [CosmosDB(
                 databaseName: "PromoDatabase",
                 collectionName: "PromoCollection",
                 ConnectionStringSetting = "CosmosDBConnection",
                 Id = "{id}")
            ] ProductPromo productpromo,
            ILogger log)
        {
            ResponseObject responseobject = new ResponseObject();

            // var headers = req.Headers;

            try
            {
                responseobject.correlationalId = Guid.NewGuid().ToString();
                responseobject.statusCode      = 200;
                responseobject.statusReason    = "OK";
                responseobject.success         = true;
                var result = productpromo.conditions;
                responseobject.conditions = result;
                return(new OkObjectResult(responseobject));
            }
            catch (Exception ex)
            {
                responseobject.correlationalId = Guid.NewGuid().ToString();
                responseobject.statusCode      = 500;
                responseobject.statusReason    = "Internal Server Error";
                responseobject.success         = false;
                return(new OkObjectResult(responseobject));
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> CreateDocument([FromBody] ProductPromo productpromo)
        {
            ResponseObject responseobject = new ResponseObject();

            try
            {
                var result = await _adapter.CreateDocument("PromoDatabase", "PromoCollection", productpromo);

                productpromo = result;
                responseobject.correlationalId = Guid.NewGuid().ToString();
                responseobject.statusCode      = 201;
                responseobject.statusReason    = "Created";
                responseobject.success         = true;
                responseobject.promotionId     = result.Id;
                return(StatusCode(StatusCodes.Status201Created, responseobject));
            }
            catch (Exception ex)
            {
                responseobject.correlationalId = Guid.NewGuid().ToString();
                responseobject.statusCode      = 400;
                responseobject.statusReason    = "Bad Request";
                responseobject.success         = false;
                return(StatusCode(StatusCodes.Status400BadRequest, responseobject));
            }
        }
        public async Task <IActionResult> Get(string id)
        {
            ResponseObject responseobject = new ResponseObject();

            try
            {
                var result = await _adapter.GetDataById("PromoDatabase", "PromoCollection", id);

                productpromo = result;
                responseobject.correlationalId = Guid.NewGuid().ToString();
                responseobject.statusCode      = 200;
                responseobject.statusReason    = "OK";
                responseobject.success         = true;

                responseobject.promotion = productpromo;
                return(Ok(responseobject));
            }
            catch (Exception ex)
            {
                // ResponseObject responseobject = new ResponseObject();
                responseobject.correlationalId = Guid.NewGuid().ToString();
                responseobject.statusCode      = 500;
                responseobject.statusReason    = "Internal Server Error";
                responseobject.success         = false;

                return(StatusCode(StatusCodes.Status500InternalServerError, responseobject));
            }
        }
Exemplo n.º 6
0
        public async Task <dynamic> GetData(string dbName, string name)
        {
            try
            {
                var response = await _client.ReadDocumentFeedAsync(UriFactory.CreateDocumentCollectionUri(dbName, name), new FeedOptions { MaxItemCount = 10 });

                //var x = response.ElementAt<ProductPromo>(0);
                //ProductPromo productpro = (ProductPromo)(dynamic)response.l;
                // var response = await _client.ReadDocumentFeedAsync()
                List <ProductPromo> productproList = new List <ProductPromo>();
                //(ProductPromo)(dynamic)response.Resource;


                foreach (Document doc in response)
                {
                    ProductPromo productpro = (ProductPromo)(dynamic)doc;
                    productproList.Add(productpro);
                }
                return(productproList);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public async Task <IActionResult> GetCondition(string id)
        {
            ProductPromo promo = await _adapter.GetDataById("PromoDatabase", "PromoCollection", id);

            var result = promo.conditions;

            return(Ok(result));
        }
        public async Task <IActionResult> GetConditionByIndex(string id, int index)
        {
            ProductPromo promo = await _adapter.GetDataById("PromoDatabase", "PromoCollection", id);

            var result = promo.conditions.ElementAt(index);

            return(Ok(result));
        }
        public async Task <bool> CreateDocument(string dbName, string name, ProductPromo productpromo)
        {
            await _client.CreateDocumentCollectionIfNotExistsAsync
                (UriFactory.CreateDatabaseUri(dbName), new DocumentCollection { Id = name });


            throw new NotImplementedException();
        }
        public static HttpResponseMessage Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "v1/promotions/{id}/conditions")] HttpRequestMessage req,
            [CosmosDB(
                 databaseName: "PromoDatabase",
                 collectionName: "PromoCollection",
                 ConnectionStringSetting = "CosmosDBConnection",
                 Id = "{id}")



            ]
            ProductPromo productPromo,
            ILogger log)
        {
            ResponseObject responseobject = new ResponseObject();
            // ProductPromoCondition productPromoCondition = new ProductPromoCondition();
            var     content     = req.Content;
            string  jsonContent = content.ReadAsStringAsync().Result;
            dynamic condition   = JsonConvert.DeserializeObject <ProductPromoCondition>(jsonContent);



            try
            {
                if (productPromo.conditions == null)
                {
                    List <ProductPromoCondition> newList = new List <ProductPromoCondition>();
                    newList.Add(condition);
                    productPromo.conditions = newList;
                }
                else
                {
                    productPromo.conditions.Add(condition);
                }



                responseobject.correlationalId = Guid.NewGuid().ToString();
                responseobject.statusCode      = 201;
                responseobject.statusReason    = "Created";
                responseobject.success         = true;
                return(new HttpResponseMessage(HttpStatusCode.Created)
                {
                    Content = new StringContent(responseobject.ToString(), Encoding.UTF8, "application/json")
                });
            }
            catch (Exception ex)
            {
                responseobject.correlationalId = Guid.NewGuid().ToString();
                responseobject.statusCode      = 400;
                responseobject.statusReason    = "Bad Request";
                responseobject.success         = false;
                return(new HttpResponseMessage(HttpStatusCode.Created)
                {
                    Content = new StringContent(responseobject.ToString(), Encoding.UTF8, "application/json")
                });
            }
        }
        public async Task <IActionResult> DeleteConditions(string id)
        {
            ProductPromo promo = await _adapter.GetDataById("PromoDatabase", "PromoCollection", id);

            promo.conditions.Clear();
            var result = await _adapter.UpdateDocumentAsyncCon("PromoDatabase", "PromoCollection", promo);

            return(Ok(result));
        }
        public async Task <IActionResult> CreateDocumentCondition(string id, [FromBody] ProductPromoCondition productPromoCondition)
        {
            ProductPromo productPromo = await _adapter.GetDataById("PromoDatabase", "PromoCollection", id);

            productPromo.conditions.Add(productPromoCondition);
            var result = await _adapter.CreateDocumentCondition("PromoDatabase", "PromoCollection", productPromo);

            return(Ok(result));
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "v1/promotions/{id}/conditions")] HttpRequestMessage req, HttpRequest request,
            [CosmosDB(
                 databaseName: "PromoDatabase",
                 collectionName: "PromoCollection",
                 ConnectionStringSetting = "CosmosDBConnection",
                 Id = "{id}")
            ] ProductPromo productpromo,
            ILogger log)



        {
            ResponseObject responseobject = new ResponseObject();
            var            headers        = req.Headers;
            var            query          = request.Query;

            try
            {
                List <ProductPromoCondition> productPromoCondition = productpromo.conditions;
                string indexValue = "";
                if (query.ContainsKey("indexes"))
                {
                    indexValue = query["indexes"].First();
                    string[] indexValuesArray = indexValue.Split(",");
                    foreach (var item in productPromoCondition.ToList())
                    {
                        bool present = indexValuesArray.Contains(item.index);
                        if (present)
                        {
                            productPromoCondition.Remove(item);
                        }
                    }
                }



                responseobject.correlationalId = Guid.NewGuid().ToString();
                responseobject.statusCode      = 201;
                responseobject.statusReason    = "Accepted";
                responseobject.success         = true;

                return(new OkObjectResult(responseobject)

                       /* {
                        *   //StatusCode = new StringContent(responseobject.ToString(), Encoding.UTF8, "application/json")
                        * }*/);
            }
            catch (Exception ex)
            {
                responseobject.correlationalId = Guid.NewGuid().ToString();
                responseobject.statusCode      = 500;
                responseobject.statusReason    = "Internal Server Error";
                responseobject.success         = false;
                return(new OkObjectResult(responseobject));
            }
        }
Exemplo n.º 14
0
        public async Task <IActionResult> CreateActions(string id, [FromBody] ProductPromoAction productPromoAction)
        {
            ProductPromo productPromo = await _adapter.GetDataById("PromoDatabase", "PromoCollection", id);

            productPromo.actions = productPromoAction;
            var result = await _adapter.CreateAction("PromoDatabase", "PromoCollection", productPromo);

            return(Ok(result));
        }
Exemplo n.º 15
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "promotion/{id}")] HttpRequestMessage req,
            [CosmosDB(
                 databaseName: "PromoDatabase",
                 collectionName: "PromoCollection",
                 ConnectionStringSetting = "CosmosDBConnection",
                 Id = "{id}")
            ] ProductPromo productpromo,
            ILogger log)
        {
            ResponseObject responseobject = new ResponseObject();
            var            header         = req.Headers;

            if (header.Contains("tenant"))
            {
                string value = header.GetValues("tenant").First();
                if (value.Equals("dcp"))
                {
                    log.LogInformation($"Function triggered");


                    try
                    {
                        // productpromo = result;
                        responseobject.correlationalId = Guid.NewGuid().ToString();
                        responseobject.statusCode      = 200;
                        responseobject.statusReason    = "OK";
                        responseobject.success         = true;

                        responseobject.promotion = productpromo;
                        return(new OkObjectResult(responseobject)

                               /* {
                                *   //StatusCode = new StringContent(responseobject.ToString(), Encoding.UTF8, "application/json")
                                * }*/);
                    }
                    catch (Exception ex)
                    {
                        responseobject.correlationalId = Guid.NewGuid().ToString();
                        responseobject.statusCode      = 500;
                        responseobject.statusReason    = "Internal Server Error";
                        responseobject.success         = false;
                        return(new OkObjectResult(responseobject));
                    }
                }
                else
                {
                    return(new OkObjectResult(responseobject));
                }
            }
            else
            {
                return(new OkObjectResult(responseobject));
            }
        }
Exemplo n.º 16
0
        // var response = await client.ReadDocumentAsync(UriFactory.CreateDocumentUri(databaseId, collectionId, "POCO1"));



        public async Task <dynamic> GetDataById(string dbName, string name, string id)
        {
            try {
                ResourceResponse <Document> response = await _client.ReadDocumentAsync(UriFactory.CreateDocumentUri(dbName, name, id));

                ProductPromo productpro = (ProductPromo)(dynamic)response.Resource;

                return(productpro);
            }
            catch (Exception ex) {
                return(false);
            }
        }
Exemplo n.º 17
0
        public async Task <bool> CreateAction(string dbName, string name, ProductPromo productPromo)
        {
            try
            {
                await _client.UpsertDocumentAsync(UriFactory.CreateDocumentCollectionUri(dbName, name), productPromo);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 18
0
        /* public async Task<bool> CreateDatabase(string name)
         * {
         *   try
         *   {
         *       await _client.CreateDatabaseIfNotExistsAsync(new Database { Id = name });
         *       return true;
         *   }
         *   catch (Exception ex)
         *   {
         *       return false;
         *   }
         * }
         *
         *
         * public async Task<bool> CreateCollection(string dbName, string name)
         * {
         *   try
         *   {
         *       await _client.CreateDocumentCollectionIfNotExistsAsync
         *        (UriFactory.CreateDatabaseUri(dbName), new DocumentCollection { Id = name });
         *       return true;
         *   }
         *   catch
         *   {
         *       return false;
         *   }
         * }
         *
         */
        public async Task <ProductPromo> CreateDocument(string dbName, string name, ProductPromo productpromo)
        {
            try
            {
                var result = await _client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(dbName, name), productpromo);

                return((dynamic)result.Resource);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 19
0
        public async Task <bool> CreateDocument(string dbName, string name, ProductPromo productpromo)
        {
            try
            {
                // productpromo.Id = "d9e51c1e-1474-41d1-8f32-96deedd8f36a";
                await _client.UpsertDocumentAsync(UriFactory.CreateDocumentCollectionUri(dbName, name), productpromo);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 20
0
        public async Task <bool> CreateDocument(string dbName, string name, ProductPromo productpromo)
        {
            try
            {
                //userInfo.id = "d9e51c1e-1474-41d1-8f32-96deedd8f36a";
                await _client.UpsertDocumentAsync(UriFactory.CreateDocumentCollectionUri(dbName, name), productpromo);

                // resposecode.statusReason = HttpStatusCode.OK();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public static HttpResponseMessage Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "v1/promotions")] HttpRequestMessage req,
            [CosmosDB(
                 databaseName: "PromoDatabase",
                 collectionName: "PromoCollection",
                 ConnectionStringSetting = "CosmosDBConnection")]
            out ProductPromo document,
            ILogger log)
        {
            ResponseObject responseobject = new ResponseObject();
            var            content        = req.Content;
            string         jsonContent    = content.ReadAsStringAsync().Result;

            document = JsonConvert.DeserializeObject <ProductPromo>(jsonContent);

            /*var header = req.Headers;
             * if (header.Contains("tenant"))
             * {
             *  string value = header.GetValues("tenant").First();
             *  if (value.Equals("dcp"))
             *  {*/

            try
            {
                responseobject.correlationalId = Guid.NewGuid().ToString();
                responseobject.statusCode      = 201;
                responseobject.statusReason    = "Created";
                responseobject.success         = true;
                responseobject.promotionId     = document.Id;

                return(new HttpResponseMessage(HttpStatusCode.Created)
                {
                    Content = new StringContent(responseobject.ToString(), Encoding.UTF8, "application/json")
                });
            }
            catch (Exception ex)
            {
                responseobject.correlationalId = Guid.NewGuid().ToString();
                responseobject.statusCode      = 400;
                responseobject.statusReason    = "Bad Request";
                responseobject.success         = false;
                return(new HttpResponseMessage(HttpStatusCode.Created)
                {
                    Content = new StringContent(responseobject.ToString(), Encoding.UTF8, "application/json")
                });
            }
        }
Exemplo n.º 22
0
        public async Task <bool> UpdateDocumentAsyncCon(string dbName, string name, ProductPromo productPromoCondition)
        {
            try
            {
                //  await _client.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(dbName, name,productPromoCondition.Id), productPromoCondition);



                await _client.UpsertDocumentAsync(UriFactory.CreateDocumentCollectionUri(dbName, name), productPromoCondition);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        // var response = await client.ReadDocumentAsync(UriFactory.CreateDocumentUri(databaseId, collectionId, "POCO1"));



        public async Task <dynamic> GetDataById(string dbName, string name, string id)
        {
            try
            {
                //Console.Write("string value", dbName);
                //ResourceResponse<Document> result = await _client.ReadDocumentAsync));
                // new FeedOptions { MaxItemCount = 10 });
                var response = await _client.ReadDocumentAsync(UriFactory.CreateDocumentUri(dbName, name, id));

                // Console.Write("printing response", response);

                ProductPromo productpro = (ProductPromo)(dynamic)response.CurrentResourceQuotaUsage;
                return(productpro);
            }
            catch (Exception ex)
            {
                return("failed");
            }
        }
Exemplo n.º 24
0
        public async Task <IActionResult> DeleteConditionsByIndex(string id)
        {
            ResponseObject responseobject = new ResponseObject();

            try
            {
                ProductPromo promo = await _adapter.GetDataById("PromoDatabase", "PromoCollection", id);

                List <ProductPromoCondition> productPromoConditionObj = promo.conditions;
                string indexValue = "";
                if (Request.Headers.ContainsKey("indexes"))
                {
                    indexValue = Request.Headers["indexes"].First();
                    string[] indexValuesArray = indexValue.Split(",");
                    foreach (var item in productPromoConditionObj.ToList())
                    {
                        bool present = indexValuesArray.Contains(item.index);
                        if (present)
                        {
                            productPromoConditionObj.Remove(item);
                        }
                    }
                }
                var result = await _adapter.UpdateDocumentAsyncCon("PromoDatabase", "PromoCollection", promo);

                responseobject.correlationalId = Guid.NewGuid().ToString();
                responseobject.statusCode      = 200;
                responseobject.statusReason    = "OK";
                responseobject.success         = true;
                return(Ok(responseobject));
            }
            catch (Exception ex)
            {
                responseobject.correlationalId = Guid.NewGuid().ToString();
                responseobject.statusCode      = 500;
                responseobject.statusReason    = "Internal Server Error";
                responseobject.success         = false;
                return(StatusCode(StatusCodes.Status500InternalServerError, responseobject));
            }
        }
        public async Task <IActionResult> UpdateConditions(int index, string id, [FromBody] ProductPromoCondition productPromoCondition)
        {
            ProductPromo promo = await _adapter.GetDataById("PromoDatabase", "PromoCollection", id);

            var productPromoConditionInstance = promo.conditions.ElementAt(index);

            if (productPromoConditionInstance != null)
            {
                // productPromoConditionInstance.index = productPromoCondition.index;
                productPromoConditionInstance.parameter      = productPromoCondition.parameter;
                productPromoConditionInstance.promoOperator  = productPromoCondition.promoOperator;
                productPromoConditionInstance.conditionValue = productPromoCondition.conditionValue;
                productPromoConditionInstance.otherValue     = productPromoCondition.otherValue;
            }
            else
            {
                return(NotFound());
            }
            var result = await _adapter.UpdateDocumentAsyncCon("PromoDatabase", "PromoCollection", promo);

            return(Ok(result));
        }
Exemplo n.º 26
0
        public async Task <IActionResult> UpdateConditions(string index, string id, [FromBody] ProductPromoCondition productPromoCondition)
        {
            ResponseObject responseobject = new ResponseObject();

            try
            {
                ProductPromo promo = await _adapter.GetDataById("PromoDatabase", "PromoCollection", id);

                List <ProductPromoCondition> productPromoConditionObj = promo.conditions;
                foreach (var item in productPromoConditionObj)
                {
                    if (item.index == index)
                    {
                        item.parameter      = productPromoCondition.parameter;
                        item.promoOperator  = productPromoCondition.promoOperator;
                        item.conditionValue = productPromoCondition.conditionValue;
                        item.otherValue     = productPromoCondition.otherValue;
                    }
                }
                var result = await _adapter.UpdateDocumentAsyncCon("PromoDatabase", "PromoCollection", promo);

                responseobject.correlationalId = Guid.NewGuid().ToString();
                responseobject.statusCode      = 202;
                responseobject.statusReason    = "Accepted";
                responseobject.success         = true;
                // responseobject.promotionId = result.Id;
                return(StatusCode(StatusCodes.Status202Accepted, responseobject));
            }
            catch (Exception ex)
            {
                responseobject.correlationalId = Guid.NewGuid().ToString();
                responseobject.statusCode      = 400;
                responseobject.statusReason    = "Bad Request";
                responseobject.success         = false;
                return(StatusCode(StatusCodes.Status400BadRequest, responseobject));
            }
        }
Exemplo n.º 27
0
        public async Task <IActionResult> UpdateActions(string id, [FromBody] ProductPromoAction productPromoAction)
        {
            ProductPromo promo = await _adapter.GetDataById("PromoDatabase", "PromoCollection", id);

            var productPromoActionInstance = promo.actions;



            if (productPromoActionInstance != null)
            {
                productPromoActionInstance.type      = productPromoAction.type;
                productPromoActionInstance.quantity  = productPromoAction.quantity;
                productPromoActionInstance.amount    = productPromoAction.amount;
                productPromoActionInstance.productId = productPromoAction.productId;
                productPromoActionInstance.catalogId = productPromoAction.catalogId;
            }
            else
            {
                return(NotFound());
            }
            var result = await _adapter.UpdateActionDocumentAsync("PromoDatabase", "PromoCollection", promo);

            return(Ok(result));
        }
Exemplo n.º 28
0
        public async Task <bool> updateDocumentAsyncResponse(string dbName, string name, ProductPromo promo)
        {
            try
            {
                var collectionUri = UriFactory.CreateDocumentUri(dbName, name, promo.Id);

                var result = await _client.DeleteDocumentAsync(collectionUri);

                return((dynamic)result.Resource);
            }
            catch (DocumentClientException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
            {
                return(false);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <IActionResult> Update([FromBody] ProductPromo productpromo)
        {
            var result = await _adapter.updateDocumentAsync("PromoDatabase", "PromoCollection", productpromo);

            return(Ok(result));
        }
Exemplo n.º 30
0
        public async Task <ProductPromo> updateDocumentAsync(string dbName, string name, ProductPromo productpromo)
        {
            try
            {
                var response = await _client.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(dbName, name, productpromo.Id), productpromo);

                return((dynamic)response.Resource);
            }
            catch
            {
                return(null);
            }
        }