internal static DeviceResponse SaveDevice(NewDevice device)
 {
     DeviceResponse dr=new DeviceResponse();
     var dev = repo.Select<Device>().Where(k => k.DevicePhoneNumber == device.DevicePhoneNumber);
     var count = dev.Any();
     if(count)
     {
         dr.Status = false;
         dr.StatusMessage = "Phone number already exist";
         dr.Device = dev.FirstOrDefault();
     }
     else
     {
         repo.Insert(new Device {DevicePhoneNumber = device.DevicePhoneNumber, DeviceToken = device.DeviceToken});
         dr.Status = true;
         dr.StatusMessage = "Saved";
         dr.Device = dev.FirstOrDefault();
     }
     return dr;
 }
        // POST api/Devices
        public HttpResponseMessage PostDevice(NewDevice device)
        {
            if (ModelState.IsValid)
            {
               DeviceResponse dr= DeviceLogic.SaveDevice(device);

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, dr);
                //response.Headers.Location = new Uri(Url.Link("DefaultApi", new DeviceResponse { Status=true,StatusMessage = "Saved"}));
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
        public HttpResponseMessage PutDevice(NewDevice device)
        {
            if (ModelState.IsValid)
            {
               DeviceResponse dr= DeviceLogic.UpdateDevice(device);

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created,dr);
                response.Headers.Add("Access-Control-Allow-Origin", "*");
                // response.Headers.Location = new Uri(Url.Link("DefaultApi", new DeviceResponse { Status = true, StatusMessage = "Updated" }));
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
 internal static DeviceResponse UpdateDevice(NewDevice device)
 {
     var dev = repo.Select<Device>().FirstOrDefault(k => k.DevicePhoneNumber == device.DevicePhoneNumber);
     DeviceResponse dr=new DeviceResponse();
     if (dev != null)
     {
         dev.DeviceToken = device.DeviceToken;
         repo.Update(dev);
         dr.Status = true;
         dr.StatusMessage = "Updated";
         dr.Device = dev;
     }
     else
     {
         dr.Status = false;
         dr.StatusMessage = "Device not found";
         dr.Device=new Device();
     }
     return dr;
 }