// PUT api/Customers/5
        public async Task<IHttpActionResult> PutCustomer(int id, Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != customer.CustomerId)
            {
                return BadRequest();
            }

            db.Entry(customer).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
 public IActionResult Customers(int id)
 {
     var customer = new Customer
     {
         Id = id,
         FirstName = "John",
         LastName = "Doe"
     };
     return Ok(customer);
 }
 public CustomerViewModel(Customer customer)
 {
     this.CustomerId = customer.CustomerId.ToString();
     this.Name = customer.Name;
     this.Phone = customer.Phone;
     this.Address = customer.Address;
     this.Email = customer.Email;
     this.Company = customer.Company;
     this.Title = customer.Title;
     this.ImagePath = string.IsNullOrEmpty(customer.Image) ? "/Assets/CustomerPlaceholder.png" : customer.Image;
 }
        public async Task<IHttpActionResult> PostCustomer(Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Customers.Add(customer);
            await db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = customer.CustomerId }, customer);
        }
        public static async void CreateCustomer(Customer customer)
        {
            object serviceUrl;
            App.Current.Resources.TryGetValue("ServiceUrl", out serviceUrl);

            using (HttpClient client = new HttpClient())
            {
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Customer));

                using (MemoryStream stream = new MemoryStream())
                {
                    serializer.WriteObject(stream, customer);
                    stream.Seek(0, SeekOrigin.Begin);

                    var json = new StreamReader(stream).ReadToEnd();

                    var response = await client.PostAsync(serviceUrl as string, new StringContent(json, Encoding.UTF8, "application/json"));
                    response.EnsureSuccessStatusCode();
                }
            }
        }
        private async Task SendNotificationAsync(Customer customer)
        {
            var connectionString = ConfigurationManager.AppSettings["HubConnectionString"];
            var notificationHub = ConfigurationManager.AppSettings["HubName"];
            NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(connectionString, notificationHub);

            var toast = "<toast>" +
                            "<visual>" +
                                "<binding template=\"ToastText02\">" +
                                    "<text id=\"1\">New customer added!</text>" +
                                    "<text id=\"2\">" + customer.Name + "</text>" +
                                "</binding>" +
                            "</visual>" +
                        "</toast>";

            await hub.SendWindowsNativeNotificationAsync(toast);
        }