public ActionResult Demographics() { var countries = db.AspNetUsers.GroupBy(x => x.Country) .Select(n => new CountryData { CountryName = n.Key, CountryCount = n.Count() }) .OrderByDescending(x => x.CountryCount) .ToList(); var views = db.ViewDatas.OrderBy(x => x.ViewCount).ToList(); var levels = db.AspNetUsers.GroupBy(x => x.LevelID) .Select(n => new UserLevelsData { UsersLevel = n.Key.ToString(), UsersLevelCount = n.Count() }) .ToList(); DemographicViewModel vm = new DemographicViewModel(); vm.CountryDatas = countries; vm.UserLevelsDatas = levels; vm.ViewsDatas = views; return(View(vm)); }
// GET: api/Demographic //6. Build a basic API endpoint that returns a JSON document with the following pieces of information, //based on the list of people: //a.Number of people //b.Average, Min and Max Age //c.Count of the number of people in each race public DemographicViewModel Get() { DemographicViewModel vm = new DemographicViewModel(); try { var people = DataContext.GetInstance().People; vm.people = people != null ? people.Count : 0; vm.age.min = people != null?people.Min(x => x.Age) : 0; vm.age.max = people != null?people.Max(x => x.Age) : 0; vm.age.average = people != null?Math.Round(people.Average(x => x.Age), 2) : 0; var races = Helper.GetPersonTypes(); if (races != null && races.Count > 0 && people != null && people.Count > 0) { vm.races = races.ToDictionary(x => x.Name, x => people.Count(p => p.GetType().Name == x.Name)); } return(vm); } catch { return(vm); } }
//Process client side data and updates demographic data in the database. public JsonResult Edit(DemographicViewModel demographic) { if (demographic.CaseDetail != null) { var caseDetail = CaseService.FindCaseDetailById(demographic.CaseDetailId); if (caseDetail != null) { if (caseDetail.CaseKey != "00") { var relationship = RelationshipTypeService.GetRelationshipTypes() .Where(x => x.RelationshipType1 == demographic.Relationship && x.WidowCertification == demographic.CaseDetail.Entity.HasWidowCertification) .FirstOrDefault(); caseDetail.RelationshipType = relationship; caseDetail.RelationshipTypeId = relationship.RelationshipTypeId; } #region Entity Information Entity entity = new Entity(); if (!demographic.InsertNewEntity) { entity = EntityService.GetById(Convert.ToInt32(caseDetail.EntityId_Sic)); } entity.FirstName = demographic.CaseDetail.Entity.FirstName.Trim(); entity.MiddleName = demographic.CaseDetail.Entity.MiddleName != null?demographic.CaseDetail.Entity.MiddleName.Trim() : null; entity.LastName = demographic.CaseDetail.Entity.LastName.Trim(); entity.SecondLastName = demographic.CaseDetail.Entity.SecondLastName != null?demographic.CaseDetail.Entity.SecondLastName.Trim() : null; entity.FullName = string.Concat( entity.FirstName + " ", entity.MiddleName.IsNullOrEmpty() ? String.Empty : entity.MiddleName + " ", entity.LastName + " ", entity.SecondLastName.IsNullOrEmpty() ? String.Empty : entity.SecondLastName + " "); entity.CaseNumber = demographic.CaseDetail.CaseNumber; entity.CaseKey = demographic.CaseDetail.CaseKey; entity.SSN = demographic.CaseDetail.Entity.SSN; entity.IDNumber = demographic.CaseDetail.Entity.IDNumber; entity.BirthDate = demographic.CaseDetail.Entity.BirthDate; entity.DeceaseDate = demographic.CaseDetail.Entity.DeceaseDate; entity.MarriageDate = demographic.CaseDetail.Entity.MarriageDate; entity.CivilStatusId = demographic.CaseDetail.Entity.CivilStatusId; entity.IsStudying = demographic.CaseDetail.Entity.IsStudying; entity.SchoolStartDate = demographic.CaseDetail.Entity.SchoolStartDate; entity.SchoolEndDate = demographic.CaseDetail.Entity.SchoolEndDate; entity.HasDisability = demographic.CaseDetail.Entity.HasDisability; entity.OccupationId = demographic.CaseDetail.Entity.OccupationId; entity.MonthlyIncome = demographic.CaseDetail.Entity.MonthlyIncome; entity.IsRehabilitated = demographic.CaseDetail.Entity.IsRehabilitated; entity.IsWorking = demographic.CaseDetail.Entity.IsWorking; entity.IsEmancipated = demographic.CaseDetail.Entity.IsEmancipated; entity.HasWidowCertification = demographic.CaseDetail.Entity.HasWidowCertification; entity.WidowCertificationDate = demographic.CaseDetail.Entity.WidowCertificationDate; entity.ModifiedReasonId = demographic.CaseDetail.Entity.ModifiedReasonId; entity.OtherModifiedReason = demographic.CaseDetail.Entity.OtherModifiedReason; entity.Comments = demographic.CaseDetail.Entity.Comments; entity.Email = demographic.CaseDetail.Entity.Email; entity.HomePhoneNumber = demographic.CaseDetail.Entity.HomePhoneNumber; entity.CellPhoneNumber = demographic.CaseDetail.Entity.CellPhoneNumber; entity.WorkPhoneNumber = demographic.CaseDetail.Entity.WorkPhoneNumber; entity.FaxPhoneNumber = demographic.CaseDetail.Entity.FaxPhoneNumber; entity.OtherPhoneNumber = demographic.CaseDetail.Entity.OtherPhoneNumber; entity.ModifiedBy = WebHelper.GetUserName(); entity.ModifiedDateTime = DateTime.Now; #endregion #region Address Information if (demographic.PostalAddress != null) { Address PostalAddress = demographic.PostalAddress; //Verificar una manera de traer toda la informaicon de coutry / state a traves de ciudad. var city = LocationService.GetAllCities().Where(x => x.CityId == demographic.PostalAddress.CityId).FirstOrDefault(); string state = ""; if (demographic.PostalAddress.StateId != null) { var state1 = LocationService.GetAllStates().Where(x => x.StateId == demographic.PostalAddress.StateId).FirstOrDefault(); state = state1.State1; } var country = LocationService.GetAllCountries().Where(x => x.CountryId == demographic.PostalAddress.CountryId).FirstOrDefault(); PostalAddress.FullAddress = demographic.PostalAddress.Line1 + (demographic.PostalAddress.Line2.IsNullOrEmpty() ? "" : " " + demographic.PostalAddress.Line2.Trim()) + (demographic.PostalAddress.CityId == null ? "" : city.City1 != "Otro" ? " " + city.City1 : " " + demographic.PostalAddress.OtherCity) + (demographic.PostalAddress.StateId == null ? "" : ", " + state) + (demographic.PostalAddress.CountryId == null ? "" : ", " + country.Country1) + (demographic.PostalAddress.ZipCode == null ? "" : " " + demographic.PostalAddress.ZipCode) + (demographic.PostalAddress.ZipCodeExt == null ? "" : "-" + demographic.PostalAddress.ZipCodeExt); PostalAddress.AddressTypeId = AddressTypeService.GetAddressTypes().Where(x => x.AddressType1 == "Postal").Select(x => x.AddressTypeId).FirstOrDefault(); PostalAddress.SourceId = 8; PostalAddress.ModifiedBy = WebHelper.GetUserName(); PostalAddress.ModifiedDateTime = DateTime.Now; if (!demographic.HasAddress) { PostalAddress.CreatedBy = WebHelper.GetUserName(); PostalAddress.CreatedDateTime = DateTime.Now; entity.Addresses.Add(PostalAddress); } else { foreach (var a in demographic.CaseDetail.Entity.Addresses) { if (a.AddressType.AddressType1 == "Postal" && a.AddressId == demographic.PostalAddress.AddressId) { a.Line1 = demographic.PostalAddress.Line1; a.Line2 = demographic.PostalAddress.Line2; a.CityId = demographic.PostalAddress.CityId; a.OtherCity = demographic.PostalAddress.OtherCity; a.StateId = demographic.PostalAddress.StateId; a.CountryId = demographic.PostalAddress.CountryId; a.ZipCode = demographic.PostalAddress.ZipCode; a.ZipCodeExt = demographic.PostalAddress.ZipCodeExt; a.FullAddress = demographic.PostalAddress.FullAddress; a.EntityId = demographic.PostalAddress.EntityId; } } } } #endregion //#region Phone Information //#endregion if (demographic.InsertNewEntity) { entity.SourceId = 8; //SourceId = Entity Sic Source entity.CreatedBy = WebHelper.GetUserName(); entity.CreatedDateTime = DateTime.Now; try { EntityService.CreateEntity(entity); } catch { throw new Exception(); } } else { try { EntityService.ModifyEntity(entity); } catch { throw new Exception(); } } caseDetail.Entity = entity; caseDetail.EntitySic = entity; caseDetail.EntityId = entity.EntityId; caseDetail.EntityId_Sic = entity.EntityId; try { CaseService.UpdateCaseDetail(caseDetail); } catch { EntityService.Delete(entity.EntityId); throw new Exception(); } return(Json(new { Data = demographic.CaseDetail })); } else { throw new Exception(); } } else { throw new Exception(); } }
// GET: Demographic public ActionResult Index() { var model = new DemographicViewModel(); return(View(model)); }