Example #1
0
        public void SetApplicationNotification(ProjectNotification notif, bool enable)
        {
            if ((notif & ProjectNotification.AdminNotificationMask) != 0)
            {
                CheckIsAdmin();
            }

            UserApplication up = db.SelectObjectWhere <UserApplication> ("UserId={0} AND ApplicationId={1}", user.Id, application.Id);

            if (enable)
            {
                if (up == null)
                {
                    up = new UserApplication()
                    {
                        UserId = user.Id, ApplicationId = application.Id, ProjectNotifications = notif
                    };
                    db.InsertObject <UserApplication> (up);
                }
                else
                {
                    up.ProjectNotifications |= notif;
                    db.UpdateObject(up);
                }
            }
            else if (up != null)
            {
                up.ProjectNotifications &= ~notif;
                db.UpdateObject(up);
            }
        }
Example #2
0
        IEnumerable <string> GetUsersToNotify(int projectId, ProjectNotification notif)
        {
            HashSet <string> emails = new HashSet <string> ();

            // Users with the notification flag for the project
            var users = db.SelectObjects <User> (
                "SELECT User.* FROM User, UserProject WHERE " +
                "User.Id = UserProject.UserId AND " +
                "UserProject.ProjectId={0} AND Notifications & {1} = {2}", projectId, (int)notif, (int)notif);

            emails.UnionWith(users.Select(u => u.Email));

            // Notification to be sent to project owners
            users = db.SelectObjects <User> (
                "SELECT User.* FROM User, UserApplication, UserProject WHERE " +
                "User.Id = UserApplication.UserId AND " +
                "User.Id = UserProject.UserId AND " +
                "UserProject.ProjectId = {0} AND " +
                "UserApplication.ApplicationId = {1} AND " +
                "UserProject.Permissions & 1 = 1 AND " +
                "UserApplication.ProjectNotifications & {2} = {3}", projectId, application.Id, (int)notif, (int)notif);
            emails.UnionWith(users.Select(u => u.Email));

            return(emails);
        }
Example #3
0
        /// <summary>
        /// Adds the user.
        /// </summary>
        /// <param name="s">The s.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void AddProjectNotification(Object s, EventArgs e)
        {
            //The users must be added to a list first because the collection can not
            //be modified while we iterate through it.
            var usersToAdd = lstAllProjects.Items.Cast <ListItem>().Where(item => item.Selected).ToList();

            foreach (var item in usersToAdd)
            {
                var notification = new ProjectNotification
                {
                    ProjectId            = Convert.ToInt32(item.Value),
                    NotificationUsername = Security.GetUserName()
                };

                if (!ProjectNotificationManager.SaveOrUpdate(notification))
                {
                    continue;
                }

                lstSelectedProjects.Items.Add(item);
                lstAllProjects.Items.Remove(item);
            }

            lstSelectedProjects.SelectedIndex = -1;
        }
Example #4
0
        public List <NotificationInfo> GetProjectNotifications(int projectId)
        {
            ProjectNotification notifs = (ProjectNotification)0;
            UserProject         up     = db.SelectObjectWhere <UserProject> ("UserId={0} AND ProjectId={1}", User.Id, projectId);

            if (up != null)
            {
                notifs = up.Notifications;
            }

            List <NotificationInfo> list = new List <NotificationInfo> ();

            list.Add(new NotificationInfo("New Add-in Release", ProjectNotification.NewRelease, notifs));

            if (CanManageProject(projectId))
            {
                list.Add(new NotificationInfo("Build Success", ProjectNotification.BuildSuccess, notifs));
                list.Add(new NotificationInfo("Build Error", ProjectNotification.BuildError, notifs));
            }

            if (IsAdmin)
            {
                list.Add(new NotificationInfo("Description Changed", ProjectNotification.DescriptionChage, notifs));
                list.Add(new NotificationInfo("Release Publish Request", ProjectNotification.PublishReleaseRequest, notifs));
            }
            return(list);
        }
Example #5
0
        public void ProjectUserChange(Project project, List <ApplicationUser> OldUserList)
        {
            var addedUsers   = project.Users.Except(OldUserList);
            var removedUsers = OldUserList.Except(project.Users);

            foreach (var user in addedUsers)
            {
                var newNotification = new ProjectNotification()
                {
                    ProjectId        = project.Id,
                    UserId           = user.Id,
                    Created          = DateTime.Now,
                    Icon             = "fa-sitemap",
                    NotificationType = "success",
                    Subject          = $"Added to Project: {project.Name}",
                    Message          = $"Hello, {user.FullName} you have been Added to the project: {project.Name}",
                };
                db.Notifications.Add(newNotification);
            }
            foreach (var user in removedUsers)
            {
                var newNotification = new ProjectNotification()
                {
                    ProjectId        = project.Id,
                    UserId           = user.Id,
                    Created          = DateTime.Now,
                    Icon             = "fa-sitemap",
                    NotificationType = "warning",
                    Subject          = $"Removed from Project: {project.Name}",
                    Message          = $"Hello, {user.FullName} you have been removed from the project: {project.Name}",
                };
                db.Notifications.Add(newNotification);
            }
        }
Example #6
0
        private void SaveNotification(Notification notification, Project project)
        {
            ProjectNotification projNotification = new ProjectNotification();

            projNotification.NotificationDate = DateTime.Now;
            projNotification.Build            = notification.build;
            project.ProjectNotifications.Add(projNotification);
            database.SaveChanges();
        }
Example #7
0
        public ActionResult SetNotification(int id, string notif, string value)
        {
            if (!notif.StartsWith("notify-"))
            {
                return(Content("Unknown notification"));
            }
            ProjectNotification pnot = (ProjectNotification)Enum.Parse(typeof(ProjectNotification), notif.Substring(7));

            CurrentUserModel.SetProjectNotification(pnot, id, value == "true");
            return(Content("OK"));
        }
 public ActionResult Edit([Bind(Include = "Id,ProjectId,UserId,NotificationBody,Created,Unread")] ProjectNotification projectNotification)
 {
     if (ModelState.IsValid)
     {
         db.Entry(projectNotification).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProjectId = new SelectList(db.Projects, "Id", "Name", projectNotification.ProjectId);
     ViewBag.UserId    = new SelectList(db.Users, "Id", "FirstName", projectNotification.UserId);
     return(View(projectNotification));
 }
Example #9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        BusinessEntity.PushStaticConnectionString();

        try
        {
            BusinessEntity.StaticConnectionString = ConfigurationSettings.AppSettings["dbConnection"];

            DL_WEB.DAL.Master.Database oDatabase = new DL_WEB.DAL.Master.Database();
            oDatabase.LoadByPrimaryKey(DatabaseID);

            BusinessEntity.StaticConnectionString = oDatabase.DBConnectionString;

            AddressBook oAddressBook = new AddressBook();
            oAddressBook.LoadAddressBookByPrimaryKey(AddressBookID);

            if (0 == oAddressBook.GUID.ToString().CompareTo(GUID))
            {
                oAddressBook.IsApproved = true;

                NotificationType oNotificationType = new NotificationType();
                oNotificationType.Where.IsClientUpdate.Value = true;
                oNotificationType.Query.Load();

                do
                {
                    ProjectNotification oProjectNotification = new ProjectNotification();
                    oProjectNotification.AddNew();
                    oProjectNotification.AddressBookEntryID = oAddressBook.EntryID;
                    oProjectNotification.ProjectID          = oAddressBook.ProjectID;
                    oProjectNotification.NotificationTypeID = oNotificationType.NotificationTypeID;

                    oProjectNotification.Save();
                } while (oNotificationType.MoveNext());

                oAddressBook.Save();
            }
            else
            {
                MultiView1.ActiveViewIndex = 1;
            }
            MultiView1.ActiveViewIndex = 0;
        }
        catch (Exception)
        {
            MultiView1.ActiveViewIndex = 1;
        }
        finally
        {
            BusinessEntity.PopStaticConnectionString();
        }
    }
