Beispiel #1
0
        public async Task CreateRoleTest(string name)
        {
            var created = await _roleBusiness.CreateRole(new Role
            {
                Name        = name,
                Description = name,
                Permissions = new List <Permission>()
            });

            Assert.NotNull(created);
            Assert.Equal(created.Name, name);
        }
Beispiel #2
0
        public async Task <IHttpActionResult> Post([FromBody] RegisterViewModel registerView)
        {
            string lclRespondMsg = ValidationMessages.RespondMsg;

            try
            {
                var roleBusiness     = new RoleBusiness();
                var registerbusiness = new RegisterBusiness();
                var role             = registerView.Role;

                //CODESC:Check if user Exist
                if (registerbusiness.FindUser(registerView.userName, AuthenticationManager))
                {
                    ModelState.AddModelError("", "User name already taken");
                    return(Ok(ValidationMessages.UserNameTaken));
                }
                //CODESC:Check if user does'nt Exist else create a role for him/her
                if (!roleBusiness.RoleExists(role))
                {
                    roleBusiness.CreateRole(role);
                }
                //CODESC:Than check if user exist
                var result = await registerbusiness.RegisterUser(new RegisterModel
                {
                    UserName = registerView.userName,
                    Password = registerView.Password
                }, AuthenticationManager);

                //CODESC:If The Result Passes Register Admin and Vendor
                if (result)
                {
                    try
                    {
                        _dbVendor.Insert(registerView);
                        _dbBusinessAdmin.Insert(registerView);
                        registerbusiness.AddUserToRole(registerView.userName, role);
                        lclRespondMsg = "Saved Successfully";
                    }
                    catch (DbEntityValidationException e)
                    {
                        throw e.InnerException;
                    }
                }
            }
            catch (Exception ex)
            {
                throw  ex.InnerException;
            }
            return(Ok(lclRespondMsg));
        }
Beispiel #3
0
        public ActionResult AddRole(string name)
        {
            bool found = rb.RoleExists(name);

            if (found == true)
            {
                ViewBag.Result = "Role name " + name + " already exists.";
            }

            else
            {
                rb.CreateRole(name);
                ViewBag.Result = "Role created successfully.";
            }

            return(View());
        }
Beispiel #4
0
        public async Task <IActionResult> CreateRole([FromBody] Role role)
        {
            var results = await _roleBusiness.CreateRole(role);

            return(Ok(CommonResponse.Success(results)));
        }