예제 #1
0
        public ActionResponse Add(SectorModel model)
        {
            using (var unitWork = new UnitOfWork(context))
            {
                ActionResponse response = new ActionResponse();
                IMessageHelper mHelper;
                try
                {
                    var sectorType = unitWork.SectorTypesRepository.GetByID(model.SectorTypeId);
                    if (sectorType == null)
                    {
                        mHelper          = new MessageHelper();
                        response.Message = mHelper.GetNotFound("Sector Type");
                        response.Success = false;
                        return(response);
                    }

                    var isSectorCreated = unitWork.SectorRepository.GetOne(s => s.SectorName.ToLower() == model.SectorName.ToLower() && s.SectorTypeId == sectorType.Id);
                    if (isSectorCreated != null)
                    {
                        response.ReturnedId = isSectorCreated.Id;
                    }
                    else
                    {
                        var      parentSector = unitWork.SectorRepository.GetByID(model.ParentId);
                        EFSector newSector    = null;

                        if (parentSector != null)
                        {
                            newSector = unitWork.SectorRepository.Insert(new EFSector()
                            {
                                SectorType   = sectorType,
                                ParentSector = parentSector,
                                SectorName   = model.SectorName,
                                IATICode     = model.IATICode,
                                TimeStamp    = DateTime.Now,
                            });
                        }
                        else
                        {
                            newSector = unitWork.SectorRepository.Insert(new EFSector()
                            {
                                SectorType = sectorType,
                                SectorName = model.SectorName,
                                IATICode   = model.IATICode,
                                TimeStamp  = DateTime.Now
                            });
                        }
                        unitWork.Save();
                        response.ReturnedId = newSector.Id;
                    }
                }
                catch (Exception ex)
                {
                    response.Success = false;
                    response.Message = ex.Message;
                }
                return(response);
            }
        }
예제 #2
0
 public SectorViewModel Get(int id)
 {
     using (var unitWork = new UnitOfWork(context))
     {
         var      sectorObj = unitWork.SectorRepository.GetWithInclude(c => c.Id == id, new string[] { "SectorType", "Category", "SubCategory" });
         EFSector sector    = null;
         foreach (var category in sectorObj)
         {
             sector = category;
         }
         return(mapper.Map <SectorViewModel>(sector));
     }
 }