Example #10
0
        public List <NotificationInfo> GetApplicationNotifications()
        {
            ApplicationNotification notifs        = (ApplicationNotification)0;
            ProjectNotification     projectNotifs = (ProjectNotification)0;

            UserApplication uap = db.SelectObjectWhere <UserApplication> ("UserId={0} AND ApplicationId={1}", User.Id, application.Id);

            if (uap != null)
            {
                notifs        = uap.Notifications;
                projectNotifs = uap.ProjectNotifications;
            }

            List <NotificationInfo> list = new List <NotificationInfo> ();
            bool hasProjects             = OwnedProjects.Count > 0;

            if (hasProjects)
            {
                list.Add(new NotificationInfo("Global Notifications"));
            }

            list.Add(new NotificationInfo("New Add-in", ApplicationNotification.FirstProjectRelease, notifs));
            list.Add(new NotificationInfo("New Add-in Release", ApplicationNotification.ProjectNewRelease, notifs));

            if (IsAdmin)
            {
                list.Add(new NotificationInfo("Build Success", ApplicationNotification.ProjectBuildSuccess, notifs));
                list.Add(new NotificationInfo("Build Error", ApplicationNotification.ProjectBuildError, notifs));
                list.Add(new NotificationInfo("Project Created", ApplicationNotification.NewProject, notifs));
                list.Add(new NotificationInfo("Project Deleted", ApplicationNotification.DeleteProject, notifs));
                list.Add(new NotificationInfo("Description Changed", ApplicationNotification.ProjectDescriptionChage, notifs));
                list.Add(new NotificationInfo("Release Publish Request", ApplicationNotification.ProjectPublishReleaseRequest, notifs));
            }

            if (IsSiteAdmin)
            {
                list.Add(new NotificationInfo("New User", SiteNotification.NewUser, User.SiteNotifications));
                list.Add(new NotificationInfo("Build Bot Error", SiteNotification.BuildBotError, User.SiteNotifications));
            }

            if (hasProjects)
            {
                list.Add(new NotificationInfo("Owned Project Notifications"));
                list.Add(new NotificationInfo("Release Published", ProjectNotification.NewRelease, projectNotifs));
                list.Add(new NotificationInfo("Build Success", ProjectNotification.BuildSuccess, projectNotifs));
                list.Add(new NotificationInfo("Build Error", ProjectNotification.BuildError, projectNotifs));
            }
            return(list);
        }
Example #11
0
        public void AddProjectUnassignmentNotification(int projectId, string oldUser)
        {
            var properProjectName = db.Projects.FirstOrDefault(t => t.Id == projectId).Name;
            var oldNotification   = new ProjectNotification
            {
                Created          = DateTimeOffset.UtcNow.ToLocalTime(),
                ProjectId        = projectId,
                Unread           = true,
                UserId           = oldUser,
                NotificationBody = $"You have been unassigned from project '{properProjectName}'."
            };

            db.ProjectNotifications.Add(oldNotification);
            db.SaveChanges();
        }
Example #12
0
        protected void AddProjectNotification <T>(AppDbContext context, string message, T project) where T : ProjectOutput, IBasicEmail, new()
        {
            var projectNotification = new ProjectNotification()
            {
                RequiresAcknowledgement = false,
                OrganizationId          = project.TargetOrganizationId,
                UserId    = project.TargetPersonId,
                ProjectId = project.Id,
                Message   = message,
                Url       = project.GetProjectUrl(project)
            };

            context.ProjectNotifications.Add(projectNotification);

            var result = context.SaveChanges(true);

            _logger.LogDebug(GetLogMessage("{0} results updated"), result);
        }
Example #13
0
        public void NewProjectCreated(Project project)
        {
            var userId = projectHelper.ListUserOnProjectInRole(project.Id, "ProjectManager").FirstOrDefault().Id;

            foreach (var user in project.Users.Where(u => u.Id != userId))
            {
                var newNotification = new ProjectNotification()
                {
                    ProjectId        = project.Id,
                    UserId           = user.Id,
                    Created          = DateTime.Now,
                    Icon             = "fa-sitemap",
                    NotificationType = "success",
                    Subject          = $"Added to Project Id: {project.Id}",
                    Message          = $"Hello, {user.FullName} you have been Added to the project: {project.Name}",
                };
                db.Notifications.Add(newNotification);
            }
        }
        public void NewProjectCreated(Project project)
        {
            var userId = HttpContext.Current.User.Identity.GetUserId();

            foreach (var user in project.Users.Where(u => u.Id != userId))
            {
                var newNotification = new ProjectNotification()
                {
                    ProjectId        = project.Id,
                    UserId           = user.Id,
                    Created          = DateTime.Now,
                    Icon             = "fa-sitemap",
                    Subject          = $"Added to Project Id: {project.Id}",
                    Message          = $"Hello, {user.FullName} you have been Added to the project: {project.Name}",
                    NotificationType = "danger"
                };
                db.Notifications.Add(newNotification);
            }
            db.SaveChanges();
        }
Example #15
0
        /// <summary>
        /// Saves this instance.
        /// </summary>
        /// <returns></returns>
        public static bool SaveOrUpdate(ProjectNotification entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (entity.ProjectId <= Globals.NEW_ID)
            {
                throw (new ArgumentException("Cannot save notification, the project id is invalid"));
            }

            var tempId = DataProviderManager.Provider.CreateNewProjectNotification(entity);

            if (tempId <= 0)
            {
                return(false);
            }
            entity.Id = tempId;
            return(true);
        }
