Esempio n. 1
0
        public IActionResult Create(PermissionCreateViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            if (model.Name.Trim().Length <= 0)
            {
                response.SetFailed("请输入权限名称");
                return(Ok(response));
            }
            using (_dbContext)
            {
                if (_dbContext.DncPermission.Count(x => x.ActionCode == model.ActionCode && x.MenuGuid == model.MenuGuid) > 0)
                {
                    response.SetFailed("权限操作码已存在");
                    return(Ok(response));
                }
                var entity = _mapper.Map <PermissionCreateViewModel, DncPermission>(model);
                entity.CreatedOn         = DateTime.Now;
                entity.Code              = RandomHelper.GetRandomizer(8, true, false, true, true);
                entity.CreatedByUserGuid = AuthContextService.CurrentUser.Guid;
                entity.CreatedByUserName = AuthContextService.CurrentUser.DisplayName;
                _dbContext.DncPermission.Add(entity);
                _dbContext.SaveChanges();

                response.SetSuccess();
                return(Ok(response));
            }
        }
Esempio n. 2
0
        public IActionResult Create(PermissionCreateViewModel model)
        {
            HttpResponseModel response = ResponseModelFactory.CreateInstance;

            if (model.Name.Trim().Length <= 0)
            {
                response.SetFailed("请输入权限名称");
                return(this.Ok(response));
            }

            using (this.DbContext)
            {
                if (this.DbContext.Permission.Count(x => x.ActionCode == model.ActionCode && x.Id == model.Id.ToString()) > 0)
                {
                    response.SetFailed("权限操作码已存在");
                    return(this.Ok(response));
                }

                Permission entity = this.Mapper.Map <PermissionCreateViewModel, Permission>(model);
                entity.CreateTime       = DateTime.Now;
                entity.Id               = Guid.NewGuid().ToString("N");
                entity.CreateByUserId   = AuthenticationContextService.CurrentUser.Id;
                entity.CreateByUserName = AuthenticationContextService.CurrentUser.DisplayName;
                this.DbContext.Permission.Add(entity);
                this.DbContext.SaveChanges();

                response.SetSuccess();
                return(this.Ok(response));
            }
        }
        public IActionResult Create(PermissionCreateViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            if (model.Name.Trim().Length <= 0)
            {
                response.SetFailed("请输入权限名称");
                return(Ok(response));
            }
            using (_dbContext)
            {
                if (_dbContext.SystemPermission.Count(x => x.ActionCode == model.ActionCode && x.SystemMenuUuid == model.SystemMenuUuid) > 0)
                {
                    response.SetFailed("权限操作码已存在");
                    return(Ok(response));
                }
                if (_dbContext.SystemPermission.Count(x => x.Name == model.Name && x.SystemMenuUuid == model.SystemMenuUuid) > 0)
                {
                    response.SetFailed("权限名称已存在");
                    return(Ok(response));
                }
                var entity = _mapper.Map <PermissionCreateViewModel, SystemPermission>(model);
                entity.SystemMenuUuid       = model.SystemMenuUuid;
                entity.CreatedOn            = DateTime.Now.ToString("yyyy-MM-dd");
                entity.SystemPermissionUuid = Guid.NewGuid();
                entity.CreatedByUserGuid    = AuthContextService.CurrentUser.Guid;
                entity.CreatedByUserName    = AuthContextService.CurrentUser.DisplayName;
                _dbContext.SystemPermission.Add(entity);
                _dbContext.SaveChanges();

                response.SetSuccess();
                return(Ok(response));
            }
        }
Esempio n. 4
0
        public async Task CreateByViewModelAsync(PermissionCreateViewModel viewModel)
        {
            var permission = _mapper.Map <Permission>(viewModel);

            _permissionRepository.Add(permission);

            await _unitOfWork.SaveAllChangesAsync();

            _eventPublisher.EntityInserted(permission);
        }
Esempio n. 5
0
        public ActionResult CreatePermission()
        {
            //prevents users from accessing the page if they are not logged in
            if (userSession.LoggedIn == false)
            {
                return(Content("You are not logged in ! Please login to view this page"));
            }

            //prevents users from accessing this functionality if they are not super admin
            Account account   = userSession.CurrentUser;
            var     adminUser = accountPermissionDAO.FetchByEmail(account.email);

            if (adminUser == null)
            {
                return(Content("Only Super Admin users are permitted to view this page"));
            }

            if (adminUser.Permission.name != "SuperAdmin")
            {
                return(Content("Only Super Admin users are permitted to view this page"));
            }

            PermissionCreateViewModel model = new PermissionCreateViewModel();

            model.adminUser = true;
            if (userSession.LoggedIn == true)
            {
                model.userSession = true;
            }

            else if (userSession.LoggedIn != true)
            {
                model.userSession = false;
            }
            model.loggedInAccount   = account;
            model.loggedInAccountID = account.accountID;
            model.permissionType    = adminUser.Permission.name;
            return(View(model));
        }
Esempio n. 6
0
        public ActionResult CreatePermission(PermissionCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                Permission permission = new Permission
                {
                    name = model.name
                };

                //prevents user from creating a permission that already exists
                var existingPermission = accountPermissionDAO.FetchPermissionByName(model.name);
                if (existingPermission != null)
                {
                    TempData["errorMessage"] = "This permission already exists";
                    return(RedirectToAction("PermissionIndex"));
                }

                else if (existingPermission == null)
                {
                    accountPermissionDAO.CreatePermission(permission);
                    alertService.AddPermissionCreatedAlert(permission);

                    if (permission != null)
                    {
                        TempData["SuccessMessage"] = "Permission was successfully created";
                    }

                    else
                    {
                        TempData["errorMessage"] = "Error saving Permission";
                    }

                    return(RedirectToAction("PermissionIndex"));
                }
            }

            return(View(model));
        }