Ejemplo n.º 1
0
        public void Seed()
        {
            // Add the tokens
            var fanArt = ApplicationConfigurations.FirstOrDefault(x => x.Type == ConfigurationTypes.FanartTv);

            if (fanArt == null)
            {
                ApplicationConfigurations.Add(new ApplicationConfiguration
                {
                    Type  = ConfigurationTypes.FanartTv,
                    Value = "4b6d983efa54d8f45c68432521335f15"
                });
                SaveChanges();
            }
            var movieDb = ApplicationConfigurations.FirstOrDefault(x => x.Type == ConfigurationTypes.FanartTv);

            if (movieDb == null)
            {
                ApplicationConfigurations.Add(new ApplicationConfiguration
                {
                    Type  = ConfigurationTypes.TheMovieDb,
                    Value = "b8eabaf5608b88d0298aa189dd90bf00"
                });
                SaveChanges();
            }
            var notification = ApplicationConfigurations.FirstOrDefault(x => x.Type == ConfigurationTypes.Notification);

            if (notification == null)
            {
                ApplicationConfigurations.Add(new ApplicationConfiguration
                {
                    Type  = ConfigurationTypes.Notification,
                    Value = "4f0260c4-9c3d-41ab-8d68-27cb5a593f0e"
                });
                SaveChanges();
            }

            // VACUUM;
            Database.ExecuteSqlCommand("VACUUM;");

            // Make sure we have the roles
            var roles = Roles.Where(x => x.Name == OmbiRoles.RecievesNewsletter);

            if (!roles.Any())
            {
                Roles.Add(new IdentityRole(OmbiRoles.RecievesNewsletter)
                {
                    NormalizedName = OmbiRoles.RecievesNewsletter.ToUpper()
                });
                SaveChanges();
            }

            // Make sure we have the API User
            var apiUserExists = Users.Any(x => x.UserName.Equals("Api", StringComparison.CurrentCultureIgnoreCase));

            if (!apiUserExists)
            {
                Users.Add(new OmbiUser
                {
                    UserName           = "******",
                    UserType           = UserType.SystemUser,
                    NormalizedUserName = "******",
                });
                SaveChanges();
            }

            //Check if templates exist
            var templates = NotificationTemplates.ToList();

            var allAgents = Enum.GetValues(typeof(NotificationAgent)).Cast <NotificationAgent>().ToList();
            var allTypes  = Enum.GetValues(typeof(NotificationType)).Cast <NotificationType>().ToList();

            foreach (var agent in allAgents)
            {
                foreach (var notificationType in allTypes)
                {
                    if (templates.Any(x => x.Agent == agent && x.NotificationType == notificationType))
                    {
                        // We already have this
                        continue;
                    }
                    NotificationTemplates notificationToAdd;
                    switch (notificationType)
                    {
                    case NotificationType.NewRequest:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello! The user '{UserName}' has requested the {Type} '{Title}'! Please log in to approve this request. Request Date: {RequestedDate}",
                            Subject          = "{ApplicationName}: New {Type} request for {Title}!",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.Issue:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello! The user '{UserName}' has reported a new issue for the title {Title}! </br> {IssueCategory} - {IssueSubject} : {IssueDescription}",
                            Subject          = "{ApplicationName}: New issue for {Title}!",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.RequestAvailable:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello! You   {Title} on {ApplicationName}! This is now available! :)",
                            Subject          = "{ApplicationName}: {Title} is now available!",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.RequestApproved:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello! Your request for {Title} has been approved!",
                            Subject          = "{ApplicationName}: your request has been approved",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.Test:
                        continue;

                    case NotificationType.RequestDeclined:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello! Your request for {Title} has been declined, Sorry!",
                            Subject          = "{ApplicationName}: your request has been declined",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.ItemAddedToFaultQueue:
                        continue;

                    case NotificationType.WelcomeEmail:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello! You have been invited to use {ApplicationName}! You can login here: {ApplicationUrl}",
                            Subject          = "Invite to {ApplicationName}",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.IssueResolved:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello {UserName} Your issue for {Title} has now been resolved.",
                            Subject          = "{ApplicationName}: Issue has been resolved for {Title}!",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.IssueComment:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello, There is a new comment on your issue {IssueSubject}, The comment is: {NewIssueComment}",
                            Subject          = "{ApplicationName}: New comment on issue {IssueSubject}!",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.AdminNote:
                        continue;

                    case NotificationType.Newsletter:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Here is a list of Movies and TV Shows that have recently been added!",
                            Subject          = "{ApplicationName}: Recently Added Content!",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                    NotificationTemplates.Add(notificationToAdd);
                }
            }
            SaveChanges();
        }