Example #16
0
        public void SuggestMems(string UserID)
        {
            int Id = Convert.ToInt32(UserID);

            string UserOnline = HttpContext.Session["Uname"].ToString();

            UserModel user   = db.Umodel.Single(id1 => id1.id == Id);
            UserModel member = db.Umodel.Single(id1 => id1.Username == UserOnline);

            ProjectNotification pn = new ProjectNotification();

            try
            {
                ProjectNotification pn2 = db.ProjNot.First();
                pn2    = db.ProjNot.OrderByDescending(nid => nid.Nid).First(); // getting the last row of Project Notification Table
                pn.Nid = pn2.Nid + 1;                                          // auto incrementing the Notification ID
                //  Debug.WriteLine("rrrrrrrrrrrrrrr");
            }
            catch (System.InvalidOperationException e)
            {
                //  Debug.WriteLine("eeeeeeeeeeeeeee");
                pn.Nid = 1;
            }



            pn.Pid        = member.CurrentProj;
            pn.Visibility = "PLeader";
            pn.MemSug     = user.Username;

            if (ModelState.IsValid)
            {
                db.ProjNot.Add(pn);
                db.SaveChanges();
            }
        }
Example #17
0
        public void SetProjectNotification(ProjectNotification notif, int projectId, bool enable)
        {
            if ((notif & ProjectNotification.OwnerNotificationMask) != 0)
            {
                ValidateProject(projectId);
            }

            if ((notif & ProjectNotification.AdminNotificationMask) != 0)
            {
                CheckIsAdmin();
            }

            UserProject up = db.SelectObject <UserProject> ("SELECT * FROM UserProject WHERE UserId={0} AND ProjectId={1}", user.Id, projectId);

            if (enable)
            {
                if (up == null)
                {
                    up = new UserProject()
                    {
                        UserId = user.Id, ProjectId = projectId, Notifications = notif
                    };
                    db.InsertObject <UserProject> (up);
                }
                else
                {
                    up.Notifications |= notif;
                    db.UpdateObject(up);
                }
            }
            else if (up != null)
            {
                up.Notifications &= ~notif;
                db.UpdateObject(up);
            }
        }
Example #18
0
        public void SetProjectNotification(ProjectNotification notif, int projectId, bool enable)
        {
            if ((notif & ProjectNotification.OwnerNotificationMask) != 0)
                ValidateProject (projectId);

            if ((notif & ProjectNotification.AdminNotificationMask) != 0)
                CheckIsAdmin ();

            UserProject up = db.SelectObject<UserProject> ("SELECT * FROM UserProject WHERE UserId={0} AND ProjectId={1}", user.Id, projectId);
            if (enable) {
                if (up == null) {
                    up = new UserProject () { UserId = user.Id, ProjectId = projectId, Notifications = notif };
                    db.InsertObject<UserProject> (up);
                }
                else {
                    up.Notifications |= notif;
                    db.UpdateObject (up);
                }
            } else if (up != null) {
                up.Notifications &= ~notif;
                db.UpdateObject (up);
            }
        }
