/// <summary> /// Save method. /// </summary> public void Save() { try { context.SaveChanges(); } catch (Exception e) { if (e.InnerException != null) { e = e.InnerException; } List <string> lines = new List <string>(); foreach (var error in e.Data) { lines.Add(error.ToString()); } string errorsFilePath = "errors.txt"; if (!File.Exists(errorsFilePath)) { File.Create(errorsFilePath); FileIOPermission fp = new FileIOPermission(FileIOPermissionAccess.AllAccess, errorsFilePath); } File.AppendAllLines("errors.txt", lines); throw e; } }
/// <summary> /// Save method. /// </summary> public void Save() { try { context.SaveChanges(); } catch (Exception e) { List <string> lines = new List <string>(); foreach (var error in e.Data) { lines.Add(error.ToString()); } System.IO.File.AppendAllLines(@"E:\errors.txt", lines); throw e; } }
public void Seed() { // Run Migrations context.Database.Migrate(); if (context.OrganizationTypes.Count() == 0) { var typeDefault = context.OrganizationTypes.Add(new EFOrganizationTypes() { TypeName = "Default" }); var type1 = context.OrganizationTypes.Add(new EFOrganizationTypes() { TypeName = "Govt" }); var type2 = context.OrganizationTypes.Add(new EFOrganizationTypes() { TypeName = "Private" }); var type3 = context.OrganizationTypes.Add(new EFOrganizationTypes() { TypeName = "Semi-Govt" }); var orgMop = context.Organizations.Add(new EFOrganization() { OrganizationName = "MoPIED", OrganizationType = type1.Entity }); var adminUser = context.Users.Add(new EFUser() { Email = "*****@*****.**", Name = "Super Admin", Password = "******", Organization = orgMop.Entity, RegistrationDate = DateTime.Now, IsApproved = true, UserType = UserTypes.SuperAdmin }); context.SaveChanges(); } }
public void Seed() { try { // Run Migrations context.Database.Migrate(); if (context.HomePageSettings.Count() == 0) { context.HomePageSettings.Add(new EFHomePageSettings() { AIMSTitle = "Somali AIMS", IntroductionHeading = "Introduction", IntroductionText = "Welcome to Somali AIMS" }); } if (context.EnvelopeTypes.Count() == 0) { context.EnvelopeTypes.Add(new EFEnvelopeTypes() { TypeName = "Development" }); context.EnvelopeTypes.Add(new EFEnvelopeTypes() { TypeName = "Humanitarian" }); } if (context.EmailMessages.Count() == 0) { context.EmailMessages.Add(new EFEmailMessages() { MessageType = EmailMessageType.NewUser, TypeDefinition = "New user registration", Subject = "New user registration", Message = "New user registered" }); context.EmailMessages.Add(new EFEmailMessages() { MessageType = EmailMessageType.NewProjectToOrg, TypeDefinition = "Organization added to project", Subject = "Organization added to project", Message = "New project added to organanization" }); context.EmailMessages.Add(new EFEmailMessages() { MessageType = EmailMessageType.UserInactive, TypeDefinition = "User inactive", Subject = "User account deactivated", Message = "User is inactive" }); context.EmailMessages.Add(new EFEmailMessages() { MessageType = EmailMessageType.ChangedMappingEffectedProject, TypeDefinition = "Sector mapping updated", Subject = "Sector mapping updated", Message = "Sector mapping updated" }); context.EmailMessages.Add(new EFEmailMessages() { MessageType = EmailMessageType.NewIATISector, TypeDefinition = "Sector added from IATI", Subject = "Sector/s added from IATI", Message = "New sector/s added from IATI" }); context.EmailMessages.Add(new EFEmailMessages() { MessageType = EmailMessageType.OrganizationMerged, TypeDefinition = "Organization merged", Subject = "Organizations merged", Message = "Organization merged" }); context.EmailMessages.Add(new EFEmailMessages() { MessageType = EmailMessageType.NewOrgToProject, TypeDefinition = "New organization request for project", Subject = "Organization requesting to join project", Message = "" }); context.EmailMessages.Add(new EFEmailMessages() { MessageType = EmailMessageType.ProjectPermissionGranted, TypeDefinition = "Project permission approved/granted", Subject = "Project membership granted", Message = "" }); context.EmailMessages.Add(new EFEmailMessages() { MessageType = EmailMessageType.ProjectPermissionDenied, TypeDefinition = "Project permission unapproved/denied", Subject = "Project membership denied", Message = "" }); context.EmailMessages.Add(new EFEmailMessages() { MessageType = EmailMessageType.UserApproved, TypeDefinition = "User account approved", Subject = "User account approval confirmation", Message = "" }); context.EmailMessages.Add(new EFEmailMessages() { MessageType = EmailMessageType.OrganizationRenamed, TypeDefinition = "Organization renamed", Subject = "Organization renamed", Message = "" }); context.EmailMessages.Add(new EFEmailMessages() { MessageType = EmailMessageType.ProjectDeletionRequest, TypeDefinition = "Project deletion request", Subject = "Project deletion request", Message = "" }); context.EmailMessages.Add(new EFEmailMessages() { MessageType = EmailMessageType.ProjectDeletionCancelled, TypeDefinition = "Project deletion cancelled", Subject = "Project deletion request cancelled", Message = "" }); context.EmailMessages.Add(new EFEmailMessages() { MessageType = EmailMessageType.ProjectDeletionApproved, TypeDefinition = "Project deletion approved", Subject = "Project deletion approved", Message = "" }); context.EmailMessages.Add(new EFEmailMessages() { MessageType = EmailMessageType.ProjectDeleted, TypeDefinition = "Project deletion notification", Subject = "Project deletion notification", Message = "" }); context.EmailMessages.Add(new EFEmailMessages() { MessageType = EmailMessageType.ResetPassword, TypeDefinition = "Reset password", Subject = "User password reset", Message = "Your password is reset successfully" }); context.EmailMessages.Add(new EFEmailMessages() { MessageType = EmailMessageType.NewIATIOrganization, TypeDefinition = "New IATI organizations", Subject = "New organization/s", Message = "Some new organizations are added through IATI to AIMS DB." }); context.EmailMessages.Add(new EFEmailMessages() { MessageType = EmailMessageType.MergeOrganizationRequest, TypeDefinition = "Organizations merge request", Subject = "Organizations merge request", Message = "" }); context.EmailMessages.Add(new EFEmailMessages() { MessageType = EmailMessageType.MergeOrganizationRejected, TypeDefinition = "Organizations merge rejection", Subject = "Organizations merge rejection", Message = "" }); context.EmailMessages.Add(new EFEmailMessages() { MessageType = EmailMessageType.MergeOrganizationRejected, TypeDefinition = "User approved un-affiliated", Subject = "User approved un-affiliated", Message = "" }); context.EmailMessages.Add(new EFEmailMessages() { MessageType = EmailMessageType.OrganizationDeletedAndMapped, TypeDefinition = "Organization deleted and mapped to another", Subject = "Organization deleted and mapped to another", Message = "" }); context.SaveChanges(); } if (context.IATISettings.Count() == 0) { context.IATISettings.Add(new EFIATISettings() { BaseUrl = "http://datastore.iatistandard.org/api/1/access/activity.xml?recipient-country=SO&stream=true" }); } if (context.FinancialYearSettings.Count() == 0) { context.FinancialYearSettings.Add(new EFFinancialYearSettings() { Day = 1, Month = 1 }); context.SaveChanges(); } if (context.FundingTypes.Count() == 0) { context.FundingTypes.Add(new EFFundingTypes() { FundingType = "Grant" }); context.FundingTypes.Add(new EFFundingTypes() { FundingType = "Loan" }); context.SaveChanges(); } if (context.StaticReports.Count() == 0) { context.StaticReports.Add(new EFStaticReports() { Title = "Projects report" }); context.StaticReports.Add(new EFStaticReports() { Title = "Locations report" }); context.StaticReports.Add(new EFStaticReports() { Title = "Sectors report" }); context.StaticReports.Add(new EFStaticReports() { Title = "Budget report" }); context.StaticReports.Add(new EFStaticReports() { Title = "Project profile" }); context.StaticReports.Add(new EFStaticReports() { Title = "Excel report" }); context.SaveChanges(); } if (context.OrganizationTypes.Count() == 0) { context.OrganizationTypes.Add(new EFOrganizationTypes() { TypeName = "Default" }); context.SaveChanges(); } if (context.SectorTypes.Count() == 0) { var primary = context.SectorTypes.Add(new EFSectorTypes() { TypeName = "Somali Sectors", IsPrimary = true, IsSourceType = false, IATICode = null }); context.SaveChanges(); //context.SectorTypes.Add(new EFSectorTypes() { TypeName = "Default" }); var inclusivePolitics = context.Sectors.Add(new EFSector() { ParentSector = null, SectorType = primary.Entity, SectorName = "Pillar 1: Inclusive Politics", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = inclusivePolitics.Entity, SectorType = primary.Entity, SectorName = "Inclusive Politics", TimeStamp = DateTime.Now }); var security = context.Sectors.Add(new EFSector() { ParentSector = null, SectorType = primary.Entity, SectorName = "Pillar 2: Security", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = security.Entity, SectorType = primary.Entity, SectorName = "Security", TimeStamp = DateTime.Now }); var ruleOfLaw = context.Sectors.Add(new EFSector() { ParentSector = null, SectorType = primary.Entity, SectorName = "Pillar 3: Rule of Law", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = ruleOfLaw.Entity, SectorType = primary.Entity, SectorName = "Rule of Law", TimeStamp = DateTime.Now }); var effectiveInstitutions = context.Sectors.Add(new EFSector() { ParentSector = null, SectorType = primary.Entity, SectorName = "Pillar 4: Effective, Efficient Institutions", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = effectiveInstitutions.Entity, SectorType = primary.Entity, SectorName = "Civil Service Reform / Public Administration", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = effectiveInstitutions.Entity, SectorType = primary.Entity, SectorName = "Planning, M&E and Statistics", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = effectiveInstitutions.Entity, SectorType = primary.Entity, SectorName = "Public Financial Management", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = effectiveInstitutions.Entity, SectorType = primary.Entity, SectorName = "State and Local Governance", TimeStamp = DateTime.Now }); var economicalGrowth = context.Sectors.Add(new EFSector() { ParentSector = null, SectorType = primary.Entity, SectorName = "Pillar 5: Economic Growth", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = economicalGrowth.Entity, SectorType = primary.Entity, SectorName = "Agriculture - Irrigated and rain-fed crops", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = economicalGrowth.Entity, SectorType = primary.Entity, SectorName = "Employment and skills development", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = economicalGrowth.Entity, SectorType = primary.Entity, SectorName = "Livestock", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = economicalGrowth.Entity, SectorType = primary.Entity, SectorName = "Private Sector Development", TimeStamp = DateTime.Now }); var infrastructure = context.Sectors.Add(new EFSector() { ParentSector = null, SectorType = primary.Entity, SectorName = "Pillar 6: Infrastructure", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = infrastructure.Entity, SectorType = primary.Entity, SectorName = "Energy and ICT", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = infrastructure.Entity, SectorType = primary.Entity, SectorName = "Other infrastructure", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = infrastructure.Entity, SectorType = primary.Entity, SectorName = "Transport", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = infrastructure.Entity, SectorType = primary.Entity, SectorName = "Water and Sanitation (Urban)", TimeStamp = DateTime.Now }); var social = context.Sectors.Add(new EFSector() { ParentSector = null, SectorType = primary.Entity, SectorName = "Pillar 7: Social & Human Development", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = social.Entity, SectorType = primary.Entity, SectorName = "Education", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = social.Entity, SectorType = primary.Entity, SectorName = "Health", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = social.Entity, SectorType = primary.Entity, SectorName = "Nutrition", TimeStamp = DateTime.Now }); var resilience = context.Sectors.Add(new EFSector() { ParentSector = null, SectorType = primary.Entity, SectorName = "Pillar 8: Resilience", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = resilience.Entity, SectorType = primary.Entity, SectorName = "Disaster Risk Reduction", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = resilience.Entity, SectorType = primary.Entity, SectorName = "Environment & Natural Resources Management", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = resilience.Entity, SectorType = primary.Entity, SectorName = "Food Security", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = resilience.Entity, SectorType = primary.Entity, SectorName = "Migration, Displacement, Refugees and Durable Solutions", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = resilience.Entity, SectorType = primary.Entity, SectorName = "Social Protection & Safety Nets", TimeStamp = DateTime.Now }); var gender = context.Sectors.Add(new EFSector() { ParentSector = null, SectorType = primary.Entity, SectorName = "Pillar 9: Gender & Human Rights", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = gender.Entity, SectorType = primary.Entity, SectorName = "Gender & Human Rights", TimeStamp = DateTime.Now }); var other = context.Sectors.Add(new EFSector() { ParentSector = null, SectorType = primary.Entity, SectorName = "Other", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = other.Entity, SectorType = primary.Entity, SectorName = "Other", TimeStamp = DateTime.Now }); context.Sectors.Add(new EFSector() { ParentSector = null, SectorType = primary.Entity, SectorName = "UNATTRIBUTED", TimeStamp = DateTime.Now, IsUnAttributed = true }); } if (context.Locations.Count() == 0) { context.Locations.Add(new EFLocation() { Location = "UNATTRIBUTED", Latitude = 0, Longitude = 0, IsUnAttributed = true }); context.SaveChanges(); } if (context.FinancialYears.Count() == 0) { context.FinancialYears.Add(new EFFinancialYears() { FinancialYear = 2016, Label = "FY 2016" }); context.FinancialYears.Add(new EFFinancialYears() { FinancialYear = 2017, Label = "FY 2017" }); context.FinancialYears.Add(new EFFinancialYears() { FinancialYear = 2018, Label = "FY 2018" }); context.FinancialYears.Add(new EFFinancialYears() { FinancialYear = 2019, Label = "FY 2019" }); context.FinancialYears.Add(new EFFinancialYears() { FinancialYear = 2020, Label = "FY 2020" }); context.FinancialYears.Add(new EFFinancialYears() { FinancialYear = 2021, Label = "FY 2021" }); context.FinancialYears.Add(new EFFinancialYears() { FinancialYear = 2022, Label = "FY 2022" }); context.FinancialYears.Add(new EFFinancialYears() { FinancialYear = 2023, Label = "FY 2023" }); context.FinancialYears.Add(new EFFinancialYears() { FinancialYear = 2024, Label = "FY 2024" }); context.SaveChanges(); } if (context.ExchangeRatesSettings.Count() == 0) { context.ExchangeRatesSettings.Add(new EFExchangeRatesSettings() { APIKeyOpenExchangeRates = "ce2f27af4d414969bfe05b7285a01dec", ManualExchangeRates = null, ManualExchangeRateSource = "Central Bank" }); context.SaveChanges(); } if (context.SMTPSettings.Count() == 0) { context.SMTPSettings.Add(new EFSMTPSettings() { AdminEmail = "*****@*****.**", Host = "smtp.gmail.com", Port = 587, Username = "******", Password = "******" }); context.SaveChanges(); } EFSectorTypes somaliSectorType = null; EFSector otherSector = null; if (context.SectorTypes.Count() == 0) { somaliSectorType = context.SectorTypes.Add(new EFSectorTypes() { TypeName = "Somali Sectors", IsPrimary = true }).Entity; otherSector = context.Sectors.Add(new EFSector() { SectorType = somaliSectorType, SectorName = "Other", ParentSector = null }).Entity; context.SaveChanges(); } if (context.Locations.Count() == 0) { context.Locations.Add(new EFLocation() { Location = "UNATTRIBUTED", Longitude = 0, Latitude = 0 }); context.Locations.Add(new EFLocation() { Location = "FGS", Longitude = 0, Latitude = 0 }); context.Locations.Add(new EFLocation() { Location = "BRA", Longitude = 0, Latitude = 0 }); context.Locations.Add(new EFLocation() { Location = "GALMUDUG", Longitude = 0, Latitude = 0 }); context.Locations.Add(new EFLocation() { Location = "HIIRSHABELLE", Longitude = 0, Latitude = 0 }); context.Locations.Add(new EFLocation() { Location = "JUBALAND", Longitude = 0, Latitude = 0 }); context.Locations.Add(new EFLocation() { Location = "PUNTLAND", Longitude = 0, Latitude = 0 }); context.Locations.Add(new EFLocation() { Location = "SOUTH WEST", Longitude = 0, Latitude = 0 }); context.Locations.Add(new EFLocation() { Location = "SOMALILAND", Longitude = 0, Latitude = 0 }); context.SaveChanges(); } if (context.Markers.Count() == 0) { context.Markers.Add(new EFMarkers() { FieldTitle = "GENDER MARKER", FieldType = FieldTypes.Text, Help = "", Values = "" }); context.Markers.Add(new EFMarkers() { FieldTitle = "CAPACITY DEVELOPMENT MARKER", FieldType = FieldTypes.Text, Help = "", Values = "" }); context.Markers.Add(new EFMarkers() { FieldTitle = "STABALIZATION/CRESTA", FieldType = FieldTypes.Text, Help = "", Values = "" }); context.Markers.Add(new EFMarkers() { FieldTitle = "DURABLE SOLUTIONS", FieldType = FieldTypes.Text, Help = "", Values = "" }); context.Markers.Add(new EFMarkers() { FieldTitle = "YOUTH MARKER", FieldType = FieldTypes.Text, Help = "", Values = "" }); context.Markers.Add(new EFMarkers() { FieldTitle = "RRF MARKER", FieldType = FieldTypes.Text, Help = "", Values = "" }); context.Markers.Add(new EFMarkers() { FieldTitle = "HUMANATARIAN", FieldType = FieldTypes.Text, Help = "", Values = "" }); context.Markers.Add(new EFMarkers() { FieldTitle = "PWG CONSULTATION", FieldType = FieldTypes.Text, Help = "", Values = "" }); context.SaveChanges(); } if (context.Organizations.Count() == 0) { //Funders & Implementers var unAgency = context.OrganizationTypes.Add(new EFOrganizationTypes() { TypeName = "UN Agency" }); var federalGovt = context.OrganizationTypes.Add(new EFOrganizationTypes() { TypeName = "Federal Government" }); var undp = context.Organizations.Add(new EFOrganization() { OrganizationName = "UNDP", OrganizationType = unAgency.Entity }); var mop = context.Organizations.Add(new EFOrganization() { OrganizationName = "Ministry of Planning, Somalia", OrganizationType = federalGovt.Entity }); if (context.Users.Count() == 0) { context.Users.Add(new EFUser() { Email = "*****@*****.**", Password = "******", Organization = undp.Entity, RegistrationDate = DateTime.Now, IsApproved = true, UserType = UserTypes.Manager }); var superUser = context.Users.Add(new EFUser() { Email = "*****@*****.**", Password = "******", Organization = undp.Entity, RegistrationDate = DateTime.Now, IsApproved = true, UserType = UserTypes.Manager }); context.Users.Add(new EFUser() { Email = "*****@*****.**", Password = "******", Organization = undp.Entity, RegistrationDate = DateTime.Now, IsApproved = true, UserType = UserTypes.Standard }); context.Users.Add(new EFUser() { Email = "*****@*****.**", Password = "******", Organization = mop.Entity, RegistrationDate = DateTime.Now, IsApproved = true, UserType = UserTypes.Standard }); context.Users.Add(new EFUser() { Email = "*****@*****.**", Password = "******", Organization = undp.Entity, RegistrationDate = DateTime.Now, IsApproved = true, UserType = UserTypes.Standard }); context.Users.Add(new EFUser() { Email = "*****@*****.**", Password = "******", Organization = undp.Entity, RegistrationDate = DateTime.Now, IsApproved = true, UserType = UserTypes.Standard }); context.SaveChanges(); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } }