예제 #1
0
        public void TestAdd()
        {
            var request = new Request <Role>()
            {
                Obj = new Role()
                {
                    RoleName       = "超级管理员",
                    CreateDate     = DateTime.Now,
                    CreateUserId   = 1,
                    CreateUserName = "******",
                    Remark         = "超级管理员, 拥有系统所有权限"
                }
            };

            new SysLogService().Add(new Request <SysLog>()
            {
                Obj = new SysLog()
                {
                    CreateDate = DateTime.Now,
                    Location   = "Test/RoleService",
                    Action     = "TestAdd",
                    Message    = JsonConvert.Serialize(request),
                    Type       = "添加",
                    UserId     = 1,
                    UserName   = "******"
                }
            });

            var response = service.Add(request);

            Assert.AreEqual(response.Status, 0);
        }
 public ActionResult AuthorizationEdit(int authorizationId, AuthorizationModel authorizationModel)
 {
     try
     {
         if (authorizationId == 0)
         {
             var item = new Role
             {
                 Name        = authorizationModel.Role.Name,
                 Description = authorizationModel.Role.Description,
             };
             RoleService.Add(item);
             Logger.Info(CurrentUser.Id + " idli kullanıcı " + item.Id + " idli yetki grubunu ekledi");
         }
         else
         {
             var item = RoleService.Get(authorizationId);
             item.Name        = authorizationModel.Role.Name;
             item.Description = authorizationModel.Role.Description;
             RoleService.Update(item);
             Logger.Info(CurrentUser.Id + " idli kullanıcı " + item.Id + " idli yetki grubunu güncelledi");
         }
     }
     catch (Exception e)
     {
         Logger.Error("Hata oluştu - " + new StackTrace().GetFrame(0).GetMethod().Name, e);
     }
     return(RedirectToAction("AuthorizationList"));
 }
예제 #3
0
        public async Task <ResponceModel> Add([FromBody] Role model)
        {
            var identifier = User.Claims.FirstOrDefault(p => p.Type == "id");

            if (identifier == null)
            {
                return(new ResponceModel(401, "FAILED", null, new string[] { "Yetkilendirme Hatası." }));
            }
            try
            {
                var role = await roleService.Add(model);

                if (await roleService.SaveChanges())
                {
                    return(new ResponceModel(200, "OK", role, null));
                }
                else
                {
                    return(new ResponceModel(404, "FAILD", null, new string[] { "Veri eklenirken sorun oluştu." }));
                }
            }
            catch (Exception ex)
            {
                await _logService.Add(new SystemLog()
                {
                    Content = ex.Message, CreateDate = DateTime.Now, UserId = 0, EntityName = roleService.GetType().Name
                });

                return(new ResponceModel(400, "ERROR", null, new string[] { "Veri eklenirken sorun oluştu." }));
            }
        }
예제 #4
0
        public IActionResult Add(AddRoleModel model)
        {
            var entity = model.MapTo <Role>();

            var reuslt = _roleService.Add(entity);

            return(Json(reuslt));
        }
예제 #5
0
        public IActionResult Add([FromBody] AddRoleViewModel model)
        {
            var role = roleService.Add(new M_Role {
                Name = model.Name
            });

            return(APIResult.成功.SetData("id", role.Id));
        }
예제 #6
0
 public ActionResult Add(string name, long[] permissionIds)
 {
     //RoleService.add
     RoleService.Add(name, permissionIds);
     return(Json(new AjaxResult <string> {
         Status = "ok"
     }));
 }
예제 #7
0
        public ActionResult Create(RoleIndexModel model)
        {
            if (ModelState.IsValid)
            {
                Service.Add(model.NewRole);
            }

            return(RedirectToAction("index", "Role"));
        }
예제 #8
0
 public IHttpActionResult AddRole(sys_role entry)
 {
     try
     {
         RoleService rs  = new RoleService();
         int         cnt = rs.Add(entry);
         return(cnt > 0 ? Json(new { code = 1, msg = "ok" }) : Json(new { code = 1, msg = "数据操作失败" }));
     }
     catch (Exception e)
     {
         return(Json(new { code = 0, msg = e.Message }));
     }
 }