Example #19
0
        protected override void Seed(BugTracker.Models.ApplicationDbContext context)
        {
            UserRoleHelper roleHelper    = new UserRoleHelper();
            ProjectHelper  projectHelper = new ProjectHelper();
            TicketHelper   ticketHelper  = new TicketHelper();
            SeedHelper     seedHelper    = new SeedHelper();
            var            rand          = new Random();

            #region User Roles

            var roleManager = new RoleManager <IdentityRole>(
                new RoleStore <IdentityRole>(context));
            if (!context.Roles.Any(r => r.Name == "Admin"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "Admin"
                });
            }
            if (!context.Roles.Any(r => r.Name == "Moderator"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "Moderator"
                });
            }
            if (!context.Roles.Any(r => r.Name == "ProjectManager"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "ProjectManager"
                });
            }
            if (!context.Roles.Any(r => r.Name == "Submitter"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "Submitter"
                });
            }
            if (!context.Roles.Any(r => r.Name == "Developer"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "Developer"
                });
            }
            if (!context.Roles.Any(r => r.Name == "No-Role"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "Default"
                });
            }
            #endregion
            #region demo-roles
            if (!context.Roles.Any(r => r.Name == "Demo-Admin"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "Demo-Admin"
                });
            }
            if (!context.Roles.Any(r => r.Name == "Demo-Moderator"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "Demo-Moderator"
                });
            }
            if (!context.Roles.Any(r => r.Name == "Demo-ProjectManager"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "Demo-ProjectManager"
                });
            }
            if (!context.Roles.Any(r => r.Name == "Demo-Submitter"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "Demo-Submitter"
                });
            }
            if (!context.Roles.Any(r => r.Name == "Demo-Developer"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "Demo-Developer"
                });
            }
            #endregion
            context.SaveChanges();
            #region TicketType Seed
            context.TicketTypes.AddOrUpdate(
                tt => tt.Name,
                new TicketType()
            {
                Name = "Software"
            },
                new TicketType()
            {
                Name = "Hardware"
            },
                new TicketType()
            {
                Name = "UI"
            },
                new TicketType()
            {
                Name = "Defect"
            },
                new TicketType()
            {
                Name = "Feature Request"
            },
                new TicketType()
            {
                Name = "Other"
            }
                );

            #endregion
            #region TicketPriority Seed
            context.TicketPriorities.AddOrUpdate(
                tp => tp.Name,
                new TicketPriority()
            {
                Name = "Low"
            },
                new TicketPriority()
            {
                Name = "Medium"
            },
                new TicketPriority()
            {
                Name = "High"
            },
                new TicketPriority()
            {
                Name = "On Hold"
            }
                );
            #endregion
            #region TicketStatus Seed
            context.TicketStatuses.AddOrUpdate(
                ts => ts.Name,
                new TicketStatus()
            {
                Name = "Open"
            },
                new TicketStatus()
            {
                Name = "Assigned"
            },
                new TicketStatus()
            {
                Name = "Resolved"
            },
                new TicketStatus()
            {
                Name = "Reopened"
            },
                new TicketStatus()
            {
                Name = "Archived"
            }
                );
            #endregion
            #region Project Seed
            context.Projects.AddOrUpdate(
                p => p.Name,
                new Project()
            {
                Name = "User Interface for Banking", Created = DateTime.Now.AddDays(-60), DueDate = DateTime.Now.AddDays(-10), IsArchive = true
            },
                new Project()
            {
                Name = "Commercial Blog Site", Created = DateTime.Now.AddDays(-10), DueDate = DateTime.Now.AddDays(+100)
            },
                new Project()
            {
                Name = "Financial API", Created = DateTime.Now.AddDays(-45), DueDate = DateTime.Now.AddDays(+100)
            },
                new Project()
            {
                Name = "Sunset Light calculator", Created = DateTime.Now.AddDays(-30), DueDate = DateTime.Now.AddDays(+100)
            },
                new Project()
            {
                Name = "Factorial Calculator", Created = DateTime.Now.AddDays(-4), DueDate = DateTime.Now.AddDays(+100)
            },
                new Project()
            {
                Name = "Movie Comparer", Created = DateTime.Now.AddDays(-60), DueDate = DateTime.Now.AddDays(-10), IsArchive = true
            },
                new Project()
            {
                Name = "Fizz Buzz", Created = DateTime.Now.AddDays(-10), DueDate = DateTime.Now.AddDays(+100)
            },
                new Project()
            {
                Name = "Tacos and Cats", Created = DateTime.Now.AddDays(-45), DueDate = DateTime.Now.AddDays(+100)
            },
                new Project()
            {
                Name = "Fear the sums", Created = DateTime.Now.AddDays(-30), DueDate = DateTime.Now.AddDays(+100)
            },
                new Project()
            {
                Name = "Finacial portal", Created = DateTime.Now.AddDays(-4), DueDate = DateTime.Now.AddDays(+100)
            }
                );
            #endregion
            context.SaveChanges();
            #region user seed
            var userManager = new UserManager <ApplicationUser>(
                new UserStore <ApplicationUser>(context));
            if (!context.Users.Any(u => u.Email == "*****@*****.**"))
            {
                userManager.Create(new ApplicationUser()
                {
                    Email       = "*****@*****.**",
                    UserName    = "******",
                    FirstName   = "Andrew",
                    LastName    = "Russell",
                    AvatarPath  = "/Avatars/DemoUserAvatars/1.jpg",
                    PhoneNumber = "(111)111-1111"
                },
                                   "HelloNurse!");
            }
            var userId = userManager.FindByEmail("*****@*****.**").Id;
            userManager.AddToRole(userId, "ProjectManager");


            if (!context.Users.Any(u => u.Email == "*****@*****.**"))
            {
                userManager.Create(new ApplicationUser()
                {
                    Email       = "*****@*****.**",
                    UserName    = "******",
                    FirstName   = "Thomas",
                    LastName    = "Zanis",
                    AvatarPath  = "/Avatars/DemoUserAvatars/2.jpg",
                    PhoneNumber = RandomPhoneNumber(),
                    Description = "Administrator of the Site"
                },
                                   "Tobeornot123!");
            }
            userId = userManager.FindByEmail("*****@*****.**").Id;
            userManager.AddToRole(userId, "Admin");


            if (!context.Users.Any(u => u.Email == "*****@*****.**"))
            {
                userManager.Create(new ApplicationUser()
                {
                    Email       = "*****@*****.**",
                    UserName    = "******",
                    FirstName   = "Admin",
                    LastName    = "Demo",
                    AvatarPath  = "/Avatars/DemoUserAvatars/3.jpg",
                    PhoneNumber = RandomPhoneNumber(),
                    Description = "Demo Administrator of the Site"
                },
                                   "Dmrss6HDRwd");
            }
            userId = userManager.FindByEmail("*****@*****.**").Id;
            userManager.AddToRole(userId, "Admin");


            if (!context.Users.Any(u => u.Email == "*****@*****.**"))
            {
                userManager.Create(new ApplicationUser()
                {
                    Email       = "*****@*****.**",
                    UserName    = "******",
                    FirstName   = "Submitter",
                    LastName    = "Demo",
                    AvatarPath  = "/Avatars/DemoUserAvatars/4.jpg",
                    PhoneNumber = RandomPhoneNumber(),
                    Description = "Demo Submitter of the Site"
                },
                                   "Dmrss6HDRwd");
            }
            userId = userManager.FindByEmail("*****@*****.**").Id;
            userManager.AddToRole(userId, "Submitter");


            if (!context.Users.Any(u => u.Email == "*****@*****.**"))
            {
                userManager.Create(new ApplicationUser()
                {
                    Email       = "*****@*****.**",
                    UserName    = "******",
                    FirstName   = "ProjectManager",
                    LastName    = "Demo",
                    AvatarPath  = "/Avatars/DemoUserAvatars/5.jpg",
                    PhoneNumber = RandomPhoneNumber(),
                    Description = "Demo ProjectManager of the Site"
                },
                                   "Dmrss6HDRwd");
            }
            userId = userManager.FindByEmail("*****@*****.**").Id;
            userManager.AddToRole(userId, "ProjectManager");


            if (!context.Users.Any(u => u.Email == "*****@*****.**"))
            {
                userManager.Create(new ApplicationUser()
                {
                    Email       = "*****@*****.**",
                    UserName    = "******",
                    FirstName   = "Developer",
                    LastName    = "Demo",
                    AvatarPath  = "/Avatars/DemoUserAvatars/6.jpg",
                    PhoneNumber = RandomPhoneNumber(),
                    Description = "Demo Developer of the Site"
                },
                                   "Dmrss6HDRwd");
            }
            userId = userManager.FindByEmail("*****@*****.**").Id;
            userManager.AddToRole(userId, "Developer");


            for (int i = 0; i < 10; i++)
            {
                var name      = generateRandomName();
                var emailCurr = $"{name.Item1}{name.Item2}@mailinator.com";
                if (!context.Users.Any(u => u.Email == emailCurr))
                {
                    userManager.Create(new ApplicationUser()
                    {
                        Email       = emailCurr,
                        UserName    = emailCurr,
                        FirstName   = $"{name.Item1}",
                        LastName    = $"{name.Item2}",
                        Description = "Developer",
                        AvatarPath  = "/Avatars/DemoUserAvatars/7.jpg",
                        PhoneNumber = RandomPhoneNumber()
                    },
                                       "123456Abc$");
                }
                userId = userManager.FindByEmail(emailCurr).Id;
                userManager.AddToRole(userId, "Developer");
            }

            for (int i = 0; i < 10; i++)
            {
                var name      = generateRandomName();
                var emailCurr = $"{name.Item1}{name.Item2}@mailinator.com";
                if (!context.Users.Any(u => u.Email == emailCurr))
                {
                    userManager.Create(new ApplicationUser()
                    {
                        Email       = emailCurr,
                        UserName    = emailCurr,
                        FirstName   = $"{name.Item1}",
                        LastName    = $"{name.Item2}",
                        Description = "ProjectManager",
                        AvatarPath  = "/Avatars/DemoUserAvatars/8.jpg",
                        PhoneNumber = RandomPhoneNumber()
                    },
                                       "123456Abc$");;
                }
                userId = userManager.FindByEmail(emailCurr).Id;
                userManager.AddToRole(userId, "ProjectManager");
            }

            for (int i = 0; i < 10; i++)
            {
                var name      = generateRandomName();
                var emailCurr = $"{name.Item1}{name.Item2}@mailinator.com";
                if (!context.Users.Any(u => u.Email == emailCurr))
                {
                    userManager.Create(new ApplicationUser()
                    {
                        Email       = emailCurr,
                        UserName    = emailCurr,
                        FirstName   = $"{name.Item1}",
                        Description = "Submitter",

                        LastName    = $"{name.Item2}",
                        AvatarPath  = "/Avatars/DemoUserAvatars/d1.jpg",
                        PhoneNumber = RandomPhoneNumber()
                    },
                                       "123456Abc$");
                }
                userId = userManager.FindByEmail(emailCurr).Id;
                userManager.AddToRole(userId, "Submitter");
            }
            #endregion
            context.SaveChanges();
            #region add connection sessions
            var user1 = userManager.Users.ToList().Where(u => u.Email == "*****@*****.**").FirstOrDefault();
            var user2 = userManager.Users.ToList().Where(u => u.Email == "*****@*****.**").FirstOrDefault();


            Connection seedConnection = new Connection();
            seedConnection.Users.Add(user1);
            seedConnection.Users.Add(user2);
            seedConnection.isArchived = false;
            seedConnection.Created    = DateTime.Now;
            context.Connections.Add(seedConnection);


            #endregion
            context.SaveChanges();
            #region add Messages to Chat
            foreach (var connection in user1.Connections)
            {
                for (int j = 0; j < 10; j++)
                {
                    Message message = new Message();
                    message.Created      = DateTime.Now;
                    message.ConnectionId = connection.Id;
                    if (j % 2 == 0)
                    {
                        message.SenderId = user1.Id;
                        message.Content  = $"{user1.FullName} this is test {j}";
                    }
                    else
                    {
                        message.SenderId = user2.Id;
                        message.Content  = $"{user2.FullName} this is test {j}";
                    }
                    context.Messages.Add(message);
                }
            }
            #endregion
            context.SaveChanges();

            #region add users to projects
            List <ApplicationUser> ProjectManagers = roleHelper.UsersInRole("ProjectManager").ToList();
            List <ApplicationUser> Developers      = roleHelper.UsersInRole("Developer").ToList();
            List <ApplicationUser> Submitters      = roleHelper.UsersInRole("Submitter").ToList();
            foreach (var project in context.Projects.ToList())
            {
                projectHelper.AddUserToProject(ProjectManagers[rand.Next(ProjectManagers.Count)].Id, project.Id);
                for (int i = 0; i < 3; i++)
                {
                    var randDev = rand.Next(Developers.Count);
                    var randSub = rand.Next(Submitters.Count);
                    projectHelper.AddUserToProject(Developers[randDev].Id, project.Id);
                    projectHelper.AddUserToProject(Submitters[randSub].Id, project.Id);
                }
            }
            #endregion
            context.SaveChanges();
            #region seed tickets 10 tickets/project
            List <string> supportIssues = new List <string>()
            {
                "The Login is not working for 3rd party", "Tickets do not Display text for zero notifications or histories",
                "Project names are not displayed right", "Need to add Users to projects", "add verification for file/image upload",
                "add a new Helper class for notifications", "Seed method duplicating notifications when update-database is ran", "Setup default Avatar images for users",
                "When uploading custom avatar image, it does not update database", "upload database to Azure", "test"
            };

            List <string> supportDiscription = new List <string>()
            {
                "The 3rd party login is not connecting to the correct service.", "Where there are zero notifications or histories for a ticket. It is displaying a empty data table"
                , "The project names are displaying the incorrect value.", "create a seed method to add users to projects. Also create a manage project to add users to the project", "File/image verification. so only certain files formats are uploaded. ",
                "Create a helper class that deals with all the methods for creating and displaying notifications for tickets, projects and users.", "when updateDatabase is ran, it is duplicating methods in the seed methods, causing issues with projects and tickets."
                , "There is no default Avatar image set up for the users. Add a feature in registry and manage user profile for uploading an avatar. if no avatar is uploaded add a default image", "the custom avatar image path is not being updated in the database.",
                "create a new database in Azure and upload the current working database to it.", "test"
            };
            List <TicketPriority> ticketPriorities = ticketHelper.ListTicketProities();
            List <TicketType>     ticketTypes      = ticketHelper.ListTicketTypes();
            var StatusId = context.TicketStatuses.Where(ts => ts.Name == "Open").FirstOrDefault().Id;
            foreach (var project in context.Projects.ToList())
            {
                List <ApplicationUser> projectDevelopers = projectHelper.ListUserOnProjectInRole(project.Id, "Developer").ToList();
                List <ApplicationUser> projectSubmitters = projectHelper.ListUserOnProjectInRole(project.Id, "Submitter").ToList();

                for (int i = 0; i < 10; i++)
                {
                    Ticket seedTicket = new Ticket();
                    var    randDev    = rand.Next(projectDevelopers.Count);
                    var    randSub    = rand.Next(projectSubmitters.Count);

                    seedTicket.DeveloperId = projectDevelopers[randDev].Id;
                    seedTicket.SubmitterId = projectSubmitters[randSub].Id;

                    seedTicket.TicketStatusId   = StatusId;
                    seedTicket.TicketPriorityId = ticketPriorities[rand.Next(ticketPriorities.Count)].Id;
                    seedTicket.TicketTypeId     = ticketTypes[rand.Next(ticketTypes.Count)].Id;
                    seedTicket.Created          = DateTime.Now;
                    seedTicket.Issue            = supportIssues[i];
                    seedTicket.IssueDescription = supportDiscription[i];
                    seedTicket.IsArchived       = false;
                    seedTicket.IsResolved       = false;
                    seedTicket.ProjectId        = project.Id;
                    context.Tickets.Add(seedTicket);
                }
            }
            #endregion
            context.SaveChanges();
            #region seed notifications and Histories
            #region project creation notification
            foreach (var project in context.Projects.ToList())
            {
                foreach (var user in project.Users)
                {
                    var newNotification = new ProjectNotification()
                    {
                        ProjectId        = project.Id,
                        UserId           = user.Id,
                        Created          = DateTime.Now,
                        Icon             = "fa-sitemap",
                        NotificationType = "success",
                        Subject          = $"Added to Project Id: {project.Id}",
                        Message          = $"Hello, {user.FullName} you have been Added to the project: {project.Name}",
                    };
                    context.Notifications.Add(newNotification);
                }
            }
            context.SaveChanges();
            #endregion
            #region project edit add users, remove users.
            foreach (var project in context.Projects.ToList())
            {
                List <ApplicationUser> UsersNotInProject = projectHelper.ListUsesNotOnProjectInExceptInRole(project.Id, "ProjectManager").ToList();
                List <ApplicationUser> oldUserList       = projectHelper.ListUserOnProjectExceptInRole(project.Id, "ProjectManager").ToList();

                var oldProject = context.Projects.AsNoTracking().FirstOrDefault(p => p.Id == project.Id);
                for (int i = 0; i < 5; i++)
                {
                    var userAddId = UsersNotInProject[rand.Next(UsersNotInProject.Count)].Id;
                    projectHelper.RemoveUserFromProject(oldUserList[rand.Next(oldUserList.Count)].Id, project.Id);
                    projectHelper.AddUserToProject(userAddId, project.Id);
                    context.SaveChanges();
                }

                project.DueDate     = DateTime.Now;
                project.Name        = $"{project.Name}v2";
                project.Description = $"{project.Description} Description has been changed to this";
                context.SaveChanges();
                var newProject = context.Projects.AsNoTracking().FirstOrDefault(p => p.Id == project.Id);
                seedHelper.ProjectHistoriesEdit(oldProject, newProject);
                seedHelper.ProjectChangedNotification(newProject, oldProject, oldUserList);
            }
            context.SaveChanges();
            #endregion

            #region seed ticket creation Notifications
            foreach (var ticket in context.Tickets)
            {
                seedHelper.NewTicketNotification(ticket);
            }
            #endregion

            #region seed ticket edit notifications and Histories
            var TicketPriorities = context.TicketPriorities.ToList();
            var TicketStatuses   = context.TicketStatuses.ToList();
            var TicketTypes      = context.TicketTypes.ToList();
            foreach (var ticket in context.Tickets.ToList().Take(10))
            {
                var oldTicket = context.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == ticket.Id);

                List <ApplicationUser> projectDevelopers = projectHelper.ListUserOnProjectInRole(ticket.project.Id, "Developer").ToList();

                //ticket.TicketPriorityId;
                ticket.TicketPriorityId = TicketPriorities[rand.Next(TicketPriorities.Count)].Id;
                ticket.TicketStatusId   = TicketStatuses[rand.Next(TicketStatuses.Count)].Id;
                ticket.TicketTypeId     = TicketTypes[rand.Next(TicketTypes.Count)].Id;
                ticket.DeveloperId      = projectDevelopers[rand.Next(projectDevelopers.Count)].Id;
                context.SaveChanges();
                var newTicket = context.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == ticket.Id);
                seedHelper.TicketHistoryEdit(oldTicket, newTicket);
                seedHelper.TicketChangeNotification(oldTicket, newTicket);
            }
            context.SaveChanges();
            #endregion
            #endregion
            #region seed ticket comments and attachments
            List <Project> projects = context.Projects.ToList();
            foreach (var project in projects)
            {
                List <ApplicationUser> UsersInProject = projectHelper.ListUsersOnProject(project.Id);
                var tickets = context.Tickets.Where(t => t.ProjectId == project.Id).ToList();

                TicketComment newTicket0Comment = new TicketComment()
                {
                    TicketId = tickets[0].Id,
                    UserId   = tickets[0].DeveloperId,
                    Comment  = "Checked the Code for the 3rd part ports and SMTP server. Looks correct. ",
                    Created  = DateTime.Now
                };
                context.TicketComments.Add(newTicket0Comment);
                //TicketAttachment newTicketAttachment0 = new TicketAttachment()
                //{
                //    TicketId = tickets[0].Id,
                //    UserId = tickets[0].DeveloperId,
                //    Created = DateTime.Now,
                //    FilePath =
                //};
                //context.TicketAttachments.Add(newTicketAttachment0);

                TicketComment newTicket0Comment2 = new TicketComment()
                {
                    TicketId = tickets[0].Id,
                    UserId   = tickets[0].DeveloperId,
                    Comment  = "Checked Account controller. The 3rd party login code was commented out. un-commented and it is working ",
                    Created  = DateTime.Now
                };
                context.TicketComments.Add(newTicket0Comment2);

                TicketComment newTicket1Comment1 = new TicketComment()
                {
                    TicketId = tickets[1].Id,
                    UserId   = tickets[1].DeveloperId,
                    Comment  = "looked at the Controller and the view for tickets. Created a If statement in the view",
                    Created  = DateTime.Now
                };
                context.TicketComments.Add(newTicket1Comment1);
                TicketAttachment newTicket1Attachment0 = new TicketAttachment()
                {
                    TicketId    = tickets[1].Id,
                    UserId      = tickets[1].DeveloperId,
                    Created     = DateTime.Now,
                    FilePath    = "/Uploads/ticketif.PNG",
                    FileName    = "ticketif.PNG",
                    Description = "ticketif.PNG"
                };
                context.TicketAttachments.Add(newTicket1Attachment0);
                TicketAttachment newTicket1Attachment1 = new TicketAttachment()
                {
                    TicketId    = tickets[1].Id,
                    UserId      = tickets[1].DeveloperId,
                    Created     = DateTime.Now,
                    FilePath    = "/Uploads/attachmentview.PNG",
                    FileName    = "attachmentview.PNG",
                    Description = "attachmentview.PNG"
                };
                context.TicketAttachments.Add(newTicket1Attachment1);

                TicketComment newTicket1Comment2 = new TicketComment()
                {
                    TicketId = tickets[1].Id,
                    UserId   = tickets[1].DeveloperId,
                    Comment  = "Found that I needed to make sure the list of notifications or histories where checked against null and length of Zero",
                    Created  = DateTime.Now
                };
                context.TicketComments.Add(newTicket1Comment2);
                TicketComment newTicket2Comment0 = new TicketComment()
                {
                    TicketId = tickets[2].Id,
                    UserId   = tickets[2].DeveloperId,
                    Comment  = "Checked the View, it was not referencing the project name, it was looking at a null object",
                    Created  = DateTime.Now
                };
                context.TicketComments.Add(newTicket2Comment0);
                TicketComment newTicket3Comment0 = new TicketComment()
                {
                    TicketId = tickets[3].Id,
                    UserId   = tickets[3].DeveloperId,
                    Comment  = "Created a Seed section for adding users to a project",
                    Created  = DateTime.Now
                };
                context.TicketComments.Add(newTicket3Comment0);
                TicketAttachment newTicket3Attachment1 = new TicketAttachment()
                {
                    TicketId    = tickets[1].Id,
                    UserId      = tickets[1].DeveloperId,
                    Created     = DateTime.Now,
                    FilePath    = "/Uploads/seetprojectuser.PNG",
                    FileName    = "seetprojectuser.PNG",
                    Description = "seetprojectuser.PNG"
                };
                context.TicketAttachments.Add(newTicket3Attachment1);
                TicketAttachment newTicket3Attachment2 = new TicketAttachment()
                {
                    TicketId    = tickets[1].Id,
                    UserId      = tickets[1].DeveloperId,
                    Created     = DateTime.Now,
                    FilePath    = "/Uploads/projectviewListBox.PNG",
                    FileName    = "projectviewListBox.PNG",
                    Description = "projectviewListBox.PNG"
                };
                context.TicketAttachments.Add(newTicket3Attachment2);
                TicketComment newTicket3Comment1 = new TicketComment()
                {
                    TicketId = tickets[3].Id,
                    UserId   = tickets[3].DeveloperId,
                    Comment  = "Created a multiselect List in the create and edit for projects users and users not in the project ",
                    Created  = DateTime.Now
                };
                context.TicketComments.Add(newTicket3Comment1);
                TicketComment newTicket3Comment2 = new TicketComment()
                {
                    TicketId = tickets[3].Id,
                    UserId   = tickets[3].DeveloperId,
                    Comment  = "Created a method in the post that looped through the selected users added to project ",
                    Created  = DateTime.Now
                };
                context.TicketComments.Add(newTicket3Comment2);
                TicketComment newTicket3Comment3 = new TicketComment()
                {
                    TicketId = tickets[3].Id,
                    UserId   = tickets[3].DeveloperId,
                    Comment  = "in the method, removed all the previous user then add the new list from the edit and create. It is working now ",
                    Created  = DateTime.Now
                };
                context.TicketComments.Add(newTicket3Comment3);
                TicketComment newTicket4Comment0 = new TicketComment()
                {
                    TicketId = tickets[4].Id,
                    UserId   = tickets[4].DeveloperId,
                    Comment  = "In the register and edit user viewModels added a Avatar HttpPostedFileBase property",
                    Created  = DateTime.Now
                };
                context.TicketComments.Add(newTicket4Comment0);
                TicketComment newTicket4Comment1 = new TicketComment()
                {
                    TicketId = tickets[4].Id,
                    UserId   = tickets[4].DeveloperId,
                    Comment  = "Created helper files FileUploadValidator, sluggerHelper, StringUtilites",
                    Created  = DateTime.Now
                };
                context.TicketComments.Add(newTicket4Comment1);
                TicketComment newTicket4Comment2 = new TicketComment()
                {
                    TicketId = tickets[4].Id,
                    UserId   = tickets[4].DeveloperId,
                    Comment  = "Added the method to verify the input file for the avatar and create a custom name. then added it to the User",
                    Created  = DateTime.Now
                };
                context.TicketComments.Add(newTicket4Comment2);
                context.SaveChanges();
            }
            #endregion
        }
