public HttpResponseMessage SavePermission(HttpRequestMessage request, SavePermissionRequest data)
        {
            string connectionstring = "server=DESKTOP-I9HJM7B; Database=DuAnWebApi_Angular; uid=DamNgocSon ; pwd =123 ;";

            if (ModelState.IsValid)
            {
                _permissionService.DeleteAll(data.FunctionId);
                _permissionService.SaveChange();
                Permission permission = null;
                foreach (var item in data.Permissions)
                {
                    permission = new Permission();
                    permission.UpdatePermission(item);
                    permission.FunctionId = data.FunctionId;
                    _permissionService.Add(permission);
                }
                var functions = _functionService.GetAllWithParentID(data.FunctionId);
                if (functions.Any())
                {
                    using (SqlConnection conn = new SqlConnection(connectionstring))
                    {
                        foreach (var item in functions)
                        {
                            conn.Open();
                            SqlCommand sqlCommand = new SqlCommand("DeletePermissionWithFunctionId", conn);
                            sqlCommand.CommandType = CommandType.StoredProcedure;

                            sqlCommand.ExecuteNonQuery();
                            conn.Close();
                            foreach (var p in data.Permissions)
                            {
                                var childPermission = new Permission();
                                childPermission.FunctionId = item.ID;
                                childPermission.RoleId     = p.RoleId;
                                childPermission.CanRead    = p.CanRead;
                                childPermission.CanCreate  = p.CanCreate;
                                childPermission.CanDelete  = p.CanDelete;
                                childPermission.CanUpdate  = p.CanUpdate;
                                _permissionService.Add(childPermission);
                            }
                        }
                    }
                }
                try
                {
                    _permissionService.SaveChange();
                    return(request.CreateResponse(HttpStatusCode.OK, "Lưu quyền thành cống"));
                }
                catch (Exception ex)
                {
                    return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
                }
            }
            else
            {
                return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
コード例 #2
0
        public HttpResponseMessage SavePermission(HttpRequestMessage request, SavePermissionRequest data)
        {
            if (ModelState.IsValid)
            {
                _permissionService.DeleteAll(data.FunctionId);

                Permission permission = null;
                foreach (var item in data.Permissions)
                {
                    string[] result = JsonConvert.DeserializeObject<string[]>(item.RoleId);
                    foreach (var role in result)
                    {
                        var roleId = AppRoleManager.Roles.Where(x => x.Name == role.ToString()).FirstOrDefault();
                        item.RoleId = roleId.Id;
                        permission = new Permission();
                        permission.UpdatePermission(item);
                        permission.FunctionId = data.FunctionId;
                        _permissionService.Add(permission);
                    }
                }
                var functions = _functionService.GetAllWithParentID(data.FunctionId);
                if (functions.Any())
                {
                    foreach (var item in functions)
                    {
                        _permissionService.DeleteAll(item.ID);

                        foreach (var p in data.Permissions)
                        {
                            var childPermission = new Permission();
                            childPermission.FunctionId = item.ID;
                            childPermission.RoleId = p.RoleId;
                            childPermission.CanRead = p.CanRead;
                            childPermission.CanCreate = p.CanCreate;
                            childPermission.CanDelete = p.CanDelete;
                            childPermission.CanUpdate = p.CanUpdate;
                            _permissionService.Add(childPermission);
                        }
                    }
                }
                try
                {
                    _permissionService.SaveChange();
                    return request.CreateResponse(HttpStatusCode.OK, "Lưu quyền thành cống");
                }
                catch (Exception ex)
                {
                    return request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message);
                }
            }
            else
            {
                return request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
コード例 #3
0
        public ActionResult <AddModel <PermissionModel> > Add()
        {
            try
            {
                return(Ok(_servicePermission.Add()));
            }

            catch (Exception exception)
            {
                ModelState.AddModelError("ErrorMessage", exception.Message);
                return(BadRequest(ModelState));
            }
        }
コード例 #4
0
        public async Task <IActionResult> SavePermission([FromBody] SavePermissionRequest data)
        {
            if (!ModelState.IsValid)
            {
                IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
                return(new BadRequestObjectResult(allErrors));
            }
            try
            {
                _permissionService.DeleteAll(data.FunctionId);
                foreach (var item in data.Permissions)
                {
                    var permissionVm = new PermissionViewModel()
                    {
                        CanCreate  = item.CanCreate,
                        CanDelete  = item.CanDelete,
                        CanRead    = item.CanRead,
                        CanUpdate  = item.CanUpdate,
                        RoleId     = item.RoleId,
                        FunctionId = data.FunctionId
                    };
                    _permissionService.Add(permissionVm);
                }
                var functions = _functionService.GetAllWithParentId(data.FunctionId);
                if (functions.Any())
                {
                    foreach (var item in functions)
                    {
                        _permissionService.DeleteAll(item.Id);

                        foreach (var p in data.Permissions)
                        {
                            var childPermissionVm = new PermissionViewModel();
                            childPermissionVm.FunctionId = item.Id;
                            childPermissionVm.RoleId     = p.RoleId;
                            childPermissionVm.CanRead    = p.CanRead;
                            childPermissionVm.CanCreate  = p.CanCreate;
                            childPermissionVm.CanDelete  = p.CanDelete;
                            childPermissionVm.CanUpdate  = p.CanUpdate;
                            _permissionService.Add(childPermissionVm);
                        }
                    }
                }
                _permissionService.SaveChange();
                return(new NoContentResult());
            }
            catch (Exception ex)
            {
                return(new BadRequestObjectResult(ex.Message));
            }
        }
コード例 #5
0
 /// <summary>
 /// 权限主表操作
 /// </summary>
 /// <param name="test"></param>
 /// <returns></returns>
 public IActionResult PermissionAdd(PermissionDTO test)
 {
     try
     {
         if (test.oper == "add")
         {
             test.CreateTime = DateTime.Now;
             test.Creator    = "administrator";
             var res = _permissionService.Add(test);
             if (res.Code == 0)
             {
                 return(Ok("success"));
             }
             else
             {
                 return(NotFound("failed"));
             }
         }
         if (test.oper == "edit")
         {
             test.ModifyTime = DateTime.Now;
             test.Modifier   = "administrator";
             var res = _permissionService.Update(test);
             if (res.Code == 0)
             {
                 return(Ok("success"));
             }
             else
             {
                 return(NotFound("failed"));
             }
         }
         if (test.oper == "delete")
         {
             var res = _permissionService.DeleteByID(test.Id);
             if (res.Code == 0)
             {
                 return(Ok("success"));
             }
             else
             {
                 return(NotFound("failed"));
             }
         }
         return(Ok("success"));
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #6
0
 public HttpResponseMessage SavePermission(HttpRequestMessage request, SavePermissionRequest data)
 {
     if (ModelState.IsValid)
     {
         _permissionService.DeleteAll(data.FunctionId);
         Permission permission = null;
         foreach (var item in data.Permissions)
         {
             permission = new Permission();
             permission.UpdatePermission(item);
             permission.FunctionId = data.FunctionId;
             _permissionService.Add(permission);
         }
         var functions = _functionService.GetAllWithParentID(data.FunctionId);
         if (functions.Any())
         {
             foreach (var item in functions)
             {
                 if (_permissionService.CheckContaint(item.ID))
                 {
                     _permissionService.DeleteAll(item.ID);
                 }
                 foreach (var p in data.Permissions)
                 {
                     var childPermission = new Permission();
                     childPermission.FunctionId = item.ID;
                     childPermission.RoleId     = p.RoleId;
                     childPermission.CanRead    = p.CanRead;
                     childPermission.CanCreate  = p.CanCreate;
                     childPermission.CanDelete  = p.CanDelete;
                     childPermission.CanUpdate  = p.CanUpdate;
                     _permissionService.Add(childPermission);
                 }
             }
         }
         try
         {
             _permissionService.SaveChange();
             return(request.CreateResponse(HttpStatusCode.OK, "Lưu quyền thành cống"));
         }
         catch (Exception ex)
         {
             return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
         }
     }
     else
     {
         return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
     }
 }
コード例 #7
0
        public ActionResult AddType(AddTypeViewModel permissionViewModel)
        {
            try
            {
                var permission = new Permission
                {
                    Name     = permissionViewModel.Name,
                    IsGlobal = permissionViewModel.IsGlobal
                };

                _permissionService.Add(permission);
                TempData[Constants.MessageViewBagName] = new GenericMessageViewModel
                {
                    Message     = "Permission Added",
                    MessageType = GenericMessages.success
                };
                Context.SaveChanges();
            }
            catch (Exception ex)
            {
                Context.RollBack();
                LoggingService.Error(ex);
                throw;
            }


            return(RedirectToAction("Index"));
        }
コード例 #8
0
        //[Permission(Action = ActionName.CanCreate)]
        public IHttpActionResult Create([FromBody] AppRoleDto role)
        {
            return(CreateResponse(() =>
            {
                if (!ModelState.IsValid)
                {
                    return BadRequest(ModelState);
                }

                var model = Mapper.Map <AppRoleDto, AppRole>(role);

                RoleManager.Create(model);

                //add new permissions for role
                foreach (var permission in role.Permissions)
                {
                    _permissionService.Add(new Permission
                    {
                        RoleId = model.Id,
                        FunctionId = permission.FunctionId,
                        CanRead = permission.CanRead,
                        CanUpdate = permission.CanUpdate,
                        CanDelete = permission.CanDelete,
                        CanCreate = permission.CanCreate
                    });
                }

                UnitOfWork.Commit();


                return Created(new Uri(Request.RequestUri + "/" + model.Id), role);
            }));
        }
コード例 #9
0
        public ServiceResult <RoleEntity> Update(RoleEntity roleEntity, List <PermissionDescriptor> permissionDescriptors)
        {
            return(BeginTransaction(() =>
            {
                var permissions = _permissionService.Get(m => m.RoleId == roleEntity.ID);
                permissions.Each(m => m.ActionType = ActionType.Delete);
                permissionDescriptors.Where(m => m.Checked ?? false).Each(m =>
                {
                    bool exists = false;
                    foreach (var item in permissions)
                    {
                        if (item.PermissionKey == m.Key)
                        {
                            item.ActionType = ActionType.Update;
                            exists = true;
                        }
                    }
                    if (!exists)
                    {
                        permissions.Add(new Permission
                        {
                            RoleId = roleEntity.ID,
                            PermissionKey = m.Key,
                            Module = m.Module,
                            Title = m.Title,
                            ActionType = ActionType.Create
                        });
                    }
                });
                _permissionService.BeginBulkSave();
                permissions.Each(m =>
                {
                    switch (m.ActionType)
                    {
                    case ActionType.Create:
                        {
                            _permissionService.Add(m);
                            break;
                        }

                    case ActionType.Update:
                        {
                            _permissionService.Update(m);
                            break;
                        }

                    case ActionType.Delete:
                        {
                            _permissionService.Remove(m);
                            break;
                        }
                    }
                });
                _permissionService.SaveChanges();

                var old = Get(roleEntity.ID);
                roleEntity.CopyTo(old);
                return Update(old);
            }));
        }
コード例 #10
0
        public ActionResult AddType(AddTypeViewModel permissionViewModel)
        {
            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                try
                {
                    var permission = new Permission
                    {
                        Name = permissionViewModel.Name,
                    };

                    _permissionService.Add(permission);
                    TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel
                    {
                        Message     = "Permission Added",
                        MessageType = GenericMessages.success
                    };
                    unitOfWork.Commit();
                }
                catch (Exception ex)
                {
                    unitOfWork.Rollback();
                    LoggingService.Error(ex);
                    throw;
                }
            }

            return(RedirectToAction("Index"));
        }
コード例 #11
0
        public IActionResult Edit(RoleEntity entity, List <PermissionDescriptor> PermissionSet)
        {
            var permissions = _permissionService.Get(m => m.RoleId == entity.ID);

            permissions.Each(m => m.ActionType = ActionType.Delete);
            PermissionSet.Where(m => m.Checked ?? false).Each(m =>
            {
                bool exists = false;
                foreach (var item in permissions)
                {
                    if (item.PermissionKey == m.Key)
                    {
                        item.ActionType = ActionType.Update;
                        exists          = true;
                    }
                }
                if (!exists)
                {
                    permissions.Add(new Permission
                    {
                        RoleId        = entity.ID,
                        PermissionKey = m.Key,
                        Module        = m.Module,
                        Title         = m.Title,
                        ActionType    = ActionType.Create
                    });
                }
            });
            var old = Service.Get(entity.ID);

            entity.CopyTo(old);
            Service.Update(old);
            _permissionService.BeginBulkSave();
            permissions.Each(m =>
            {
                switch (m.ActionType)
                {
                case ActionType.Create:
                    {
                        _permissionService.Add(m);
                        break;
                    }

                case ActionType.Update:
                    {
                        _permissionService.Update(m);
                        break;
                    }

                case ActionType.Delete:
                    {
                        _permissionService.Remove(m);
                        break;
                    }
                }
            });
            _permissionService.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #12
0
 public async Task <IResultModel> Add(PermissionAddModel model)
 {
     if (!model.Actions.Any())
     {
         return(ResultModel.Failed("请选择操作"));
     }
     return(await _service.Add(model));
 }
コード例 #13
0
 public object Save([FromBody] Permission model)
 {
     try
     {
         if (model.Id != 0)
         {
             return(permissionService.Update(model));
         }
         else
         {
             return(permissionService.Add(model));
         }
     }
     catch (Exception ex)
     {
         return(errorLogService.InsertToErrorLog(ex, MethodBase.GetCurrentMethod().Name, Request.Headers["UserInfo"].ToString()));
     }
 }
コード例 #14
0
        public HttpResponseMessage SavePermission(HttpRequestMessage request, SavePermissionRequest data)
        {
            Func <HttpResponseMessage> func = () =>
            {
                HttpResponseMessage response = null;
                if (ModelState.IsValid)
                {
                    _permissionService.DeleteAll(data.FunctionId);
                    foreach (var item in data.Permissions)
                    {
                        Permission permission = new Permission();
                        permission.UpdatePermission(item);
                        permission.FunctionId = data.FunctionId;
                        _permissionService.Add(permission);
                    }
                    var functions = _functionService.GetAllWithParentID(data.FunctionId);
                    if (functions.Any())
                    {
                        foreach (var item in functions)
                        {
                            _permissionService.DeleteAll(item.ID);
                            foreach (var per in data.Permissions)
                            {
                                var permission = new Permission()
                                {
                                    FunctionId = item.ID,
                                    RoleId     = per.RoleId,
                                    CanCreate  = per.CanCreate,
                                    CanRead    = per.CanRead,
                                    CanDelete  = per.CanDelete,
                                    CanUpdate  = per.CanUpdate,
                                };
                                _permissionService.Add(permission);
                            }
                        }
                    }
                    _permissionService.SaveChange();
                    response = request.CreateResponse(HttpStatusCode.OK, "Lưu quyền thành công");
                }
                return(response);
            };

            return(CreateHttpResponse(request, func));
        }
コード例 #15
0
        // [AppAuthorize(PermissionTypes.Any, PermissionRule.update_news)]
        public IActionResult Add([FromBody] Permission permission)
        {
            if (!ModelState.IsValid)
            {
                var allErrors = ModelState.Values.SelectMany(v => v.Errors);
                return(new BadRequestObjectResult(new GenericResult(false, allErrors)));
            }
            else
            {
                try
                {
                    _permissionService.Add(permission);

                    return(new OkObjectResult(new GenericResult(true, "Add success!!!")));
                }
                catch (Exception ex)
                {
                    return(new OkObjectResult(new GenericResult(false, ex.Message)));
                }
            }
        }
コード例 #16
0
        public JsonResult SavePermission(string ID, string PermissionJson)
        {
            ReturnResult result = new ReturnResult();

            try
            {
                if (string.IsNullOrEmpty(PermissionJson))
                {
                    throw new NullReferenceException("请勾选权限");
                }
                var o_employee = _employeeService.SingleAndInit(ID);
                //TryUpdateModel(o_employee, null, Request.Form.AllKeys);
                List <KeyValuePair <string, int?> > permissions_ = PermissionJson.FromJson <List <KeyValuePair <string, int?> > >();
                Dictionary <string, int?>           permissions  = new Dictionary <string, int?>();
                permissions_.ForEach((item) => { permissions.Add(item.Key, item.Value); });

                //if (entity.Details == null) entity.Details = new List<SysRoleDetail>();
                var removeids = o_employee.Permissions.Where(s => !permissions.ContainsKey(s.MenuID)).Select(s => s.ID).ToList();
                foreach (var kv in permissions)
                {
                    if (!o_employee.Permissions.Any(s => s.MenuID == kv.Key))
                    {
                        Permission Permission = new Permission()
                        {
                            MenuID      = kv.Key,
                            Permissions = kv.Value,
                            UserID      = o_employee.ID
                        };
                        _permissionService.Add(Permission);
                        _dbTool.Commit();
                    }
                    else if (!o_employee.Permissions.Any(s => s.MenuID == kv.Key && s.Permissions == kv.Value))
                    {
                        var o_permission = o_employee.Permissions.FirstOrDefault(s => s.MenuID == kv.Key);
                        o_permission.Permissions = kv.Value;
                        _permissionService.Update(o_permission);
                        _dbTool.Commit();
                    }
                }
                _permissionService.Delete(s => removeids.Contains(s.ID));
                //_employeeService.Save(entity, entity.ID);
                _dbTool.Commit();
                //roleService.ClearCache();
                result.Status  = 200;
                result.Message = "保存成功!";
            }
            catch (Exception ex)
            {
                result.Message = ex.ToString();
            }
            return(Json(result));
        }
コード例 #17
0
        public bool AddPermission(PermissionRequestModel request)
        {
            PermissionViewModel existPermission = _permissionService.GetAll().FirstOrDefault(x => x.Name == request.Name);

            if (existPermission != null)
            {
                return(false);
            }

            Permission newPermission = new Permission();

            newPermission.Resource = request.Name;
            return(_permissionService.Add(newPermission));
        }
コード例 #18
0
        public IActionResult Add([FromBody] AddPermissionRequest addPermission)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Result result = _permissionService.Add(addPermission);

            if (result.Failure)
            {
                ModelState.AddErrors(result.Errors);
                return(BadRequest(ModelState));
            }

            return(Ok(new EmptyResult()));
        }
コード例 #19
0
        public async Task <MessageModel <string> > Post(Permission permission)
        {
            var data = new MessageModel <string>();

            if (permission != null)
            {
                permission.IsDelete   = false;
                permission.CreateTime = DateTime.Now;
                permission.ModifyTime = DateTime.Now;
                var result = await _permissionService.Add(permission).ConfigureAwait(false);

                data.Success = result > 0;
                if (data.Success)
                {
                    data.Response = result.ObjToString();
                    data.Msg      = "添加成功";
                }
            }

            // TODO:添加日志到数据库
            return(data);
        }
コード例 #20
0
        public virtual List <T> Add(List <T> entitiesToAdd)
        {
            _permissionService.Add();

            EntityExtensions.SetDefaultValuesOnEntities(entitiesToAdd);

            using (var context = _contextFactory.Create())
            {
                var dbSet = context.Set <T>();
                dbSet.AddRange(entitiesToAdd);

                try
                {
                    context.SaveChanges();
                }
                catch (DbEntityValidationException exception)
                {
                    WrapValidationException(exception);
                }
            }

            return(entitiesToAdd);
        }
コード例 #21
0
 public ActionResult <ApplicationRole> PostPermission(ApplicationRole permission)
 {
     permissionService.Add(permission);
     return(CreatedAtAction("GetPermission", new { id = permission.Id }, permission));
 }
コード例 #22
0
        public IHttpActionResult Post([FromBody] string[] ids)
        {
            _permissionService.Add(ids);

            return(Ok(ids));
        }
コード例 #23
0
        public ActionResult PermissionAdd(Permission permission)

        {
            _permissionService.Add(permission);
            return(RedirectToAction(""));
        }
コード例 #24
0
        public IHttpActionResult Post([FromBody] List <Permission> values)
        {
            _permissionService.Add(values.Select(p => p.PermissionId).ToArray());

            return(Ok(values));
        }
コード例 #25
0
        private InstallerResult CreateInitialData()
        {
            var installerResult = new InstallerResult {
                Successful = true, Message = "Congratulations, MVC Forum has installed successfully"
            };

            // I think this is all I need to call to kick EF into life
            //EFCachingProviderConfiguration.DefaultCache = new AspNetCache();
            //EFCachingProviderConfiguration.DefaultCachingPolicy = CachingPolicy.CacheAll;

            // Now setup the services as we can't do it in the constructor
            InitialiseServices();

            // First UOW to create the data needed for other saves
            using (var unitOfWork = _UnitOfWorkManager.NewUnitOfWork())
            {
                try
                {
                    // Check if category exists or not, we only do a single check for the first object within this
                    // UOW because, if anything failed inside. Everything else would be rolled back to because of the
                    // transaction
                    const string exampleCatName = "Example Category";
                    if (_categoryService.GetAll().FirstOrDefault(x => x.Name == exampleCatName) == null)
                    {
                        // Doesn't exist so add the example category
                        var exampleCat = new Category {
                            Name = exampleCatName, ModeratePosts = false, ModerateTopics = false
                        };
                        _categoryService.Add(exampleCat);

                        // Add the default roles
                        var standardRole = new MembershipRole {
                            RoleName = AppConstants.StandardMembers
                        };
                        var guestRole = new MembershipRole {
                            RoleName = AppConstants.GuestRoleName
                        };
                        var adminRole = new MembershipRole {
                            RoleName = AppConstants.AdminRoleName
                        };
                        _roleService.CreateRole(standardRole);
                        _roleService.CreateRole(guestRole);
                        _roleService.CreateRole(adminRole);

                        unitOfWork.Commit();
                    }
                }
                catch (Exception ex)
                {
                    unitOfWork.Rollback();
                    installerResult.Exception  = ex.InnerException;
                    installerResult.Message    = "Error creating the initial data >> Category & Roles";
                    installerResult.Successful = false;
                    return(installerResult);
                }
            }

            // Add / Update the default language strings
            installerResult = AddOrUpdateTheDefaultLanguageStrings(installerResult);
            if (!installerResult.Successful)
            {
                return(installerResult);
            }

            // Now we have saved the above we can create the rest of the data
            using (var unitOfWork = _UnitOfWorkManager.NewUnitOfWork())
            {
                try
                {
                    // if the settings already exist then do nothing
                    if (_settingsService.GetSettings(false) == null)
                    {
                        // Get the default language
                        var startingLanguage = _localizationService.GetLanguageByName("en-GB");

                        // Get the Standard Members role
                        var startingRole = _roleService.GetRole(AppConstants.StandardMembers);

                        // create the settings
                        var settings = new Settings
                        {
                            ForumName                   = "MVC Forum",
                            ForumUrl                    = "http://www.mydomain.com",
                            IsClosed                    = false,
                            EnableRSSFeeds              = true,
                            DisplayEditedBy             = true,
                            EnablePostFileAttachments   = false,
                            EnableMarkAsSolution        = true,
                            EnableSpamReporting         = true,
                            EnableMemberReporting       = true,
                            EnableEmailSubscriptions    = true,
                            ManuallyAuthoriseNewMembers = false,
                            EmailAdminOnNewMemberSignUp = true,
                            TopicsPerPage               = 20,
                            PostsPerPage                = 20,
                            EnablePrivateMessages       = true,
                            MaxPrivateMessagesPerMember = 50,
                            PrivateMessageFloodControl  = 1,
                            EnableSignatures            = false,
                            EnablePoints                = true,
                            PointsAllowedToVoteAmount   = 1,
                            PointsAddedPerPost          = 1,
                            PointsAddedForSolution      = 4,
                            PointsDeductedNagativeVote  = 2,
                            AdminEmailAddress           = "*****@*****.**",
                            NotificationReplyEmail      = "*****@*****.**",
                            SMTPEnableSSL               = false,
                            Theme = "Metro",
                            NewMemberStartingRole = startingRole,
                            DefaultLanguage       = startingLanguage,
                            ActivitiesPerPage     = 20,
                            EnableAkisment        = false,
                            EnableSocialLogins    = false,
                            EnablePolls           = true
                        };
                        _settingsService.Add(settings);

                        unitOfWork.Commit();
                    }
                }
                catch (Exception ex)
                {
                    unitOfWork.Rollback();
                    installerResult.Exception  = ex.InnerException;
                    installerResult.Message    = "Error creating the initial data >> Settings";
                    installerResult.Successful = false;
                    return(installerResult);
                }
            }


            // Now we have saved the above we can create the rest of the data
            using (var unitOfWork = _UnitOfWorkManager.NewUnitOfWork())
            {
                try
                {
                    // If the admin user exists then don't do anything else
                    if (_membershipService.GetUser("admin") == null)
                    {
                        // Set up the initial category permissions
                        var readOnly = new Permission {
                            Name = AppConstants.PermissionReadOnly
                        };
                        var deletePosts = new Permission {
                            Name = AppConstants.PermissionDeletePosts
                        };
                        var editPosts = new Permission {
                            Name = AppConstants.PermissionEditPosts
                        };
                        var stickyTopics = new Permission {
                            Name = AppConstants.PermissionCreateStickyTopics
                        };
                        var lockTopics = new Permission {
                            Name = AppConstants.PermissionLockTopics
                        };
                        var voteInPolls = new Permission {
                            Name = AppConstants.PermissionVoteInPolls
                        };
                        var createPolls = new Permission {
                            Name = AppConstants.PermissionCreatePolls
                        };
                        var createTopics = new Permission {
                            Name = AppConstants.PermissionCreateTopics
                        };
                        var attachFiles = new Permission {
                            Name = AppConstants.PermissionAttachFiles
                        };
                        var denyAccess = new Permission {
                            Name = AppConstants.PermissionDenyAccess
                        };

                        _permissionService.Add(readOnly);
                        _permissionService.Add(deletePosts);
                        _permissionService.Add(editPosts);
                        _permissionService.Add(stickyTopics);
                        _permissionService.Add(lockTopics);
                        _permissionService.Add(voteInPolls);
                        _permissionService.Add(createPolls);
                        _permissionService.Add(createTopics);
                        _permissionService.Add(attachFiles);
                        _permissionService.Add(denyAccess);

                        // Set up global permissions
                        var editMembers = new Permission {
                            Name = AppConstants.PermissionEditMembers, IsGlobal = true
                        };

                        _permissionService.Add(editMembers);

                        // create the admin user and put him in the admin role
                        var admin = new MembershipUser
                        {
                            Email      = "*****@*****.**",
                            UserName   = "******",
                            Password   = "******",
                            IsApproved = true,
                            DisableEmailNotifications = false,
                            DisablePosting            = false,
                            DisablePrivateMessages    = false
                        };
                        _membershipService.CreateUser(admin);

                        // Do a save changes just in case
                        unitOfWork.SaveChanges();

                        // Put the admin in the admin role
                        var adminRole = _roleService.GetRole(AppConstants.AdminRoleName);
                        admin.Roles = new List <MembershipRole> {
                            adminRole
                        };

                        unitOfWork.Commit();
                    }
                }
                catch (Exception ex)
                {
                    unitOfWork.Rollback();
                    installerResult.Exception  = ex.InnerException;
                    installerResult.Message    = "Error creating the initial data >> Admin user & Permissions";
                    installerResult.Successful = false;
                    return(installerResult);
                }
            }

            return(installerResult);
        }
コード例 #26
0
        public ActionResult Add(Permission entity, int moduleId)
        {
            var data = permissionService.Add(entity, moduleId);

            return(Json(new { code = 200, message = "添加成功!", action = data }));
        }
コード例 #27
0
 public Task <IResultModel> Add(PermissionAddModel model)
 {
     return(_service.Add(model));
 }
コード例 #28
0
 public async Task <Result> Add(AddPermissionDto dto)
 {
     return(await _permissionService.Add(_mapper.Map <Permission>(dto)));
 }