Ejemplo n.º 2
0
        public void Seed()
        {
            // Make sure we have the API User
            var apiUserExists = Users.Any(x => x.UserName.Equals("Api", StringComparison.CurrentCultureIgnoreCase));

            if (!apiUserExists)
            {
                Users.Add(new OmbiUser
                {
                    UserName           = "******",
                    UserType           = UserType.SystemUser,
                    NormalizedUserName = "******",
                });
                SaveChanges();
            }

            //Check if templates exist
            var templates = NotificationTemplates.ToList();

            var allAgents = Enum.GetValues(typeof(NotificationAgent)).Cast <NotificationAgent>().ToList();
            var allTypes  = Enum.GetValues(typeof(NotificationType)).Cast <NotificationType>().ToList();

            foreach (var agent in allAgents)
            {
                foreach (var notificationType in allTypes)
                {
                    if (templates.Any(x => x.Agent == agent && x.NotificationType == notificationType))
                    {
                        // We already have this
                        continue;
                    }
                    NotificationTemplates notificationToAdd;
                    switch (notificationType)
                    {
                    case NotificationType.NewRequest:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello! The user '{UserName}' has requested the {Type} '{Title}'! Please log in to approve this request. Request Date: {RequestedDate}",
                            Subject          = "{ApplicationName}: New {Type} request for {Title}!",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.Issue:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello! The user '{UserName}' has reported a new issue for the title {Title}! </br> {IssueCategory} - {IssueSubject} : {IssueDescription}",
                            Subject          = "{ApplicationName}: New issue for {Title}!",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.RequestAvailable:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello! Your request for {Title} on {ApplicationName}! This is now available! :)",
                            Subject          = "{ApplicationName}: {Title} is now available!",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.RequestApproved:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello! Your request for {Title} has been approved!",
                            Subject          = "{ApplicationName}: your request has been approved",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.Test:
                        continue;

                    case NotificationType.RequestDeclined:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello! Your request for {Title} has been declined, Sorry!",
                            Subject          = "{ApplicationName}: your request has been declined",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.ItemAddedToFaultQueue:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello! The user '{UserName}' has requested {Title} but it could not be added. This has been added into the requests queue and will keep retrying",
                            Subject          = "Item Added To Retry Queue",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.WelcomeEmail:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello! You have been invited to use {ApplicationName}! You can login here: {ApplicationUrl}",
                            Subject          = "Invite to {ApplicationName}",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.IssueResolved:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello {UserName} Your issue for {Title} has now been resolved.",
                            Subject          = "{ApplicationName}: Issue has been resolved for {Title}!",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.IssueComment:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello, There is a new comment on your issue {IssueSubject}, The comment is: {NewIssueComment}",
                            Subject          = "{ApplicationName}: New comment on issue {IssueSubject}!",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.AdminNote:
                        continue;

                    case NotificationType.Newsletter:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Here is a list of Movies and TV Shows that have recently been added!",
                            Subject          = "{ApplicationName}: Recently Added Content!",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                    NotificationTemplates.Add(notificationToAdd);
                }
            }
            SaveChanges();
        }
