public new void Page_PreInit(object sender, EventArgs e) { base.Page_PreInit(sender, e); Entity = db.CRM_Schools.SingleOrDefault(a => a.ID.ToString() == Request.QueryString["id"]); if (Entity == null) { NoticeManager.SetMessage("School not found", "/admin/school/list.aspx"); } }
public void ProcessRequest(HttpContext context) { string JSONOutput = EmptyOutput; context.Response.AddHeader("Content-type", "text/json"); using (MainDataContext db = new MainDataContext()) { string dataset = context.Request.QueryString["dataset"]; int parseddataset = Enumeration.GetEnumValueByName <JSONSet.DataSets>(dataset); string searchCriteria = HttpUtility.HtmlDecode(context.Request.QueryString["query"]).ToLower(); IEnumerable <JSONSet> jsonItems = Enumerable.Empty <JSONSet>(); switch (parseddataset) { case (int)JSONSet.DataSets.venue: { var venues = CRM_Venue.BaseSet(db); jsonItems = from p in venues where p.Tokens.Any(t => t.Contains(searchCriteria)) select new JSONSet(p.Name + " : " + p.CRM_Address.FormattedAddressBySep(", "), p.CRM_Address.Postcode, p.Reference.ToString(), "", p.Reference); } break; case (int)JSONSet.DataSets.person: { var persons = CRM_Person.BaseSet(db); jsonItems = from p in persons where !p.IsArchived where p.Tokens.Any(t => t.Contains(searchCriteria)) select new JSONSet(p.Fullname + " : " + p.PrimaryAddressRecord.FormattedAddressBySep(", "), p.DateOfBirthOutput, p.ID.ToString(), p.Photo, p.Reference); } break; case (int)JSONSet.DataSets.archivedperson: { var persons = db.CRM_Persons; jsonItems = from p in (from p in persons where p.IsArchived select p).ToList() where p.Tokens.Any(t => t.Contains(searchCriteria)) select new JSONSet(p.Fullname + " : " + p.PrimaryAddressRecord.FormattedAddressBySep(", "), p.DateOfBirthOutput, p.Reference.ToString(), p.Photo, p.Reference); } break; case (int)JSONSet.DataSets.contact: { var unarchivedContacts = from p in CRM.Code.Utils.SharedObject.SharedObject.GetSharedObjects <IContact>(db) where !p.IsArchived select p; jsonItems = from p in unarchivedContacts where p.Tokens.Any(t => t.ToLower().Contains(searchCriteria.ToLower())) orderby p.Lastname, p.Firstname select new JSONSet(p.Fullname + " : " + p.PrimaryAddress.FormattedAddressBySep(", "), p.OutputTableName, p.Reference, p.Photo, p.CRM_PersonReference); } break; case (int)JSONSet.DataSets.organisation: { var orgs = CRM_Organisation.BaseSet(db); jsonItems = from p in orgs where p.Tokens.Any(t => t.Contains(searchCriteria)) select new JSONSet(p.Name + " : " + p.CRM_Address.FormattedAddressBySep(", "), p.CRM_OrganisationType.Name, p.ID.ToString(), "", p.Reference); } break; case (int)JSONSet.DataSets.school: { var schools = CRM_School.BaseSet(db); jsonItems = from p in schools where p.Tokens.Any(t => t.Contains(searchCriteria)) select new JSONSet(p.Name + " : " + p.CRM_Address.FormattedAddressBySep(", "), p.CRM_SchoolType.Name, p.ID.ToString(), "", p.Reference); } break; case (int)JSONSet.DataSets.schoolperson: { var schoolsp = CRM_PersonSchool.BaseSet(db); jsonItems = from p in schoolsp where !p.IsArchived where p.Tokens.Any(t => t.Contains(searchCriteria)) select new JSONSet(p.Name + " : " + p.PrimaryAddress.FormattedAddressBySep(", "), p.CRM_School.Name, p.ID.ToString(), p.CRM_Person.Photo, p.Reference); } break; case (int)JSONSet.DataSets.orgperson: { var orgpers = CRM_PersonOrganisation.BaseSet(db); jsonItems = from p in orgpers where !p.IsArchived where p.Tokens.Any(t => t.Contains(searchCriteria)) select new JSONSet(p.Name + " : " + p.PrimaryAddress.FormattedAddressBySep(", "), p.CRM_Organisation.Name, p.ID.ToString(), p.CRM_Person.Photo, p.Reference); } break; case (int)JSONSet.DataSets.family: { var families = CRM_Family.BaseSet(db); jsonItems = from p in families where p.Tokens.Any(t => t.Contains(searchCriteria)) select new JSONSet(p.Name + " : " + p.CRM_FamilyPersons.Count() + " members", p.MemberList, p.ID.ToString(), "", p.Reference); } break; case (int)JSONSet.DataSets.mytasks: { var tasks = db.CRM_Tasks.ToArray().Where(c => c.IsVisible(Convert.ToInt32(HttpContext.Current.Request.QueryString["adminuserid"]))); jsonItems = from p in tasks where p.Tokens.Any(t => t.Contains(searchCriteria)) select new JSONSet(p.Name + "", p.DueDate.ToString("dd/MM/yyyy"), p.ID.ToString(), "", p.Reference); } break; case (int)JSONSet.DataSets.admin: { var admins = db.Admins.ToArray(); jsonItems = from p in admins where p.Tokens.Any(t => t.Contains(searchCriteria)) select new JSONSet(p.DisplayName + "", p.LastLogin == null ? "Never logged in" : "Last Login: "******"dd/MM/yyyy HH:mm"), p.ID.ToString(), "", p.ID.ToString()); } break; case (int)JSONSet.DataSets.schoolorgs: { var schoolorgs = CRM.Code.Utils.SharedObject.SharedObject.GetSharedObjects <ISchoolOrganisation>(db); jsonItems = from p in schoolorgs where p.Tokens.Any(t => t.Contains(searchCriteria)) select new JSONSet(p.Name + " : " + p.CRM_Address.FormattedAddressBySep(", "), p.OutputTableName, p.Reference, "", p.Reference.ToString()); } break; } if (jsonItems.Any()) { JSONOutput = JSONSet.ConvertToJSON(jsonItems); } else { jsonItems = Enumerable.Concat(jsonItems, new [] { new JSONSet("No results found", "Please alter your search", "", "", "") }); JSONOutput = JSONSet.ConvertToJSON(jsonItems); } context.Response.Write(JSONOutput); } context.Response.End(); }
public void RunImport(int startLine, int endLine) { MainDataContext db = new MainDataContext(); HttpServerUtility Server = HttpContext.Current.Server; using (StreamReader reader = new StreamReader(Server.MapPath("/taskscript/scotschools.csv"))) { lineNumber = 0; while (!reader.EndOfStream) { lineNumber++; string contents = reader.ReadLine(); if (lineNumber >= startLine && lineNumber <= endLine) { string[] contentsSplit = contents.Split(','); string errorMessage = ""; string postcode = contentsSplit[(int)accountPos.postcodea] + " " + contentsSplit[(int)accountPos.postcodeb]; CRM_School school = db.CRM_Schools.FirstOrDefault(s => s.Name == contentsSplit[(int)accountPos.name] && s.CRM_Address.Postcode.Trim().Replace(" ", "").ToLower() == postcode.Trim().Replace(" ", "").ToLower()); CRM_LEA lea = db.CRM_LEAs.Single(s => s.ID == 25); // blank CRM_SchoolType type = db.CRM_SchoolTypes.Single(s => s.ID == 1); // none Country country = db.Countries.Single(s => s.ID == 1); // uk if (school == null) { CRM_Address address = new CRM_Address() { AddressLine1 = contentsSplit[(int)accountPos.address1].Trim(), AddressLine2 = "", AddressLine3 = "", AddressLine4 = "", AddressLine5 = "", Town = contentsSplit[(int)accountPos.address2], County = "", Postcode = postcode, CountryID = country.ID }; db.CRM_Addresses.InsertOnSubmit(address); db.SubmitChanges(); school = new CRM_School() { CRM_AddressID = address.ID, ApproxPupils = 0, CRM_LEAID = lea.ID, CRM_RegionID = null, CRM_SchoolTypeID = type.ID, Email = "", IsArchived = false, IsSEN = false, Name = contentsSplit[(int)accountPos.name].Trim(), Phone = "", SageAccountNumber = "", PrimaryContactReference = "", SENSupportFreq = "", }; db.CRM_Schools.InsertOnSubmit(school); db.SubmitChanges(); } } } } }
protected void lnkSelect_Click(object sender, EventArgs e) { CRM_School school = db.CRM_Schools.Single(v => v.ID.ToString() == ucACSchool.SelectedID); ucACSchool.Populate(school); }
public void RunImport(int startLine, int endLine) { MainDataContext db = new MainDataContext(); HttpServerUtility Server = HttpContext.Current.Server; string path = "/TaskScript/FinalListforCoalFace.csv"; using (StreamReader reader = new StreamReader(Server.MapPath(path))) { lineNumber = 0; while (!reader.EndOfStream) { lineNumber++; string contents = reader.ReadLine(); if (lineNumber >= startLine && lineNumber <= endLine) { string[] contentsSplit = contents.Split(','); string errorMessage = ""; CRM_Person person = db.CRM_Persons.FirstOrDefault(f => f.LegacyID != null && f.LegacyID.ToString() == contentsSplit[(int)accountPos.LegacyID]); if (person != null && contentsSplit[(int)accountPos.Constituent] == "Schools and universities") { /* * if (contentsSplit[(int)accountPos.PhoneNumber11].Contains("@")) * { * person.PrimaryEmail = contentsSplit[(int)accountPos.PhoneNumber11]; * } * else * { * person.PrimaryTelephone = contentsSplit[(int)accountPos.PhoneNumber11]; * person.PrimaryEmail = contentsSplit[(int)accountPos.PhoneNumber12]; * } * * if (!contentsSplit[(int)accountPos.PhoneNumber12].Contains("@")) * { * person.Telephone2 = contentsSplit[(int)accountPos.PhoneNumber12]; * } * * db.SubmitChanges(); */ if (!String.IsNullOrEmpty(contentsSplit[(int)accountPos.Address1])) { CRM_School org = db.CRM_Schools.FirstOrDefault(f => f.Name == contentsSplit[(int)accountPos.Address1]); if (org == null) { string name = ""; CRM_Address orgAddress = new CRM_Address(); if (!String.IsNullOrEmpty(contentsSplit[(int)accountPos.OrgAddr1].Trim())) { orgAddress = new CRM_Address() { AddressLine1 = contentsSplit[(int)accountPos.OrgAddr1], AddressLine2 = contentsSplit[(int)accountPos.OrgAddr2], AddressLine3 = contentsSplit[(int)accountPos.OrgAddr3], AddressLine4 = contentsSplit[(int)accountPos.OrgAddr4], AddressLine5 = "", County = "", Town = contentsSplit[(int)accountPos.OrgAddrCity], Postcode = contentsSplit[(int)accountPos.OrgAddrPostcode], CountryID = 1 }; db.CRM_Addresses.InsertOnSubmit(orgAddress); db.SubmitChanges(); name = contentsSplit[(int)accountPos.OrgName]; } else { orgAddress = new CRM_Address() { AddressLine1 = contentsSplit[(int)accountPos.Address1], AddressLine2 = contentsSplit[(int)accountPos.Address2], AddressLine3 = contentsSplit[(int)accountPos.Address3], AddressLine4 = contentsSplit[(int)accountPos.Address4], AddressLine5 = "", County = "", Town = contentsSplit[(int)accountPos.City], Postcode = contentsSplit[(int)accountPos.Postcode], CountryID = 1 }; db.CRM_Addresses.InsertOnSubmit(orgAddress); db.SubmitChanges(); name = contentsSplit[(int)accountPos.Address1]; } org = new CRM_School() { CRM_SchoolTypeID = 1, CRM_AddressID = orgAddress.ID, Name = name, IsArchived = false, PrimaryContactReference = person.Reference, SENSupportFreq = "", SageAccountNumber = "", Phone = "", Email = "" }; db.CRM_Schools.InsertOnSubmit(org); db.SubmitChanges(); } CRM_Role role = db.CRM_Roles.FirstOrDefault(f => f.Name == contentsSplit[(int)accountPos.OrgPosition]); if (role == null) { role = new CRM_Role(); db.CRM_Roles.InsertOnSubmit(role); role.Name = contentsSplit[(int)accountPos.OrgPosition]; db.SubmitChanges(); } CRM_PersonSchool personOrg = new CRM_PersonSchool() { CRM_SchoolID = org.ID, CRM_RoleID = role.ID, IsArchived = false, Email = "", Telephone = contentsSplit[(int)accountPos.PhoneNumber21], CRM_PersonID = person.ID }; db.CRM_PersonSchools.InsertOnSubmit(personOrg); db.SubmitChanges(); } } } } } }