예제 #3
0
        public async Task <ActionResponse> DeleteAsync(int id, int newId)
        {
            ActionResponse response = new ActionResponse();
            IMessageHelper mHelper;

            using (var unitWork = new UnitOfWork(context))
            {
                EFSector sector    = null;
                EFSector newSector = null;
                var      sectors   = await unitWork.SectorRepository.GetWithIncludeAsync(s => (s.Id == id || s.Id == newId), new string[] { "SectorType" });

                if (sectors.Count() < 2 && newId != 0)
                {
                    mHelper          = new MessageHelper();
                    response.Success = false;
                    response.Message = mHelper.GetNotFound("Sector");
                    return(await Task <ActionResponse> .Run(() => response).ConfigureAwait(false));
                }

                var sectorToDelete = (from s in sectors
                                      where s.Id == id
                                      select s).FirstOrDefault();

                if (sectorToDelete.IsUnAttributed)
                {
                    mHelper          = new MessageHelper();
                    response.Message = mHelper.UnattributedCannotBeDeleted("Sector");
                    response.Success = false;
                    return(response);
                }

                if (sectorToDelete != null)
                {
                    if (sectorToDelete.SectorType.IsSourceType)
                    {
                        mHelper          = new MessageHelper();
                        response.Message = mHelper.GetCannotBeDeleted("Sector imported from source");
                        response.Success = false;
                        return(response);
                    }
                }

                var projectSectors = await unitWork.ProjectSectorsRepository.GetManyQueryableAsync(s => (s.SectorId == id || s.SectorId == newId));

                var projectIds = (from s in projectSectors
                                  select s.ProjectId).Distinct().ToList <int>();
                if (projectIds.Count() > 0 && newId == 0)
                {
                    mHelper          = new MessageHelper();
                    response.Success = false;
                    response.Message = mHelper.GetDependentProjectsOnSectorMessage();
                    return(await Task <ActionResponse> .Run(() => response).ConfigureAwait(false));
                }

                var sectorsInDb = (from s in projectSectors
                                   select new SectorsKeyView()
                {
                    SectorId = s.SectorId,
                    ProjectId = s.ProjectId
                });
                projectSectors = (from s in projectSectors
                                  where s.SectorId == id
                                  select s);

                sector = (from s in sectors
                          where s.Id == id
                          select s).FirstOrDefault();

                newSector = (from s in sectors
                             where s.Id == newId
                             select s).FirstOrDefault();

                var           projects     = unitWork.ProjectRepository.GetWithInclude(p => projectIds.Contains(p.Id), new string[] { "CreatedBy" });
                List <string> projectNames = (from p in projects
                                              select p.Title).ToList <string>();
                var emails = (from p in projects
                              select p.CreatedBy.Email);
                try
                {
                    var strategy = context.Database.CreateExecutionStrategy();
                    await strategy.ExecuteAsync(async() =>
                    {
                        using (var transaction = context.Database.BeginTransaction())
                        {
                            List <EFProjectSectors> sectorsList = new List <EFProjectSectors>();
                            foreach (var projectSector in projectSectors)
                            {
                                var isExists = (from s in sectorsList
                                                where s.SectorId == newId && s.ProjectId == projectSector.ProjectId
                                                select s).FirstOrDefault();
                                var isExistsInDb = (from s in sectorsInDb
                                                    where s.SectorId == newId && s.ProjectId == projectSector.ProjectId
                                                    select s).FirstOrDefault();

                                if (isExists == null && isExistsInDb == null)
                                {
                                    sectorsList.Add(new EFProjectSectors()
                                    {
                                        SectorId        = newId,
                                        ProjectId       = projectSector.ProjectId,
                                        FundsPercentage = projectSector.FundsPercentage
                                    });
                                }
                                unitWork.ProjectSectorsRepository.Delete(projectSector);
                            }
                            await unitWork.SaveAsync();

                            unitWork.ProjectSectorsRepository.InsertMultiple(sectorsList);
                            await unitWork.SaveAsync();

                            unitWork.SectorRepository.Delete(sector);
                            await unitWork.SaveAsync();
                            transaction.Commit();

                            if (projectNames.Count > 0)
                            {
                                var users = unitWork.UserRepository.GetManyQueryable(u => u.UserType == UserTypes.Manager || u.UserType == UserTypes.SuperAdmin);
                                List <EmailAddress> emailAddresses = new List <EmailAddress>();
                                foreach (var user in users)
                                {
                                    emailAddresses.Add(new EmailAddress()
                                    {
                                        Email = user.Email
                                    });
                                }

                                foreach (var email in emails)
                                {
                                    var isEmailExists = (from e in emailAddresses
                                                         where e.Email.Equals(email, StringComparison.OrdinalIgnoreCase)
                                                         select e).FirstOrDefault();

                                    if (isEmailExists == null)
                                    {
                                        emailAddresses.Add(new EmailAddress()
                                        {
                                            Email = email
                                        });
                                    }
                                }

                                if (emailAddresses.Count > 0)
                                {
                                    ISMTPSettingsService smtpService = new SMTPSettingsService(context);
                                    var smtpSettings = smtpService.GetPrivate();
                                    SMTPSettingsModel smtpSettingsModel = new SMTPSettingsModel();
                                    if (smtpSettings != null)
                                    {
                                        smtpSettingsModel.Host       = smtpSettings.Host;
                                        smtpSettingsModel.Port       = smtpSettings.Port;
                                        smtpSettingsModel.Username   = smtpSettings.Username;
                                        smtpSettingsModel.Password   = smtpSettings.Password;
                                        smtpSettingsModel.AdminEmail = smtpSettings.AdminEmail;
                                        smtpSettingsModel.SenderName = smtpSettings.SenderName;
                                    }

                                    string subject   = "", message = "", footerMessage = "";
                                    var emailMessage = unitWork.EmailMessagesRepository.GetOne(m => m.MessageType == EmailMessageType.ChangedMappingEffectedProject);
                                    if (emailMessage != null)
                                    {
                                        subject       = emailMessage.Subject;
                                        message       = emailMessage.Message;
                                        footerMessage = emailMessage.FooterMessage;
                                    }

                                    mHelper = new MessageHelper();
                                    string oldSectorName = sector != null ? sector.SectorName : null;
                                    string newSectorName = newSector != null ? newSector.SectorName : null;
                                    message += mHelper.ChangedMappingAffectedProjectsMessage(projectNames, oldSectorName, newSectorName);
                                    IEmailHelper emailHelper = new EmailHelper(smtpSettingsModel.AdminEmail, smtpSettings.SenderName, smtpSettingsModel);
                                    emailHelper.SendEmailToUsers(emailAddresses, subject, "", message);
                                }
                            }
                        }
                    });
                }
                catch (Exception ex)
                {
                    response.Success = false;
                    response.Message = ex.Message;
                }
            }
            return(await Task <ActionResponse> .Run(() => response).ConfigureAwait(false));
        }
