Example #1
0
        public void CreateUserTest()
        {
            //Arrange
            var userRepo = new UserDetailRepository();
            var user     = new UserDetailVm
            {
                City   = "Orastie",
                County = "Hunedoara",
                PersonalDescription = "Short description working!!!",
                Phone            = "0754566257",
                Position         = "Junior web developer",
                SelectedFile     = "Teorie.pdf",
                SelectedFileName = "D:/files/Teorie_20200616231210.pdf",
                UserModelId      = 6
            };

            //Act
            var userDetail = userRepo.GetById(4);

            //Assert
            Assert.AreEqual(userDetail, user);
        }
Example #2
0
        public object Post([FromBody] UserDetailVm userDetailVm)
        {
            var identity  = HttpContext.User.Identity as ClaimsIdentity;
            var userClaim = _authService.GetClaim(identity);

            try
            {
                _logger.LogInfo($"{MethodInfoHelper.GetCurrentMethodName()} started.");
                var user = _authService.AuthorizeUser(Convert.ToInt32(userClaim[4].Value));
                if (user != null)
                {
                    var file   = userDetailVm.SelectedFile.Replace("data:application/pdf;base64,", String.Empty);
                    var data   = Convert.FromBase64String(file);
                    var stream = new MemoryStream(data);
                    userDetailVm.SelectedFile = _employeeDetail.CreateFile(userDetailVm.SelectedFileName, data);

                    var employeeDetail = _mapper.Map <UserDetail>(userDetailVm);
                    if (employeeDetail != null)
                    {
                        _unitOfWork.Employees.Insert(employeeDetail);
                        _unitOfWork.Employees.Save();
                    }
                    return(Ok(new { message = "Success" }));
                }
                else
                {
                    return(new { message = "Unauthorize" });
                }
            }
            catch (AppException ex)
            {
                _logger.LogError($"{MethodInfoHelper.GetCurrentMethodName()} failed.", ex);
                throw;
            }
            finally
            {
                _logger.LogInfo($"{MethodInfoHelper.GetCurrentMethodName()} ended.");
            }
        }
        public async Task <IActionResult> AddRolesToUser(UserDetailVm user)
        {
            await _userService.ChangeUserRolesAsync(user.Id, user.UserRoles);

            return(RedirectToAction("Index"));
        }
Example #4
0
        public async Task <IActionResult> ManageRoles(UserDetailVm user)
        {
            await _adminPanelService.ChangeUserRolesAsync(user.Id, user.UserRoles);

            return(RedirectToAction("Index"));
        }