Ejemplo n.º 3
0
        public void Seed()
        {
            var strat = Database.CreateExecutionStrategy();

            strat.Execute(() =>
            {
                using (var tran = Database.BeginTransaction())
                {
                    // Make sure we have the API User
                    var apiUserExists = Users.ToList().Any(x => x.NormalizedUserName == "API");
                    if (!apiUserExists)
                    {
                        Users.Add(new OmbiUser
                        {
                            UserName           = "******",
                            UserType           = UserType.SystemUser,
                            NormalizedUserName = "******",
                            StreamingCountry   = "US"
                        });
                        SaveChanges();
                        tran.Commit();
                    }
                }
            });

            //Check if templates exist
            var templates = NotificationTemplates.ToList();

            var allAgents = Enum.GetValues(typeof(NotificationAgent)).Cast <NotificationAgent>().ToList();
            var allTypes  = Enum.GetValues(typeof(NotificationType)).Cast <NotificationType>().ToList();

            var needToSave = false;

            foreach (var agent in allAgents)
            {
                foreach (var notificationType in allTypes)
                {
                    if (templates.Any(x => x.Agent == agent && x.NotificationType == notificationType))
                    {
                        // We already have this
                        continue;
                    }

                    needToSave = true;
                    NotificationTemplates notificationToAdd = null;
                    switch (notificationType)
                    {
                    case NotificationType.NewRequest:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello! The user '{UserName}' has requested the {Type} '{Title}'! Please log in to approve this request. Request Date: {RequestedDate}",
                            Subject          = "{ApplicationName}: New {Type} request for {Title}!",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.Issue:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello! The user '{UserName}' has reported a new issue for the title {Title}! </br> {IssueCategory} - {IssueSubject} : {IssueDescription}",
                            Subject          = "{ApplicationName}: New issue for {Title}!",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.RequestAvailable:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello! Your request for {Title} on {ApplicationName} is now available! :)",
                            Subject          = "{ApplicationName}: {Title} is now available!",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.RequestApproved:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello! Your request for {Title} has been approved!",
                            Subject          = "{ApplicationName}: your request has been approved",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.Test:
                        continue;

                    case NotificationType.RequestDeclined:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello! Your request for {Title} has been declined, Sorry!",
                            Subject          = "{ApplicationName}: your request has been declined",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.ItemAddedToFaultQueue:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello! The user '{UserName}' has requested {Title} but it could not be added. This has been added into the requests queue and will keep retrying",
                            Subject          = "Item Added To Retry Queue",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.WelcomeEmail:
                        if (agent == NotificationAgent.Email)
                        {
                            notificationToAdd = new NotificationTemplates
                            {
                                NotificationType = notificationType,
                                Message          = "Hello! You have been invited to use {ApplicationName}! You can login here: {ApplicationUrl}",
                                Subject          = "Invite to {ApplicationName}",
                                Agent            = agent,
                                Enabled          = true,
                            };
                        }
                        break;

                    case NotificationType.IssueResolved:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello {UserName} Your issue for {Title} has now been resolved.",
                            Subject          = "{ApplicationName}: Issue has been resolved for {Title}!",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.IssueComment:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Hello, There is a new comment on your issue {IssueSubject}, The comment is: {NewIssueComment}",
                            Subject          = "{ApplicationName}: New comment on issue {IssueSubject}!",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.AdminNote:
                        continue;

                    case NotificationType.Newsletter:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Here is a list of Movies and TV Shows that have recently been added!",
                            Subject          = "{ApplicationName}: Recently Added Content!",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    case NotificationType.PartiallyAvailable:
                        notificationToAdd = new NotificationTemplates
                        {
                            NotificationType = notificationType,
                            Message          = "Your TV request is now partially available! Season {PartiallyAvailableSeasonNumber} Episodes {PartiallyAvailableEpisodeNumbers}!",
                            Subject          = "{ApplicationName}: Partially Available Request!",
                            Agent            = agent,
                            Enabled          = true,
                        };
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                    if (notificationToAdd != null)
                    {
                        NotificationTemplates.Add(notificationToAdd);
                    }
                }
            }

            if (needToSave)
            {
                strat.Execute(() =>
                {
                    using (var tran = Database.BeginTransaction())
                    {
                        SaveChanges();
                        tran.Commit();
                    }
                });
            }
        }