예제 #9
0
        public void addrole()
        {
            RoleService rs = new RoleService();

            rs.Add(new sys_role
            {
                title   = "销售管理员",
                status  = 1,
                adduser = 1,
                code    = "03",
                addtime = System.DateTime.Now
            });
        }
예제 #10
0
        public void InitializeRole()
        {
            RoleService   roleService   = new RoleService();
            ActionService actionService = new ActionService();

            Role role = roleService.Add(new Role
            {
                RoleName = "系统管理员",
            });

            //关联角色和权限类型(Menu和模块)
            actionService.GetEntities(u => u.Id > 0).ToList().ForEach(m => m.Role.Add(role));
        }
예제 #11
0
 public ActionResult <Result <Role> > Post([FromBody] Role model)
 {
     try
     {
         _roleService.Add(model);
         _logger.LogInformation("Added one Role");
         return(new Result <Role>(true, "Role added successfully"));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, "Error occurred on Role adding");
         throw ex;
     }
 }
예제 #12
0
        public HttpResponseMessage PostNewRole(BRole bRole)
        {
            RoleResult          roleResult = roleService.Add(bRole);
            HttpResponseMessage response;

            if (roleResult.IsValid)
            {
                response = Request.CreateResponse(HttpStatusCode.OK, roleResult.bRoles.Single());
                return(response);
            }

            response = Request.CreateResponse(HttpStatusCode.BadRequest, roleResult.ErrorMessages);
            return(response);
        }
예제 #13
0
        public ActionResult <Role> Register([FromBody] Role role)
        {
            Console.WriteLine($"name {role.Name} description: {role.Description}");
            if (role.Name == null || role.Name.Length < 4)
            {
                return(BadRequest("role is empty ó no cumple"));
            }
            Role model = _roleService.Add(role);

            if (model == null)
            {
                return(BadRequest(model));
            }
            return(Ok(model));
        }
예제 #14
0
        public IHttpActionResult Post([FromBody] dynamic data)
        {
            Role role = roleService.Add(new Role()
            {
                RoleName = (String)data["RoleName"].Value
            });

            if (role == null)
            {
                return(Ok(new
                {
                    code = 0,
                    data = ""
                }));
            }
            return(Ok(new { code = 1 }));
        }
예제 #15
0
        public void RoleService_Add()
        {
            RoleService service = new RoleService(mockRepository.Object, mockMapper.Object);

            Role role = new Role()
            {
                RoleTitle   = "Test Role",
                RoleId      = 1,
                Description = "Unit Test Role",
                CreatedDate = DateTime.Now,
                CreatedUser = "******",
            };

            bool result = service.Add(role);

            Assert.IsFalse(result);
        }
예제 #16
0
        public void Check_That_Role_Service_Adds_Role()
        {
            // A
            var mock = new Mock <IUnitOfWork>();

            mock.Setup(m => m.RoleRepository.Insert(It.IsAny <Role>()));

            var roleService = new RoleService(mock.Object);

            RoleModel roleModel = GetRoleModel();

            // A
            roleService.Add(roleModel);

            // A
            mock.Verify(m => m.RoleRepository.Insert(It.IsAny <Role>()));
        }
예제 #17
0
        public IHttpActionResult AddRole(SysRole sysRole)
        {
            var roleService = new RoleService();
            var maxRoleNum  = roleService.GetAll().Select(item => item.RoleNum).LastOrDefault();
            int RoleNum     = Int32.Parse(maxRoleNum);

            RoleNum++;
            sysRole.CreateTime = DateTime.Now;
            sysRole.IsDelete   = 0;
            sysRole.RoleNum    = RoleNum.ToString().PadLeft(6, '0');
            var addRole = roleService.Add(sysRole);
            var result  = new
            {
                Count = addRole?"添加成功":"添加失败"
            };

            return(Json(result));
        }
