// [Route("api/sms/send")]
        //[HttpGet]
        //public async Task<IHttpActionResult> SendSms([FromUri]SmsContact contact)
        //{

        //    try
        //    {
        //        HttpClient smsSender = new HttpClient();

        //        if (!ModelState.IsValid)
        //        {
        //            return BadRequest("model state not valid");
        //        }
        //        var data = new
        //        {
        //            url = ConfigurationManager.AppSettings["SmsGatewayRequestUrl"],
        //            username = HttpUtility.UrlEncode(ConfigurationManager.AppSettings["SmsGatewayUser"]),
        //            password = HttpUtility.UrlEncode(ConfigurationManager.AppSettings["SmsGatewayPassword"]),
        //            type = HttpUtility.UrlEncode(ConfigurationManager.AppSettings["SmsGatewayRequestType"]),
        //            dlr = HttpUtility.UrlEncode(ConfigurationManager.AppSettings["SmsGatewayRequestDelivery"]),
        //            source = HttpUtility.UrlEncode(ConfigurationManager.AppSettings["SmsGatewayRequestSource"]),
        //            destination = HttpUtility.UrlEncode(String.Format("91{0}", contact.phone)),
        //            message = HttpUtility.UrlEncode(contact.message)
        //        };

        //        string encodedPostUrl = string.Format("{0}?username={1}&password={2}&type={3}&dlr={4}&destination={5}&source={6}&message={7}", data.url, data.username, data.password, data.type, data.dlr, data.destination, data.source, data.message);

        //        HttpResponseMessage responseMessage = await smsSender.PostAsync(encodedPostUrl, new StringContent(""));

        //        if (responseMessage.IsSuccessStatusCode)
        //        {
        //            string messageResponseString = await responseMessage.Content.ReadAsStringAsync();

        //            if (messageResponseString.Split('|')[0] == "1701")
        //            {
        //                return Ok(messageResponseString);
        //            }
        //            else
        //            {
        //                return BadRequest("Someting wrong happened. Response returned : " + messageResponseString);
        //            }
        //        }

        //    }
        //    catch (Exception ex)
        //    {
        //        BadRequest(ex.Message);
        //    }

        //    return Ok();
        //}


        public async Task <bool> SendSMS(SmsContact contact)
        {
            try
            {
                HttpClient smsSender = new HttpClient();

                if (!ModelState.IsValid)
                {
                    throw new Exception("Model is not valid");
                }
                var data = new
                {
                    url         = ConfigurationManager.AppSettings["SmsGatewayRequestUrl"],
                    username    = HttpUtility.UrlEncode(ConfigurationManager.AppSettings["SmsGatewayUser"]),
                    password    = HttpUtility.UrlEncode(ConfigurationManager.AppSettings["SmsGatewayPassword"]),
                    type        = HttpUtility.UrlEncode(ConfigurationManager.AppSettings["SmsGatewayRequestType"]),
                    dlr         = HttpUtility.UrlEncode(ConfigurationManager.AppSettings["SmsGatewayRequestDelivery"]),
                    source      = HttpUtility.UrlEncode(ConfigurationManager.AppSettings["SmsGatewayRequestSource"]),
                    destination = HttpUtility.UrlEncode(String.Format("91{0}", contact.phone)),
                    message     = HttpUtility.UrlEncode(contact.message)
                };

                string encodedPostUrl = string.Format("{0}?username={1}&password={2}&type={3}&dlr={4}&destination={5}&source={6}&message={7}", data.url, data.username, data.password, data.type, data.dlr, data.destination, data.source, data.message);

                HttpResponseMessage responseMessage = await smsSender.PostAsync(encodedPostUrl, new StringContent(""));;

                if (responseMessage.IsSuccessStatusCode)
                {
                    string messageResponseString = await responseMessage.Content.ReadAsStringAsync();

                    if (messageResponseString.Split('|')[0] == "1701")
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                BadRequest(ex.Message);
            }

            return(true);
        }
        public async Task <IHttpActionResult> Post([FromUri] CaseModel model)
        {
            if (!ModelState.IsValid)
            {
                throw new Exception("Invalid input values. Please send correct input.");
            }
            String transactionId = "";

            try
            {
                Case entity = new Case();
                entity.Id         = Guid.NewGuid().ToString();
                entity.Origins    = model.Origins;
                entity.Status     = model.Status;
                entity.Subject    = model.Subject;
                entity.SyncStatus = 0;
                entity.Timestamp  = DateTime.UtcNow;
                entity.DeviceId   = model.DeviceId;
                entity.MongoId    = Guid.NewGuid().ToString();
                //entity = await _repository.AddOrUpdateAsync(entity);
                entity = Repository.Add(entity);
                SmsContact con = new SmsContact();
                con.adminName  = "Ramandeep Singh";
                con.contactId  = "14251231";
                con.deviceName = "IoT";
                con.email      = "*****@*****.**";
                con.message    = entity.ToString();
                con.phone      = "8800220368";
                SendSMS(con).GetAwaiter().GetResult();

                transactionId = entity.Id;
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }


            return(Ok(new { transactionId = transactionId }));
        }