Example #20
0
 public void SendMail(string subject, string body, ProjectNotification notif, int projectId)
 {
     BuildService.SendMail (GetUsersToNotify (projectId, notif), subject, body);
 }
Example #21
0
        public void SetApplicationNotification(ProjectNotification notif, bool enable)
        {
            if ((notif & ProjectNotification.AdminNotificationMask) != 0)
                CheckIsAdmin ();

            UserApplication up = db.SelectObjectWhere<UserApplication> ("UserId={0} AND ApplicationId={1}", user.Id, application.Id);
            if (enable) {
                if (up == null) {
                    up = new UserApplication () { UserId = user.Id, ApplicationId = application.Id, ProjectNotifications = notif };
                    db.InsertObject<UserApplication> (up);
                }
                else {
                    up.ProjectNotifications |= notif;
                    db.UpdateObject (up);
                }
            } else if (up != null) {
                up.ProjectNotifications &= ~notif;
                db.UpdateObject (up);
            }
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {
            switch (this.Type)
            {
            case "role":
                ObjectNameLabel.Text = "Role";
                ProjectNotificationItemList.DataSourceID   = "RoleDataSource";
                ProjectNotificationItemList.DataValueField = "RoleID";
                ProjectNotificationItemList.DataTextField  = "Name";
                break;

            case "user":
                ObjectNameLabel.Text = "User";

                ProjectNotification oProjectNotification = new ProjectNotification();
                oProjectNotification.Where.ProjectID.Value             = this.ProjectID;
                oProjectNotification.Where.ProjectID.Operator          = MyGeneration.dOOdads.WhereParameter.Operand.Equal;
                oProjectNotification.Where.NotificationTypeID.Value    = this.NotificationTypeID;
                oProjectNotification.Where.NotificationTypeID.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Equal;
                oProjectNotification.Where.UserID.Operator             = MyGeneration.dOOdads.WhereParameter.Operand.IsNotNull;
                oProjectNotification.Query.Distinct = true;
                oProjectNotification.Query.Load();

                string UserIdList = string.Empty;
                while (!oProjectNotification.EOF)
                {
                    UserIdList += "," + oProjectNotification.UserID.ToString();
                    oProjectNotification.MoveNext();
                }
                if (UserIdList.Length > 0)
                {
                    UserIdList = UserIdList.Remove(0, 1);
                }

                DL_WEB.DAL.Client.User oUser = new DL_WEB.DAL.Client.User();
                oUser.Where.UserID.Value    = UserIdList;
                oUser.Where.UserID.Operator = MyGeneration.dOOdads.WhereParameter.Operand.NotIn;
                oUser.Query.Load();

                ProjectNotificationItemList.DataSource     = oUser.DefaultView;
                ProjectNotificationItemList.DataValueField = "UserID";
                ProjectNotificationItemList.DataTextField  = "Login";
                ProjectNotificationItemList.DataBind();
                break;

            case "addressbook":
                ObjectNameLabel.Text = "Contact";

                DL_DAL.Client.AddressBookView view = new DL_DAL.Client.AddressBookView();
                view.Where.UserID.Value        = DL_WEB.DAL.Client.User.Instance.GetUserIDByGUID(this.UserGUID);
                view.Where.UserID.Operator     = MyGeneration.dOOdads.WhereParameter.Operand.Equal;
                view.Where.IsShared.Value      = true;
                view.Where.IsShared.Operator   = MyGeneration.dOOdads.WhereParameter.Operand.Equal;
                view.Where.IsShared.Conjuction = MyGeneration.dOOdads.WhereParameter.Conj.Or;
                view.LoadAll();
                ProjectNotificationItemList.DataSource     = view.DefaultView;
                ProjectNotificationItemList.DataValueField = "EntryID";
                ProjectNotificationItemList.DataTextField  = "Name";
                ProjectNotificationItemList.DataBind();
                break;
            }
        }
    }
