Exemple #1
0
        public async Task <ListResultDto <UserListDto> > GetUserList()
        {
            var userList = CreateFilteredQuery(new PagedUserResultRequestDto {
                MaxResultCount = int.MaxValue
            }).ToList();

            var userLists = new List <UserListDto>();

            foreach (var user in userList)
            {
                var userListDto = new UserListDto
                {
                    Name         = user.Name,
                    Surname      = user.Surname,
                    UserKey      = user.UserKey,
                    UserName     = user.UserName,
                    PhoneNumber  = user.PhoneNumber,
                    CreationTime = user.CreationTime
                };

                foreach (var userRole in user.Roles)
                {
                    var roles = _roleManager.Roles.Where(p => user.Roles.Any(pr => pr.RoleId == p.Id))
                                .Select(p => p.DisplayName);

                    userListDto.RoleNames = roles.ToArray();
                }

                userLists.Add(userListDto);
            }

            return(new ListResultDto <UserListDto>(userLists));
        }
Exemple #2
0
        public async Task <IActionResult> Login(UserLoginDto userLoginDto)
        {
            User user = await _userNamager.FindByNameAsync(userLoginDto.Username);

            if (user != null)
            {
                SignInResult result = await _signInManager.CheckPasswordSignInAsync(user, userLoginDto.Password, false);

                if (result.Succeeded)
                {
                    User appUser = await _userNamager.Users.Include(p => p.Photos)
                                   .FirstOrDefaultAsync(u => u.NormalizedUserName == userLoginDto.Username.ToUpper());

                    UserListDto userListDto = _mapper.Map <UserListDto>(appUser);

                    return(Ok(new
                    {
                        token = await GenerateJwtToken(appUser),
                        user = userListDto
                    }));
                }
            }

            return(Unauthorized());
        }
 public async Task <UserListDto> GetAll()
 {
     try
     {
         var usersDto = new UserListDto
         {
             Users = new List <UserDto>
             {
                 new UserDto
                 {
                     Id       = 1,
                     Username = "******"
                 },
                 new UserDto
                 {
                     Id       = 2,
                     Username = "******"
                 }
             },
             Page          = 1,
             PageSize      = 10,
             PageSizeTotal = 2
         };
         return(await Task.FromResult(usersDto));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Exemple #4
0
        public UserListDto GetUserByQuery(UserListDto queryDto)
        {
            var _user = _userRepository.FirstOrDefault(null);

            //_user.Where<User>(m => { });
            return(_user.MapTo <UserListDto>());
        }
Exemple #5
0
        public UserListDto GetAll()
        {
            UserListDto dto = new UserListDto();

            dto.Users = userManager.Users;

            return(dto);
        }
        private void SingIn(UserListDto user, ClaimsIdentity identity = null, bool rememberMe = false)
        {
            if (identity == null)
            {
                identity = _userAppServicep.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
            }
            AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
            AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = rememberMe }, identity);

        }
Exemple #7
0
        private void FrmUserList_Load(object sender, EventArgs e)
        {
            var users = _userService.GetirHepsi();
            List <UserListDto> models = new List <UserListDto>();

            foreach (var item in users)
            {
                UserListDto userListDto = new UserListDto();
                userListDto.Id   = item.Id;
                userListDto.Name = item.Name;
                models.Add(userListDto);
            }
            dgwUserList.DataSource = models;
        }
