public AppViewModel GetAppViewModel(Guid id)
        {
            AppViewModel avm = new AppViewModel();            
            avm.Id = id;
            using (SlpContext context = new SlpContext())
            {
                SlpApplication dbApp = context.SlpApplication.Find(avm.Id);
                if (dbApp != null)
                {
                    avm.AssistanceProgramId = dbApp.AssistanceProgramId;
                    avm.AssistanceProgramCaseNumber = dbApp.AssistanceProgramCaseNumber;
                    avm.TotalMembers = dbApp.TotalMembers;
                    avm.MemberLastFourSSN = dbApp.MemberLastFourSSN;
                    avm.StreetAddress = dbApp.StreetAddress;
                    avm.AptNo = dbApp.AptNo;
                    avm.City = dbApp.City;
                    avm.State = dbApp.State;
                    avm.Zip = dbApp.Zip;
                    avm.Email = dbApp.Email;
                    avm.Phone = dbApp.Phone;
                    avm.AdultFilledByName = dbApp.AdultFilledByName;
                    avm.EthnicityId = dbApp.EthnicityId;

                    avm.NoSSN = dbApp.NoSSN;
                }
            }
            List<MemberViewModel> members = GetMembers(avm.Id);
            avm.Children = members.Where(a => a.IsChild == true).ToList();
            avm.Adults = members.Where(a => a.IsChild == false).ToList();

            //set domain values, default for all applications new/old
            using (SlpContext context = new SlpContext())
            {
                avm.AssistancePrograms = context.AssistanceProgram.Where(a => a.Visible == true).Select(a => new NameValueViewModel { Name = a.Name, Value = a.Id }).OrderBy(a => a.Value).ToList();
                avm.Ethnicities = context.Ethnicity.Where(a => a.Visible == true).Select(a => new NameValueViewModel { Name = a.Name, Value = a.Id }).OrderBy(a => a.Value).ToList();
                avm.Frequencies = context.Frequency.Where(a => a.Visible == true).Select(a => new NameValueViewModel { Name = a.Name, Value = a.Id }).OrderBy(a => a.Value).ToList();
                avm.Races = context.Race.Where(a => a.Visible == true).Select(a => new NameValueViewModel { Name = a.Name, Value = a.Id }).OrderBy(a => a.Value).ToList();
                
                foreach (SlpApplicationRace dbrace in context.SlpApplicationRace.Where(a => a.SlpApplicationId == avm.Id))
                {
                    NameValueViewModel race = avm.Races.Where(a => a.Value == dbrace.RaceId).FirstOrDefault();
                    if (race != null)
                    {
                        race.SelectedItem = true;
                    }
                }
            }
            avm.AssistanceProgramNoneId = (int)AssistanceProgramsEnum.None;
            return avm;
        }
        public AppViewModel CompletedAppMembers(Guid applicationGuid) {
            List<AppMembersViewModel> avm = new List<AppMembersViewModel>();
            List<MemberViewModel> mvm = new List<MemberViewModel>();
            using (SlpContext context = new SlpContext())
            {
                 mvm =
                    context.Members.Where(a => a.SlpApplication.CompletedDate != null).Select(b =>
                  new MemberViewModel
                  {
                      AppId = b.SlpApplicationId,
                      FirstName = b.FirstName,
                      MiddleInitial = b.MiddleInitial,
                      LastName = b.LastName,
                      IsChild = b.IsChild,
                      ApplicationCompletedDate = b.SlpApplication.CompletedDate
                  }).ToList();
            }

            foreach (Guid appId in mvm.Select(a => a.AppId).Distinct())
            {
                List<MemberViewModel> appMembers = mvm.Where(a => a.AppId == appId).ToList();
                avm.Add(
                    new AppMembersViewModel
                    {
                        AppId = appId,
                        CompletedDate = appMembers.FirstOrDefault().ApplicationCompletedDate.ToString(),
                        CompletedDateTime = appMembers.FirstOrDefault().ApplicationCompletedDate.Value,
                        Adults = string.Join(", ", appMembers.Where(a => a.IsChild == false).Select(b => b.DisplayName)),
                        Children = string.Join(", ", appMembers.Where(a => a.IsChild == true).Select(b => b.DisplayName))
                    }
                    );
            }
            AppViewModel appVM = new AppViewModel();            
            AppOrchestrator appOrc = new AppOrchestrator();
            appVM = appOrc.GetAppViewModel(applicationGuid); //init objects with random guid
            appVM.AppMembers = avm.OrderByDescending(a => a.CompletedDateTime).ToList(); //members for report
            return appVM;
        }
Exemplo n.º 3
0
 public JsonResult GetAplication(Guid appId)
 {
     AppViewModel avm = new AppViewModel();            
     avm = appOrchestrator.GetAppViewModel(appId);
     return Json(avm, JsonRequestBehavior.AllowGet);
 }