Example #1
0
        // If ClientData IsNull New Up A new client Data

        public async Task <Client> UpdateBasicOffer(BasicOffer offer, string clientId)
        {
            // Get the client and the existing offer
            var client = await _clientRepository.GetClient(clientId);

            if (client.ClientData == null)
            {
                client.ClientData = new ClientData
                {
                    BasicOffers = new System.Collections.Generic.List <BasicOffer>()
                };
            }

            var existingOfferIndex = client?.ClientData?.BasicOffers.FindIndex(x => x.Id == offer.Id);

            if (!existingOfferIndex.HasValue || existingOfferIndex.Value == -1)
            {
                // No existing offer found, so add the new basic offer
                offer.Id = Guid.NewGuid().ToString();
                client.ClientData.BasicOffers.Add(offer);
            }
            else
            {
                // Replace the existing offer
                client.ClientData.BasicOffers[existingOfferIndex.Value] = offer;
            }
            var result = await _clientRepository.UpdateClient("ClientData.BasicOffers", client.ClientData.BasicOffers, client.Id);

            return(result);
        }
        public async Task <IActionResult> UpdateBasicOffer([FromBody] BasicOffer offer)
        {
            var client = await _clientService.GetClientByShortKey(Request.ClientKey());

            return(new OkObjectResult(await _basicOffersService.UpdateBasicOffer(offer, client.Id)));
        }