Exemple #8
0
 public async Task <IActionResult> GetList([FromQuery] int limit, [FromQuery] int offset)
 {
     try
     {
         var list   = _mapper.Map <IEnumerable <UserDto> >(await _dbContext.Users.Skip(offset).Take(limit).ToListAsync());
         var result = new UserListDto()
         {
             Total = await _dbContext.Users.CountAsync(),
             List  = list
         };
         return(Ok(result));
     }
     catch (Exception err)
     {
         return(BadRequest(err.Message));
     }
 }
        public async Task <UserListDto> List(int page = 0, int size = 5, string search = null)
        {
            try
            {
                using (DHContext db = new DHContext())
                {
                    var users = db.Users.AsNoTracking().AsQueryable();
                    if (!string.IsNullOrEmpty(search))
                    {
                        users = users.Where(user => (user.Login.ToLower() == search.ToLower()));
                    }
                    var TotalCount = await users.CountAsync();

                    users = users.OrderBy(user => user.Login).Skip(page * size).Take(size);
                    var EntityItems = await users.Include(d => d.Role).Include(d => d.Profile).ToListAsync();

                    var items = EntityItems.Select(user => new UserDto
                    {
                        UserId    = user.Id,
                        FullName  = user.Profile != null ? user.Profile.LastName + ' ' + user.Profile.FirstName + ' ' + user.Profile.MiddleName : string.Empty,
                        Gender    = user.Profile != null? user.Profile.Gender : string.Empty,
                        Login     = user.Login,
                        ProfileId = user.ProfileId != null ? user.ProfileId.Value : Guid.Empty,
                        RoleId    = user.RoleId,
                        RoleName  = user.Role.Name
                    }).ToList();
                    var obj = new UserListDto
                    {
                        UserDtos   = items,
                        TotalCount = TotalCount,
                        Page       = page + 1,
                        PageSize   = size,
                        PageCount  = (TotalCount % size) > 0 ? TotalCount / size + 1 : TotalCount / size
                    };
                    return(obj);
                }
            }
            catch (Exception exc)
            {
                _logger.Error($"Failed get list users : {exc}");
                throw;
            }
        }
        public async Task <UserListDto> UpdateUserAsync(UserListDto user)
        {
            try
            {
                var client  = new RestClient("https://webattackapi.azurewebsites.net/api/Admin/update-user");
                var request = new RestRequest(Method.POST)
                {
                    RequestFormat = DataFormat.Json
                };
                request.AddJsonBody(user);
                var result = await client.ExecuteAsync <UserListDto>(request);

                return(result.Data);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Exemple #11
0
        public async Task <IActionResult> Index(UserListDto model, IFormFile sekil)
        {
            TempData["Active"] = TempDataInfo.Profil;
            if (ModelState.IsValid)
            {
                var User =
                    _userManager.Users.FirstOrDefault(m => m.Id == model.Id);
                if (sekil != null)
                {
                    string uzanti  = Path.GetExtension(sekil.FileName);
                    string sekilAd = Guid.NewGuid() + uzanti;
                    string path    = Path.Combine(Directory.GetCurrentDirectory()
                                                  , "wwwroot/img/" + sekilAd);
                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await sekil.CopyToAsync(stream);
                    }

                    User.Picture = sekilAd;
                }

                User.Name    = model.Name;
                User.SurName = model.SurName;
                User.Email   = model.Email;

                var result = await _userManager.UpdateAsync(User);

                if (result.Succeeded)
                {
                    TempData["message"] = "Gunellendi";
                    return(RedirectToAction("Index"));
                }
                else
                {
                    XetaElaveEt(result.Errors);
                }
            }
            return(View(model));
        }
        public FileDto GetListUsersToExcel()
        {
            var data = _hoSoRepository.GetAll();
            List <UserListDto> listuser = new List <UserListDto>();

            foreach (var d in data)
            {
                var           user        = new UserListDto();
                List <string> arrListName = d.HoVaTen.Split(' ').ToList();
                arrListName.Remove("");

                user.Surname = d.HoVaTen.Trim().Replace(arrListName.Last(), "");
                user.Name    = arrListName.Last();

                var arrUserName = ConvertToUnSign(d.HoVaTen.Trim()).Split('-').ToList();
                arrUserName.Remove("");
                user.UserName = arrUserName.Last().ToLower();
                arrUserName.Remove(arrUserName.Last());
                foreach (var u in arrUserName)
                {
                    user.UserName += u.Left(1);
                }
                user.UserName         = user.UserName.Replace('đ', 'd');
                user.EmailAddress     = $"{user.UserName}@gosft.com.vn";
                user.PhoneNumber      = d.DtDiDong;
                user.IsActive         = true;
                user.IsEmailConfirmed = false;
                user.CreationTime     = DateTime.Now;
                user.Roles            = new List <UserListRoleDto>()
                {
                    new UserListRoleDto()
                    {
                        RoleName = "Nhân viên"
                    }
                };
                listuser.Add(user);
            }
            return(_userListExcelExporter.ExportToFile(listuser));
        }
 public LoginResultDto(UserListDto user, ClaimsIdentity identity)
     : this(LoginResultType.Success)
 {
     User = user;
     Identity = identity;
 }
Exemple #14
0
        public void Handle(DtoAggregateEvent <ISingleSignOnToken, UserDto> message)
        {
            UserListDto dto;

            switch (message.GetEventType())
            {
            case DtoAggregateEventType.Created:
                dto = new UserListDto(message.Id, message.New.Name);
                if (ReadModelFacade.UseSqlDatabase)
                {
                    using (var datastore = new SqlDatabase())
                        datastore.UserListDtoStore.Add(dto);
                }
                else
                {
                    InMemoryDatabase.UserList.Add(dto);
                }
                break;

            case DtoAggregateEventType.Updated:
                if (ReadModelFacade.UseSqlDatabase)
                {
                    using (var datastore = new SqlDatabase())
                    {
                        dto = datastore.UserList.SingleOrDefault(x => x.Id == message.Id);
                        if (dto != null)
                        {
                            dto.Name = message.New.Name;
                            datastore.UserListDtoStore.Update(dto);
                        }
                    }
                }
                else
                {
                    dto = InMemoryDatabase.UserList.SingleOrDefault(x => x.Id == message.Id);
                    if (dto != null)
                    {
                        InMemoryDatabase.UserList.Remove(dto);
                        InMemoryDatabase.UserList.Add(new UserListDto(message.Id, message.New.Name));
                    }
                }

                if (dto == null)
                {
                    throw new InvalidOperationException("Did not find the original item. This shouldn't happen.");
                }
                break;

            case DtoAggregateEventType.Deleted:
                if (ReadModelFacade.UseSqlDatabase)
                {
                    using (var datastore = new SqlDatabase())
                    {
                        dto = datastore.UserList.SingleOrDefault(x => x.Id == message.Id);
                        if (dto != null)
                        {
                            dto.Name = message.New.Name;
                            datastore.UserListDtoStore.Remove(dto);
                        }
                    }
                }
                else
                {
                    dto = InMemoryDatabase.UserList.SingleOrDefault(x => x.Id == message.Id);
                    if (dto != null)
                    {
                        InMemoryDatabase.UserList.Remove(dto);
                    }
                }

                if (dto == null)
                {
                    throw new InvalidOperationException("Did not find the original item. This shouldn't happen.");
                }
                break;

            default:
                throw new InvalidOperationException("Unknown event. This shouldn't happen.");
            }
        }
        public ClaimsIdentity CreateIdentity(UserListDto user, string authenticationType)
        {
            var identity =  new ClaimsIdentity(authenticationType, ClaimTypes.NameIdentifier, AbpClaimTypes.RoleClaimType);
            if (user.Id != null)
            {
                identity.AddClaim(new Claim(AbpClaimTypes.UserIdClaimType, user.Id.ToString()));
            }
            if (user.RoleId!=null)
            {
                identity.AddClaim(new Claim(AbpClaimTypes.RoleClaimType, user.RoleId.ToString()));
            }
         
            if (user.ManageOrgId != null)
            {
                identity.AddClaim(new Claim(AbpClaimTypes.OrgIdClaimType, user.ManageOrgId.ToString()));
            }

            return identity;
        }