Ejemplo n.º 1
0
        /// <summary>
        /// Get the first user id with the given role.
        /// </summary>
        public static string GetUserRoleId(CmagruDBContext dBContext, string roleName)
        {
            var role     = dBContext.Roles.First(x => x.NormalizedName == roleName.ToUpper());
            var userRole = dBContext.UserRoles.FirstOrDefault(x => x.RoleId == role.Id);

            return(userRole.UserId);
        }
Ejemplo n.º 2
0
        public static string GetUserRole(CmagruDBContext dBContext, ApplicationUser user)
        {
            var role = dBContext.UserRoles.FirstOrDefault(x => x.UserId == user.Id);

            if (role == null)
            {
                return(null);
            }
            return(dBContext.Roles.First(x => x.Id == role.RoleId).Name);
        }
Ejemplo n.º 3
0
 public ImgControl(
     ILogger logger,
     CmagruDBContext context,
     UserManager <ApplicationUser> userManager,
     IEmailService emailService)
 {
     _logger       = logger;
     _context      = context;
     _userManager  = userManager;
     _emailService = emailService;
 }
 public PhotoRoomController(
     ILogger <AccountController> logger,
     CmagruDBContext context,
     UserManager <ApplicationUser> userManager,
     IEmailService emailService)
 {
     _logger      = logger;
     _context     = context;
     _userManager = userManager;
     _imgCtrl     = new ImgControl(_logger, _context, _userManager, emailService);
 }
 public PhotoWallController(
     ILogger <AccountController> logger,
     CmagruDBContext context,
     UserManager <ApplicationUser> userManager,
     IEmailService emailService,
     IAuthorizationService authorizationService)
 {
     _logger               = logger;
     _context              = context;
     _userManager          = userManager;
     _authorizationService = authorizationService;
     _imgCtrl              = new ImgControl(logger, context, userManager, emailService);
 }
Ejemplo n.º 6
0
 public AccountController(
     UserManager <ApplicationUser> userManager,
     SignInManager <ApplicationUser> signInManager,
     CmagruDBContext context,
     ILogger <AccountController> logger,
     IMapper mapper,
     IEmailService emailService)
 {
     System.Security.Claims.ClaimsPrincipal a = User;
     _logger        = logger;
     _mapper        = mapper;
     _userManager   = userManager;
     _signInManager = signInManager;
     _emailService  = emailService;
     _context       = context;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Send email notification to target, if email is
        /// confirmed and target allows notifications.
        /// </summary>
        public static void SendEmailNotif(
            CmagruDBContext context,
            IEmailService emailService,
            string targetUserId,
            string subject,
            string content)
        {
            var targetUser = context.Users.Find(targetUserId);

            if (targetUser == null)
            {
                return;
            }
            if (!targetUser.EmailConfirmed)
            {
                return;
            }

            var settings = context.GetUserSettings
                           .FirstOrDefault(x => x.UserId == targetUser.Id);

            if (settings == null)
            {
                return;
            }
            if (!settings.SendEmailNotifs)
            {
                return;
            }

            emailService.Send(new EmailMessage
            {
                ToAddress = targetUser.Email,
                Subject   = subject,
                Content   = content
            });
        }