Exemplo n.º 1
0
        public async Task <IActionResult> Edit(string userId)
        {
            if (!string.IsNullOrEmpty(userId))
            {
                var user = await _userManagerService.FindByIdAsync(userId);

                if (user == null)
                {
                    _loggerService.LogError("User id is null");
                    return(NotFound());
                }
                var userRoles = await _userManagerService.GetRolesAsync(user);

                var allRoles = await _adminService.GetRolesExceptAdminAsync();

                RoleViewModel model = new RoleViewModel
                {
                    UserID    = user.Id,
                    UserEmail = user.Email,
                    UserRoles = userRoles,
                    AllRoles  = allRoles
                };

                return(Ok(model));
            }
            _loggerService.LogError("User id is null");
            return(NotFound());
        }
        public async Task <ActionResult> Create(int orderId)
        {
            ViewBag.OrderId = orderId;
            var currentUser = await _userManagerService.FindByIdAsync(User.Identity.GetUserId());

            var currentCustomerId = currentUser.CustomerId;

            ViewBag.OrderId   = orderId;
            ViewBag.ProductId = new SelectList(_db.Products.Where(x => x.CustomerId == currentCustomerId), "CustomerId", "Name");
            return(View());
        }
Exemplo n.º 3
0
        public async Task <Dictionary <string, bool> > GetUserAccessAsync(string userId, IEnumerable <string> userRoles = null)
        {
            if (userRoles == null)
            {
                var user = await _userManagerService.FindByIdAsync(userId);

                userRoles = await _userManagerService.GetRolesAsync(user);
            }

            var userAccesses = _accessDictionary.Where(userAccess => userRoles.Contains(userAccess.Key));
            var accesses     = new Dictionary <string, bool>();

            foreach (var uAccess in userAccesses)
            {
                foreach (var roleAccesses in uAccess.Value)
                {
                    if (!accesses.ContainsKey(roleAccesses.Key))
                    {
                        accesses.Add(roleAccesses.Key, roleAccesses.Value);
                    }
                    else
                    {
                        accesses[roleAccesses.Key] |= roleAccesses.Value;
                    }
                }
            }

            return(accesses);
        }