Example #23
0
        IEnumerable<string> GetUsersToNotify(int projectId, ProjectNotification notif)
        {
            HashSet<string> emails = new HashSet<string> ();

            // Users with the notification flag for the project
            var users = db.SelectObjects<User> (
                "SELECT User.* FROM User, UserProject WHERE " +
                "User.Id = UserProject.UserId AND " +
                "UserProject.ProjectId={0} AND Notifications & {1} = {2}", projectId, (int)notif, (int)notif);
            emails.UnionWith (users.Select (u => u.Email));

            // Notification to be sent to project owners
            users = db.SelectObjects<User> (
                "SELECT User.* FROM User, UserApplication, UserProject WHERE " +
                "User.Id = UserApplication.UserId AND " +
                "User.Id = UserProject.UserId AND " +
                "UserProject.ProjectId = {0} AND " +
                "UserApplication.ApplicationId = {1} AND " +
                "UserProject.Permissions & 1 = 1 AND " +
                "UserApplication.ProjectNotifications & {2} = {3}", projectId, application.Id, (int)notif, (int)notif);
            emails.UnionWith (users.Select (u => u.Email));

            return emails;
        }
Example #24
0
 //Project Notifications
 public abstract int CreateNewProjectNotification(ProjectNotification newProjectNotification);
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        BusinessEntity.PushStaticConnectionString();

        BusinessEntity.StaticConnectionString = ConfigurationSettings.AppSettings["dbConnection"];

        DL_WEB.DAL.Master.Organization oOrganization = new DL_WEB.DAL.Master.Organization();
        oOrganization.LoadByPrimaryKey(OrganizationID);

        DL_WEB.DAL.Master.Database oDatabase = new DL_WEB.DAL.Master.Database();
        if (oOrganization.RowCount > 0)
        {
            oDatabase.LoadByPrimaryKey(oOrganization.DatabaseID);
        }

        DL_WEB.DAL.Master.Server oServer = new DL_WEB.DAL.Master.Server();
        if (oDatabase.RowCount > 0)
        {
            oServer.LoadByPrimaryKey(oDatabase.ServerID);

            MyGeneration.dOOdads.BusinessEntity.StaticConnectionString = oDatabase.DBConnectionString;
        }

        AddressBook oAddressBook = new AddressBook();

        oAddressBook.AddNew();
        oAddressBook.FirstName    = tbFirstName.Text;
        oAddressBook.LastName     = tbLastName.Text;
        oAddressBook.Company      = tbCompany.Text;
        oAddressBook.PrimaryEmail = tbEmail.Text;
        oAddressBook.ProjectID    = this.ProjectID;
        oAddressBook.IsApproved   = false;
        oAddressBook.GUID         = Guid.NewGuid();
        oAddressBook.Save();

        ProjectNotification oProjectNotification = new ProjectNotification();

        oProjectNotification.AddNew();
        oProjectNotification.AddressBookEntryID = oAddressBook.EntryID;
        oProjectNotification.ProjectID          = this.ProjectID;
        oProjectNotification.ImpactLevelID      = Micajah.Common.Helper.Convert.o2i(this.ImpactLevelList.SelectedValue);
        oProjectNotification.NotificationTypeID = 1;
        oProjectNotification.Save();

        BusinessEntity.PopStaticConnectionString();

        #region Sending confirmation request to this contact

        SmtpClient client = new SmtpClient(oServer.MailHost);
        client.Credentials = new NetworkCredential(oServer.MailUser, oServer.MailPass);

        MailAddress from    = new MailAddress(oServer.MailEmail, "Deployment Logger");
        MailAddress to      = new MailAddress(tbEmail.Text, tbFirstName.Text + " " + tbLastName.Text);
        MailMessage message = new MailMessage(from, to);

        message.Subject = "Welcome to Deployment Logger";
        message.Body    = String.Format("Dear, {3},\n\nThank you for registering with Deployment Logger.\n" +
                                        "To activate your account and verify your e-mail address, please click on the following link:\n" +
                                        "{0}anonymous/SubscribeConfirmation.aspx?addressbookid={1}&databaseid={2}&guid={4}\n\n" +
                                        "If you have received this mail in error, you do not need to take any action to cancel the account. " +
                                        "The account will not be activated, and you will not receive any further emails.\n\n" +
                                        "If clicking the link above does not work, copy and paste the URL in a new browser window instead.\n\n" +
                                        "Thank you for using Micajah Deployment Logger!" +
                                        "---" +
                                        "This is a post-only mailing.  Replies to this message are not monitored or answered.", oServer.WebReference, oAddressBook.EntryID, oDatabase.DatabaseID, tbFirstName.Text + " " + tbLastName.Text, HttpUtility.UrlEncode(oAddressBook.GUID.ToString()));
        client.Send(message);
        message.Dispose();

        #endregion
    }
 public OrganizationProjectCommandHandler(NotificationService notificationService, ProjectNotification notification)
 {
     this.notificationService = notificationService;
     this.notification        = notification;
 }