예제 #18
0
        public JsonResult InstallRl(int type, string data)
        {
            var result = new AjaxResultModel {
                success = false,
                code    = 400,
                message = "Error: Installation.InstallRl."
            };

            try {
                if (!_dbManager.DatabaseIsInstalled())
                {
                    throw new iPemException("数据库尚未配置,请完成配置后重试。");
                }

                var model      = JsonConvert.DeserializeObject <iPem.Site.Models.Installation.RoleModel>(data);
                var repository = new U_RoleRepository(_dbManager.CurrentConnetions[EnmDbType.Sc]);
                var service    = new RoleService(repository, _cacheManager);
                var installed  = (type == 0);

                var entity = service.GetRoleById(U_Role.SuperId);
                if (entity != null)
                {
                    service.Remove(entity);
                }

                entity = new U_Role()
                {
                    Id      = U_Role.SuperId,
                    Name    = model.name,
                    Comment = model.comment,
                    Enabled = true
                };

                service.Add(entity);
                result.success = true;
                result.code    = 200;
                result.message = "OK";
            } catch (Exception err) {
                result.message = err.Message;
            }

            return(Json(result));
        }
예제 #19
0
 public ActionResult Create(RoleModel model)
 {
     if (ModelState.IsValid)
     {
         if (roleService.AlreadyExists(model.Name, Guid.Empty))
         {
             ModelState.AddModelError("Name", "角色名重复");
         }
         else
         {
             roleService.Add(model.ToEntity());
             return(Json(new AjaxResult()
             {
                 Result = Result.Success
             }));
         }
     }
     return(View(model));
 }
예제 #20
0
        public JsonResult Add(Role role)
        {
            var entity = new Role()
            {
                RoleName       = role.RoleName,
                Remark         = role.Remark,
                Enabled        = role.Enabled,
                SortCode       = role.SortCode,
                CreateUserId   = SessionUser.Data.Id,
                CreateUserName = SessionUser.Data.UserName,
                CreateDate     = DateTime.Now
            };

            var response = service.Add(new Qz.Core.Entity.Request <Role>
            {
                Obj = entity
            });

            return(Json(response));
        }
예제 #21
0
        public async Task <JsonResult> RoleAdd(Role role, string MenuIds)
        {
            try
            {
                role.MenuIds = Tools.GetIntIds(MenuIds).ToList();
                _logService.Debug(string.Format("添加角色参数!role = 【{0}】", role.ToJSON()));
                var ret = await _roleService.Add(role);

                if (ret)
                {
                    RefreshCache();
                }
                return(Json(new { isadd = ret }));
            }
            catch (Exception ex)
            {
                _logService.Error(string.Format("添加角色失败!role = 【{0}】", role.ToJSON()), ex);
                return(Json(new { isadd = false }));
            }
        }
예제 #22
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            var obj = new ROLE();

            obj.ROLE_CODE = popTxtRoleCode.Text;
            obj.ROLE_NAME = popTxtRoleName.Text;
            var cmd = new RoleService(obj);

            if (flag.Text.Equals("Add"))
            {
                obj.Action             = ActionEnum.Create;
                obj.CREATE_DATE        = DateTime.Now;
                obj.CREATE_EMPLOYEE_ID = 0;
                obj.UPDATE_DATE        = DateTime.Now;
                obj.UPDATE_EMPLOYEE_ID = 0;
                obj.SYE_DEL            = true;
                cmd.Add();
            }
            else
            {
                obj.Action             = ActionEnum.Update;
                obj.ROLE_ID            = Convert.ToInt32(ViewState["RoleId"].ToString());
                obj.UPDATE_DATE        = DateTime.Now;
                obj.UPDATE_EMPLOYEE_ID = 0;
                obj.SYE_DEL            = true;
                cmd.Edit();
            }
            if (DataSouceNewRoleFunction.Count > 0)
            {
                foreach (ROLE_FUNCTION item in DataSouceNewRoleFunction)
                {
                    item.ROLE_ID = obj.ROLE_ID;
                }
                var cmdRoleFunction = new RoleFunctionService(DataSouceNewRoleFunction);
                cmdRoleFunction.AddList();
            }
            ViewState["RoleId"] = null;
            Response.Redirect("SearchRole.aspx");
        }
