Example #1
0
        /// <summary>
        /// Fetch child records
        /// </summary>
        public async void GetChildRecords()
        {
            int addedBy;

            if (ChildRecords.Any())
            {
                ChildRecords.Clear();
            }

            var initialChildRecords = new List <ChildRecord>();

            if (Application.Current.Properties.ContainsKey("UserID"))
            {
                var isSuccess = int.TryParse(Application.Current.Properties["UserID"].ToString(), out addedBy);
                if (isSuccess)
                {
                    var childRecords        = (_studentService.GetStudentsByOfflineID(addedBy));
                    var testRecords         = (_clinicalTestFormService.GetStudentTestForms()).Where(x => x.FormStatus != "Not started").Select(x => x.LocalStudentId).ToList();
                    var filteredChildRecord = childRecords.FindAll(x => testRecords.Contains(x.OfflineStudentID));
                    foreach (var childRecord in filteredChildRecord)
                    {
                        if (childRecord.SelectedLocationId.HasValue && AllLocations != null && AllLocations.Any() && AllLocations.Where(p => p.IsEnabled).Any(p => p.LocationId == childRecord.SelectedLocationId.Value))
                        {
                            string birthdate = (childRecord.Birthdate.Month < 10 ? "0" + childRecord.Birthdate.Month : childRecord.Birthdate.Month + "") + "/" + (childRecord.Birthdate.Day < 10 ? "0" + childRecord.Birthdate.Day : childRecord.Birthdate.Day + "") + "/" + childRecord.Birthdate.Year;
                            initialChildRecords.Add(new ChildRecord()
                            {
                                Name             = childRecord.FirstName + " " + childRecord.LastName,
                                selected         = false,
                                Location         = AllLocations != null && AllLocations.Any() && childRecord.SelectedLocationId != null ? AllLocations.FirstOrDefault(p => p.LocationId == childRecord.SelectedLocationId.Value)?.LocationName : "",
                                LocationID       = (childRecord.SelectedLocationId == null) ? 0 : Convert.ToInt32(childRecord.SelectedLocationId),
                                OfflineStudentId = childRecord.OfflineStudentID,
                                DOB = birthdate
                            });
                        }
                    }
                    var list = initialChildRecords.OrderBy(a => a.LastName);
                    initialChildRecords = new List <ChildRecord>(list);

                    var searchChildRecords          = new List <ChildRecord>();
                    IEnumerable <ChildRecord> query = initialChildRecords;

                    if (SelectedLocations.Count > 0)
                    {
                        query = query.Where(p => !string.IsNullOrEmpty(p.Location) && SelectedLocations.Contains(p.Location));
                    }

                    searchChildRecords = new List <ChildRecord>(query);
                    foreach (var item in searchChildRecords)
                    {
                        ChildRecords.Add(item);
                    }
                }
            }

            if (ChildRecords.Count == 0)
            {
                SelectedChild = "No results found";
                IsChildRecordButtonEnabled = false;
                IsBatteryTypeButtonEnabled = false;
            }
            else
            {
                SelectedChild = null;
            }
        }