Example #27
0
 public void SendMail(string subject, string body, ProjectNotification notif, int projectId)
 {
     BuildService.SendMail(GetUsersToNotify(projectId, notif), subject, body);
 }
Example #28
0
        public void SendOrganizationProjectNotification(ProjectNotification notification, OrganizationProjectCommand command)
        {
            var users = new List <Data.ViewModels.Organization.MemberModel>();

            using (var noSqlSession = noSqlSessionFactory())
            {
                var org =
                    noSqlSession.GetAll <Organization>().Where(o => o.Id == command.ObjectId).Select(
                        o => new { Projects = o.Projects, Name = o.Name }).Single();
                var project  = org.Projects.Where(p => p.Id == command.ProjectId).Single();
                var todo     = project.ToDos.Where(t => t.Id == command.ToDoId).SingleOrDefault();
                var fromUser = noSqlSession.GetAll <Data.MongoDB.User>().SingleOrDefault(u => u.Id == command.UserId);

                if (!string.IsNullOrEmpty(todo.ResponsibleUserId))
                {
                    using (var userSession = usersSessionFactory.CreateContext())
                    {
                        var dbUser = organizationService.GetDbUser(todo.ResponsibleUserId);
                        foreach (var email in userSession.UserEmails.Where(e => e.User.ObjectId == todo.ResponsibleUserId && e.IsEmailConfirmed && e.SendMail))
                        {
                            users.Add(new Data.ViewModels.Organization.MemberModel()
                            {
                                FullName = dbUser.FirstName + " " + dbUser.LastName,
                                Email    = email.Email,
                                ObjectId = dbUser.ObjectId
                            });
                        }
                    }
                }
                else
                {
                    users.AddRange(organizationService.GetMemberConfirmedEmails(command.OrganizationId));
                }

                Data.EF.Users.Notification not = null;
                if (command.ActionType == ActionTypes.OrganizationToDoAdded)
                {
                    not = GetNotification((int)NotificationTypes.OrganizationTodo);
                }

                if (command.ActionType == ActionTypes.OrganizationToDoCommentAdded)
                {
                    not = GetNotification((int)NotificationTypes.OrganizationProjectComment);
                    users.AddRange(organizationService.GetCommentUserEmails(todo));
                }

                users = users.Where(u => !string.IsNullOrEmpty(u.Email)).Distinct().ToList();

                if (notification == null)
                {
                    logger.Information(string.Format("{0} id={1} failed sending mail, notification not found",
                                                     command.GetType().Name, command.MessageId));
                    return;
                }

                if (users.Any())
                {
                    logger.Information(string.Format("Sending emails to {0} users", users.Count));
                }
                else
                {
                    logger.Information(string.Format("{0} id={1} successfully completed, no users to send mail to", command.GetType().Name, command.MessageId));
                    return;
                }

                notification.UserFullName     = command.UserFullName;
                notification.UserLink         = command.UserLink;
                notification.OrganizationLink = command.OrganizationLink;
                notification.OrganizationName = command.OrganizationName;
                notification.ProjectLink      = command.Link;
                notification.ProjectName      = command.ProjectSubject;
                notification.TodoLink         = command.ToDoLink;
                notification.ToDoSubject      = command.ToDoSubject;
                notification.Text             = command.Text.NewLineToHtml();
                if (fromUser != null)
                {
                    notification.FromDisplayName = command.UserFullName;
                    notification.From            = fromUser.Email;
                }

                notification.MessageTemplate = not.Message;
                notification.Subject         = not.Subject;
                foreach (var user in users)
                {
                    notification.To            = user.Email;
                    notification.ToDisplayName = user.FullName;
                    notification.Execute();
                }
            }
        }