예제 #23
0
 // POST: api/Product
 public bec_Role Post([FromBody] bec_Role role)
 {
     return(roleService.Add(role));
 }
예제 #24
0
        public IActionResult Add(RoleFormParams roleFormParams)
        {
            var result = _roleService.Add(roleFormParams.ToDto <RoleFormParams, RoleAddAndEditModel>());

            return(Json(result));
        }
예제 #25
0
 // POST: api/Role
 public Response AddRole([FromBody] Role data)
 {
     return(rs.Add(data));
 }
예제 #26
0
        public RoleEditViewModel AddRole(RoleEditViewModel RoleEditView)
        {
            var Role = RoleService.Add(RoleEditView);

            return(Role);
        }
예제 #27
0
        private static void DbInitialize()
        {
            Role adminRole = new Role {
                Name = "Admin", ContentManager = true, UserAdmin = true, Seller = true, Сourier = true
            };
            Role contentManager = new Role {
                Name = "ContentManager", ContentManager = true, UserAdmin = false, Seller = false, Сourier = false
            };
            RoleService roleService = new RoleService();

            roleService.Add(adminRole);
            roleService.Add(contentManager);
            roleService.Add(new Role {
                Name = "Courier", ContentManager = false, UserAdmin = false, Seller = false, Сourier = true
            });
            roleService.Add(new Role {
                Name = "Seller", ContentManager = false, UserAdmin = false, Seller = true, Сourier = false
            });
            roleService.Add(new Role {
                Name = "Customer", ContentManager = false, UserAdmin = false, Seller = false, Сourier = false
            });

            //adminRole.Id = contentManager.Id = 0;

            //RoleService roleService = new RoleService();
            //var adminRole = roleService.GetAll().FirstOrDefault(x => x.UserAdmin == true);
            //var contentManager = roleService.GetAll().FirstOrDefault(x => x.UserAdmin == false);

            User adminUser = new User {
                Login = "******", Password = "******", RoleId = adminRole.Id
            };
            User contentUser = new User {
                Login = "******", Password = "******", RoleId = contentManager.Id
            };
            AccountService accountService = new AccountService();

            accountService.Add(adminUser);
            accountService.Add(contentUser);


            CarBrand renault = new CarBrand {
                Name = "Ranault", ImagePath = "test1"
            };
            CarBrand citroen = new CarBrand {
                Name = "Citroen", ImagePath = "test2"
            };
            CarBrand peugeot = new CarBrand {
                Name = "Peugeot", ImagePath = "test3"
            };
            CarBrand bugatti = new CarBrand {
                Name = "Bugatti", ImagePath = "test4"
            };
            CarBrandService carBrandService = new CarBrandService();

            carBrandService.Add(renault);
            carBrandService.Add(citroen);
            carBrandService.Add(peugeot);
            carBrandService.Add(bugatti);

            CarModel logan = new CarModel {
                Name = "Logan", CarBrandId = renault.Id
            };
            CarModel stepway = new CarModel {
                Name = "Stepway", CarBrandId = renault.Id
            };
            CarModel kaptur = new CarModel {
                Name = "Kaptur", CarBrandId = renault.Id
            };
            CarModel koleos = new CarModel {
                Name = "Koleos", CarBrandId = renault.Id
            };
            CarModelService carModelService = new CarModelService();

            carModelService.Add(logan);
            carModelService.Add(stepway);
            carModelService.Add(kaptur);
            carModelService.Add(koleos);

            Console.WriteLine("DB has been initialized");
        }
 public void Post(ViewModels.RoleEditViewModel model)
 {
     RoleService.Add(model);
 }
예제 #29
0
 public async Task <IResultModel <int> > Add(RoleEntity model)
 {
     return(await _service.Add(model));
 }
 public static int Add(Role r)
 {
     return(RoleService.Add(r));
 }