Exemplo n.º 1
0
 public List<ClientData> SearchFriends(ClientData client)
 {
     List<ClientData> friend;
     using (EmergencyDBEntities context = new EmergencyDBEntities())
     {
         friend = (from c in context.Clients
                   where c.FirstName.StartsWith(client.FirstName)
                   select new ClientData { Username = c.Username, FirstName = c.FirstName, LastName = c.LastName, Age = c.Age.Value, Email = c.Email }).ToList<ClientData>();
     }
     return friend;
 }
Exemplo n.º 2
0
        public List<string> SendSosNotifications(ClientData client)
        {
            using (EmergencyDBEntities context = new EmergencyDBEntities())
            {
                string notificationStatus = "";
                string notificationChannelStatus = "";
                string deviceConnectionStatus = "";

                var sender = (from c in context.Clients
                              where c.Username == client.Username
                              select c).FirstOrDefault();
                var clients = (from f in context.Friendships
                               join c in context.Clients
                               on f.FriendID equals c.ClientID
                               where f.ClientID == sender.ClientID
                               select c);
                foreach (var cl in clients)
                {
                    List<string> uriStrings;
                    using (EmergencyDBEntities context2 = new EmergencyDBEntities())
                    {
                        uriStrings = (from d in context2.Devices
                                      where d.ClientID == cl.ClientID
                                      select d.DeviceUrl).ToList<string>();
                    }
                    if (uriStrings.Count != 0)
                    {
                        foreach (var uriString in uriStrings)
                        {
                            Uri uri = new Uri(uriString);
                            byte[] payload = new byte[0];

                            var request = (HttpWebRequest)WebRequest.Create(uri);
                            request.Method = "POST";
                            request.ContentType = "text/xml";

                            payload = GetToastPayload("Emergency", sender.FirstName + " " + sender.LastName);
                            request.Headers.Add("X-WindowsPhone-Target", "toast");
                            request.Headers.Add("X-NotificationClass", "2");

                            request.ContentLength = payload.Length;

                            using (Stream requestStream = request.GetRequestStream())
                            {
                                requestStream.Write(payload, 0, payload.Length);
                            }

                            try
                            {
                                var response = (HttpWebResponse)request.GetResponse();
                                notificationStatus = response.Headers["X-NotificationStatus"];
                                notificationChannelStatus = response.Headers["X-SubscriptionStatus"];
                                deviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"];
                            }
                            catch (Exception ex) { }//return new List<string> { "Device is not connected!", ex.Message }; }
                        }
                    }
                }
                return new List<string> { notificationStatus, notificationChannelStatus, deviceConnectionStatus };
                //return new List<string> { "You don't have any friend." };
            }
        }
Exemplo n.º 3
0
 public string ClientRegistration(ClientData client, string password)
 {
     using (EmergencyDBEntities context = new EmergencyDBEntities())
     {
         if ((from c in context.Clients
              where c.Username == client.Username
              select c).FirstOrDefault() != null)
         { return "User with current username is already exist. Please choose another username."; }
         else if ((from c in context.Clients
                   where c.Email == client.Email
                   select c).FirstOrDefault() != null)
         { return "User with current email is already exist. Please enter another email address."; }
         else
         {
             context.Clients.AddObject(new Client { Username = client.Username, Password = password, Email = client.Email, FirstName = client.FirstName, LastName = client.LastName, Age = client.Age });
             context.SaveChanges();
             return "Your account is successfully registered.";
         }
     }
 }