Example #1
0
        public virtual MailMessage Invitation(User user)
        {
            using (var repo = new Repo())
            {
                var profile = repo.Profiles.Single();

                var from = profile.EmailFromAddress ?? "noreply@domain";

                var mailMessage = new MailMessage(from, user.Email)
                {
                    Subject = "Invitation to Service Tracker"
                };

                var bcc = profile.EmailBccAddress;
                if (!string.IsNullOrEmpty(bcc))
                {
                    mailMessage.Bcc.Add(bcc);
                }

                ViewBag.User = user;
                PopulateBody(mailMessage, viewName: "Invitation");

                return mailMessage;
            }
        }
        public override bool IsUserInRole(string username, string roleName)
        {
            using (var repo = new Repo())
            {
                int DesiredRoleId = (int)Enum.Parse(typeof(RoleType), roleName);
                int UserRoleId = repo.Users.Single(u => u.ClaimedIdentifier == username).RoleId;

                return DesiredRoleId >= UserRoleId;
            }
        }
        public override string[] GetRolesForUser(string username)
        {
            // return all roles up to and including the requested role
            using (var repo = new Repo())
            {
                var RoleId = repo.Users.Single(u => u.ClaimedIdentifier == username).RoleId;

                var roleIds = ((int[])Enum.GetValues(typeof(RoleType)));
                var roleIdsForUser = roleIds.Where(r => r <= RoleId);
                var rolesForUser = roleIdsForUser.Select(r => (RoleType)r);

                return rolesForUser.Select(r => r.ToString()).ToArray();
            }
        }
        private void PopulateEditViewBagProperties(bool includeAllOptionsWhenAppropriate)
        {
            var repo = new Repo();

            ViewBag.Services = repo.Services.ToSelectListItems(includeAllOption: false);
            ViewBag.Servicers = repo.Servicers.ToSelectListItems(includeAllOption: includeAllOptionsWhenAppropriate);
            ViewBag.Sites = repo.Sites.ToSelectListItems(includeAllOption: includeAllOptionsWhenAppropriate);
        }