예제 #4
0
        public ActionResponse AddSectorWithMapping(MappingSectorModel model)
        {
            using (var unitWork = new UnitOfWork(context))
            {
                ActionResponse response = new ActionResponse();
                IMessageHelper mHelper;
                try
                {
                    EFSector primarySector = null;
                    var      sectorType    = unitWork.SectorTypesRepository.GetOne(s => s.Id == model.SectorTypeId);
                    if (sectorType == null)
                    {
                        mHelper          = new MessageHelper();
                        response.Message = mHelper.GetNotFound("Sector Type");
                        response.Success = false;
                        return(response);
                    }

                    if (model.SectorId != 0)
                    {
                        primarySector = unitWork.SectorRepository.GetOne(s => s.Id == model.SectorId);
                    }
                    else
                    {
                        primarySector = unitWork.SectorRepository.GetOne(s => s.SectorName.ToLower() == model.SectorName.ToLower().Trim());
                    }

                    if (primarySector != null)
                    {
                        response.ReturnedId = primarySector.Id;
                    }
                    else
                    {
                        var      parentSector = unitWork.SectorRepository.GetByID(model.ParentId);
                        EFSector newSector    = null;

                        if (parentSector != null)
                        {
                            newSector = unitWork.SectorRepository.Insert(new EFSector()
                            {
                                SectorType   = sectorType,
                                ParentSector = parentSector,
                                SectorName   = model.SectorName.Trim(),
                                IATICode     = model.IATICode,
                                TimeStamp    = DateTime.Now,
                            });
                        }
                        else
                        {
                            newSector = unitWork.SectorRepository.Insert(new EFSector()
                            {
                                SectorType = sectorType,
                                SectorName = model.SectorName,
                                IATICode   = model.IATICode,
                                TimeStamp  = DateTime.Now
                            });
                        }
                        unitWork.Save();
                        response.ReturnedId = newSector.Id;
                    }

                    EFSectorMappings mapping = unitWork.SectorMappingsRepository.Get(m => m.SectorId == response.ReturnedId && m.MappedSectorId == model.MappingSectorId);
                    if (mapping == null)
                    {
                        mapping = new EFSectorMappings()
                        {
                            SectorId       = response.ReturnedId,
                            SectorTypeId   = sectorType.Id,
                            MappedSectorId = model.MappingSectorId
                        };
                        unitWork.SectorMappingsRepository.Insert(mapping);
                        unitWork.Save();
                    }
                }
                catch (Exception ex)
                {
                    response.Success = false;
                    response.Message = ex.Message;
                }
                return(response);
            }
        }
예제 #5
0
        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);
            }
        }