Esempio n. 1
0
        public ComposeMessage(MessageEntity message)
        {
            Type      = message.MessageType;
            StartTime = message.StartTime;
            EndTime   = message.EndTime;
            Title     = message.Title;
            Body      = message.Body;
            To        = "";
            // get all the devices included that haven't received the message yet
            var devices = message.DeviceMessages.Where(x => x.DeliveryTime == null).Select(x => x.Device).ToList();

            // get all the locations where all of the devices are included
            var locations =
                devices.Select(x => x.Location).Distinct().ToList().Where(x => x.Devices.All(y => devices.Contains(y))).ToList();

            devices = devices.Except(locations.SelectMany(x => x.Devices)).ToList();

            // get all the organizations where all of the locations are included
            var organizations =
                locations.Select(x => x.Organization).Distinct().ToList().Where(x => x.Locations.All(y => locations.Contains(y))).ToList();

            locations = locations.Except(organizations.SelectMany(x => x.Locations)).ToList();

            // loop through each entity and add it to the to address
            foreach (var entity in ((IEnumerable <CommonEntityBase>)devices).Concat(locations).Concat(organizations))
            {
                To += (To != "" ? ", " : "") + MessageValidationAttribute.GetId(entity);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Filters out the To addresses based on user permissions and the search term typed in by the user.
 /// </summary>
 /// <param name="term"></param>
 /// <returns></returns>
 private IEnumerable <dynamic> GetTosInternal(string term)
 {
     // loop through all entities and filter based on the type and if it contains the term.
     foreach (var recipient in ComposeMessage.Entities)
     {
         var device = recipient as DeviceEntity;
         if (device != null)
         {
             var label = String.Format(Message.DeviceFormat, SharedRes.Formats.Device.FormatWith(device));
             if (label.IndexOf(term, StringComparison.OrdinalIgnoreCase) > -1)
             {
                 yield return new
                        {
                            value = MessageValidationAttribute.GetId(device),
                            label
                        }
             }
             ;
         }
         var location = recipient as LocationEntity;
         if (location != null && location.Name.IndexOf(term, StringComparison.OrdinalIgnoreCase) > -1)
         {
             yield return new
                    {
                        value = MessageValidationAttribute.GetId(location),
                        label = String.Format(Message.LocationFormat, location.Name)
                    }
         }
         ;
         var organization = recipient as OrganizationEntity;
         if (organization != null && organization.Name.IndexOf(term, StringComparison.OrdinalIgnoreCase) > -1)
         {
             yield return new
                    {
                        value = MessageValidationAttribute.GetId(organization),
                        label = String.Format(Message.OrganizationFormat, organization.Name)
                    }
         }
         ;
     }
 }