Ejemplo n.º 1
0
        public void Search_ByOperationUser_NoResults()
        {
            //Arrange
            var user1 = _userAccountService.FindByUserName("admin");
            var user2 = _userAccountService.Create(new UserAccountViewModel {
                UserName = "******"
            });

            var userName = user1.UserName;
            const OperationType operationType = OperationType.Login;
            int?         patientId            = null;
            const string dateFrom             = "";
            const string dateTo        = "";
            const string operationData = "";
            const string sorting       = "";
            const int    pageNumber    = 1;
            const int    pageSize      = 10;

            var task = _operationService.Log(operationType, user2.Id);

            task.Wait();

            //Act
            var result = _operationService.Search(userName, null, patientId,
                                                  dateFrom, dateTo, operationData, sorting, pageNumber, pageSize);

            //Assert
            Assert.That(result, Is.Empty);
        }
Ejemplo n.º 2
0
        public ActionResult Create(UserModels userModel)
        {
            Role selectedRole = _accountService.GetRoles().Where(i => i.Name == "Anonymous").FirstOrDefault();

            if (ModelState.IsValid)
            {
                List <Role> roles = new List <Role>();
                roles.Add(selectedRole);
                userModel.User.Roles = roles;
            }
            else
            {
                userModel.RoleList = _accountService.GetRoles();
                return(View(userModel));
            }

            try
            {
                userModel.User.UserStatus = true;
                _accountService.Create(userModel.User);
                return(RedirectToAction("Login", "Account", new { Message = "Registration Successful. Please login..." }));
            }
            catch (Exception ex)
            {
                userModel.RoleList = _accountService.GetRoles();

                ModelState.AddModelError("User", ex.Message);
                return(View(userModel));
            }
        }
Ejemplo n.º 3
0
        public ActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var result = accountService.Create(model);
                if (result.ResultType == ResultType.Success)
                {
                    return(RedirectToAction("Login"));
                }
                ViewBag.Result = result.ResultMessage;
            }

            return(View(model));
        }
Ejemplo n.º 4
0
        public async Task <Instructor> Create(InstructorCreationData data)
        {
            await _registrationValidationService.TrowsIfEmailIsNotUniq(data.Email);

            Account account = await _userAccountService.Create(_mapper.Map <AccountCreationData>(data));

            var instructor = await _unitOfWork.Add(new Instructor
            {
                Account = account,
            });

            await _userAccountService.SendEmailConfirmation(account);

            await _unitOfWork.Commit();

            return(instructor);
        }
Ejemplo n.º 5
0
        public async Task <Student> Create(StudentCreationData data)
        {
            await _registrationValidationService.TrowsIfEmailIsNotUniq(data.Email);

            Account account = await _userAccountService.Create(_mapper.Map <AccountCreationData>(data));

            var student = await _unitOfWork.Add(new Student
            {
                Account   = account,
                FirstName = data.FirstName,
                LastName  = data.LastName,
                Group     = data.Group,
            });

            await _userAccountService.SendEmailConfirmation(account);

            await _unitOfWork.Commit();

            return(student);
        }
Ejemplo n.º 6
0
        public ActionResult Register(UserAccountViewModel user)
        {
            if (!ModelState.IsValid)
            {
                return(View(user));
            }

            //If user is already registered show message
            if (_userAccountService.IsRegistered(user.UserName))
            {
                ModelState.AddModelError(string.Empty, Strings.UserAlreadyExists);
            }
            else
            {
                var validCredentials = _userAccountService.ValidateCredentials(user.UserName, user.Password);

                //Check if the authentication failed
                if (validCredentials == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, Strings.AuthenticationError));
                }

                //Check credentials
                if (validCredentials == true)
                {
                    var newUser = _userAccountService.Create(user);

                    //Log the correct registration
                    _userAccountService.Log(OperationType.Register, newUser.Id, data: "UserName: "******", Addr: " + Request.HostAddress());

                    //Redirect to login
                    return(RedirectToAction("Login", new { registered = 1 }));
                }

                //If incorrect credentials, add the error
                ModelState.AddModelError(string.Empty, Strings.LoginError);
            }

            return(View(user));
        }
Ejemplo n.º 7
0
        public void Search_SortDefault()
        {
            //Arrange
            var user1 = _userAccountService.FindByUserName("admin");
            var user2 = _userAccountService.Create(new UserAccountViewModel {
                UserName = "******"
            });

            const string      id             = "";
            const string      userName       = "";
            UserAccountType?  type           = null;
            UserAccountStatus?status         = null;
            const string      registeredFrom = "";
            const string      registeredTo   = "";
            const string      sorting        = "";
            const int         pageNumber     = 1;
            const int         pageSize       = 10;

            //Act
            var result = _userAccountService.Search(id, userName, type, status,
                                                    registeredFrom, registeredTo, sorting, pageNumber, pageSize);

            //Assert
            Assert.That(result[0], Is.EqualTo(user2));
            Assert.That(result[1], Is.EqualTo(user1));
        }
Ejemplo n.º 8
0
        public ActionResult <UserAccountResponse> Create(CreateUserAccountRequest newAccountDTO)
        {
            var account = _service.Create(newAccountDTO);

            return(Ok(account));
        }