Exemplo n.º 4
0
        /// <inheritdoc />
        public async Task <ClubMembersDTO> AddFollowerAsync(int clubId, string userId)
        {
            var club = await _clubService.GetClubInfoByIdAsync(clubId);

            var userDto = await _userManagerService.FindByIdAsync(userId) ??
                          throw new ArgumentNullException($"User with {userId} id not found");

            var oldMember = await _repoWrapper.ClubMembers.GetFirstOrDefaultAsync(i => i.UserId == userId);

            if (oldMember != null)
            {
                _repoWrapper.ClubMembers.Delete(oldMember);
                await _repoWrapper.SaveAsync();
            }

            ClubMembers newMember = new ClubMembers()
            {
                ClubId = club.ID, IsApproved = false, UserId = userDto.Id
            };

            await _repoWrapper.ClubMembers.CreateAsync(newMember);

            await _repoWrapper.SaveAsync();

            return(_mapper.Map <ClubMembers, ClubMembersDTO>(newMember));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Edit(string userId)
        {
            if (!string.IsNullOrEmpty(userId))
            {
                var user = await _userManagerService.FindByIdAsync(userId);

                if (user == null)
                {
                    _logger.Log(LogLevel.Error, $"Can`t find the User");
                    return(RedirectToAction("HandleError", "Error", new { code = 404 }));
                }
                var userRoles = await _userManagerService.GetRolesAsync(user);

                var allRoles = await _adminService.GetRolesExceptAdminAsync();

                RoleViewModel model = new RoleViewModel
                {
                    UserID    = user.Id,
                    UserEmail = user.Email,
                    UserRoles = userRoles,
                    AllRoles  = allRoles
                };
                return(PartialView(model));
            }
            _logger.Log(LogLevel.Error, $"User, with userId: {userId}, is null");
            return(RedirectToAction("HandleError", "Error", new { code = 404 }));
        }
Exemplo n.º 6
0
        /// <inheritdoc />
        public async Task <IEnumerable <string> > GetUserAccessLevelsAsync(string userId)
        {
            List <string> accessLevels = new List <string>();
            var           user         = await _userManagerService.FindByIdAsync(userId);

            List <string> userRoles = (await _userManagerService.GetRolesAsync(user)).ToList();

            if (userRoles.Count == 1)
            {
                if (userRoles[0] == RolesForActiveMembershipTypeDTO.Plastun.GetDescription())
                {
                    accessLevels.Add(AccessLevelTypeDTO.Member.GetDescription());
                }
                else if (userRoles[0] == RolesForActiveMembershipTypeDTO.Supporter.GetDescription())
                {
                    accessLevels.Add(AccessLevelTypeDTO.Supporter.GetDescription());
                }
            }
            else if (userRoles.Count > 1)
            {
                accessLevels.AddRange(new List <string>
                {
                    AccessLevelTypeDTO.Member.GetDescription(),
                    AccessLevelTypeDTO.LeadershipMember.GetDescription()
                });
            }
            else
            {
                accessLevels.Add(AccessLevelTypeDTO.FormerMember.GetDescription());
            }

            return(accessLevels.AsEnumerable());
        }
Exemplo n.º 7
0
        public async Task <int> GetCustomerId()
        {
            var currentUserId = HttpContext.Current.User.Identity.GetUserId();
            var currentUser   = await _userManagerService.FindByIdAsync(currentUserId);

            return(currentUser.CustomerId);
        }
Exemplo n.º 8
0
        public async Task <bool> ChangeUserMembershipDatesAsync(UserMembershipDatesDTO userMembershipDatesDTO)
        {
            bool isChanged = false;
            var  userDto   = await _userManagerService.FindByIdAsync(userMembershipDatesDTO.UserId);

            if (userDto != null)
            {
                UserMembershipDates userMembershipDates = await _repoWrapper.UserMembershipDates.GetFirstOrDefaultAsync(umd => umd.UserId == userDto.Id);

                if (userMembershipDates != null)
                {
                    userMembershipDates.DateEntry = userMembershipDatesDTO.DateEntry;
                    userMembershipDates.DateOath  = userMembershipDatesDTO.DateOath;
                    userMembershipDates.DateEnd   = userMembershipDatesDTO.DateEnd;
                    _repoWrapper.UserMembershipDates.Update(userMembershipDates);
                    await _repoWrapper.SaveAsync();

                    isChanged = true;
                }
            }
            return(isChanged);
        }
        public async Task <ActionResult> AllCategories()
        {
            var currentUser = await _userManagerService.FindByIdAsync(User.Identity.GetUserId());

            var currentCustomerId = currentUser.CustomerId;
            var categories        = _categoryRepository.GetAll().OrderBy(o => o.Name).Where(x => x.CustomerId == currentCustomerId).Select(y => new CategoryDropDownViewModel
            {
                Id   = y.Id,
                Name = y.Name
            }).ToList();

            return(Json(categories, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 10
0
        /// <inheritdoc />
        public async Task <IEnumerable <string> > GetUserAccessLevelsAsync(string userId)
        {
            var leadershipLevelRoles = new List <string>
            {
                Roles.KurinHead,
                Roles.KurinHeadDeputy,
                Roles.KurinSecretary,
                Roles.CityHead,
                Roles.CityHeadDeputy,
                Roles.CitySecretary,
                Roles.OkrugaHead,
                Roles.OkrugaHeadDeputy,
                Roles.OkrugaSecretary,
                "Голова Керівного органу",
                "Діловод Керівного органу"
            };

            var supporterLevelDegree = "Пласт прият";
            var accessLevels         = new List <string>();
            var user = await _userManagerService.FindByIdAsync(userId);

            var userRoles        = (await _userManagerService.GetRolesAsync(user)).ToList();
            var userPlastDegrees = await _plastDegreeService.GetUserPlastDegreesAsync(userId);

            var isInSupporterDegree = userPlastDegrees.Any(d => d.PlastDegree.Name == supporterLevelDegree);

            if (userRoles.Contains(RolesForActiveMembershipTypeDTO.RegisteredUser.GetDescription()))
            {
                accessLevels.Add(AccessLevelTypeDTO.RegisteredUser.GetDescription());
            }

            if (userRoles.Contains(RolesForActiveMembershipTypeDTO.Supporter.GetDescription()) ||
                userRoles.Contains(RolesForActiveMembershipTypeDTO.FormerPlastMember.GetDescription()) ||
                isInSupporterDegree)
            {
                accessLevels.Add(AccessLevelTypeDTO.Supporter.GetDescription());
            }

            if (userRoles.Contains(RolesForActiveMembershipTypeDTO.PlastMember.GetDescription()))
            {
                accessLevels.Add(AccessLevelTypeDTO.PlastMember.GetDescription());
            }

            if (userRoles.Intersect(leadershipLevelRoles).Any())
            {
                accessLevels.Add(AccessLevelTypeDTO.LeadershipMember.GetDescription());
            }

            return(accessLevels.AsEnumerable());
        }
Exemplo n.º 11
0
        public async Task <bool> AddUserNotificationAsync(UserNotificationDTO userNotificationDTO)
        {
            bool addedSuccessfully = false;

            if ((await _userManagerService.FindByIdAsync(userNotificationDTO.OwnerUserId)) != null)
            {
                UserNotification userNotification = _mapper.Map <UserNotification>(userNotificationDTO);
                NotificationType notificationType = await _repoWrapper.NotificationTypes.GetFirstOrDefaultAsync(nt => nt.Id == userNotificationDTO.NotificationTypeId);

                if (notificationType != null)
                {
                    userNotification.NotificationType = notificationType;
                    userNotification.Checked          = false;
                    userNotification.CreatedAt        = DateTime.Now;
                    await _repoWrapper.UserNotifications.CreateAsync(userNotification);

                    await _repoWrapper.SaveAsync();

                    addedSuccessfully = true;
                }
            }
            return(addedSuccessfully);
        }
Exemplo n.º 12
0
        public async Task <IEnumerable <UserNotificationDTO> > AddListUserNotificationAsync(IEnumerable <UserNotificationDTO> userNotificationsDTO)
        {
            bool addedSuccessfully       = true;
            var  resultUserNotifications = new List <UserNotification>();

            foreach (var userNotificationDTO in userNotificationsDTO)
            {
                if ((await _userManagerService.FindByIdAsync(userNotificationDTO.OwnerUserId)) != null)
                {
                    UserNotification userNotification = _mapper.Map <UserNotification>(userNotificationDTO);
                    NotificationType notificationType = await _repoWrapper.NotificationTypes.GetFirstOrDefaultAsync(nt => nt.Id == userNotificationDTO.NotificationTypeId);

                    if (notificationType != null)
                    {
                        userNotification.Checked   = false;
                        userNotification.CreatedAt = DateTime.Now;
                        resultUserNotifications.Add(userNotification);
                        await _repoWrapper.UserNotifications.CreateAsync(userNotification);
                    }
                    else
                    {
                        addedSuccessfully = false;
                    }
                }
                else
                {
                    addedSuccessfully = false;
                }
            }
            if (addedSuccessfully)
            {
                await _repoWrapper.SaveAsync();

                return(_mapper.Map <IEnumerable <UserNotificationDTO> >(resultUserNotifications));
            }
            throw new InvalidOperationException();
        }
Exemplo n.º 13
0
        /// <inheritdoc />
        public async Task <DateTime> GetDateOfEntryAsync(string userId)
        {
            var userDTO = await _userManagerService.FindByIdAsync(userId);

            return(userDTO.RegistredOn);
        }