public void UserRoleService_Get()
        {
            UserRoleService service = new UserRoleService(mockRepository.Object, mockMapper.Object);

            var result = service.Get();

            Assert.IsNotNull(result);
        }
Exemple #2
0
        protected override async void OnAppearing()
        {
            // try
            // {


            RegisterUserModel user = JsonConvert.DeserializeObject <RegisterUserModel>(Application.Current.Properties["User"].ToString());
            UserRoleModel     ur   = await userRoleService.Get(user.ActiveUserRoleID);

            if (ur != null)
            {
                switch (ur.RoleID)
                {
                case 1:
                    Application.Current.MainPage = new NavigationPage(new DefaultSuperAdminPage());
                    break;

                case 2:
                    Application.Current.MainPage = new NavigationPage(new AdminsPage());
                    break;

                case 3:
                    Application.Current.MainPage = new NavigationPage(new UserHomePage());
                    break;

                case 4:
                    DefaultCouriersPage main = new DefaultCouriersPage();
                    //main.Master = new DefaultCouriersPageMaster();
                    //main.Detail = new DefaultCouriersPageDetail();
                    Application.Current.MainPage = new NavigationPage(main);
                    break;

                case 5:
                    Application.Current.MainPage = new NavigationPage(new DispatcherHomeMDPage());
                    break;
                }
            }
            else
            {
                Application.Current.Properties.Remove("User");
                Application.Current.MainPage = new NavigationPage(new WelcomeTabbedPage());
            }

            //catch (Exception)
            //{
            //    //await DisplayAlert("Greska", ex.Message + ex.InnerException, "ok");
            //}
            base.OnAppearing();
        }
Exemple #3
0
        public ActionResult List()
        {
            int    pageIndex = Request["page"] == null ? 1 : int.Parse(Request["page"]);
            int    pageSize  = Request["rows"] == null ? 1 : int.Parse(Request["rows"]);
            string sortName  = Request["sort"];
            string sortOrder = Request["order"];
            bool   IsAsc     = sortOrder == null ? true : sortOrder.ToUpper().Equals("ASC");
            int    total     = 0;

            var data = service.Get(t => true, sortName, pageSize, pageIndex, out total, IsAsc);
            //var data = service.Get(t => true, "Role").ToList();
            var result = new { total = total, rows = data };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult <User> Create([FromForm] AccountModel account)
        {
            var curUser = _userService.GetUserByUsername(account.Username);

            if (curUser != null)
            {
                return(BadRequest(new { message = "Username has been used" }));
            }
            var role = _roleService.Get(account.RoleId);

            if (role == null)
            {
                return(BadRequest(new { message = "Role Not Found" }));
            }
            var  md5      = new MD5CryptoServiceProvider();
            var  passHash = md5.ComputeHash(Encoding.ASCII.GetBytes(account.Password));
            User user     = new User()
            {
                Username        = account.Username,
                PasswordHash    = Encoding.ASCII.GetString(passHash),
                AccessFailCount = 0,
                Role            = role,
                UserClaims      = new UserClaim()
                {
                    Email       = account.Email,
                    PhoneNumber = account.PhoneNumber,
                    DateOB      = account.DateOB,
                    FullName    = account.FullName,
                    Address     = account.Address
                }
            };

            _userService.Create(user);

            return(CreatedAtRoute("GetUser", new { id = user.Id.ToString() }, user));
        }
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IUserRoleRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <UserRole>(null));
            var service = new UserRoleService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.UserRoleModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLUserRoleMapperMock,
                                              mock.DALMapperMockFactory.DALUserRoleMapperMock);

            ApiUserRoleResponseModel response = await service.Get(default(string));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <string>()));
        }