コード例 #1
0
        public async Task <TaskResult <RolesDto> > SaveAsync(RolesDto roleDto)
        {
            var guid = Guid.NewGuid();
            var role = new IdentityRole
            {
                Id   = guid.ToString(),
                Name = roleDto.Name
            };

            var result = new TaskResult <RolesDto>();

            try
            {
                _context.Roles.Add(role);
                await _context.SaveChangesAsync();

                result.Message = $"Se agregó el role {role.Name}";
            }
            catch (Exception e)
            {
                result.Success = false;
                result.Message = $"Error al intentar agregar al Role: {e.Message}";
            }
            return(result);
        }
コード例 #2
0
        private static RolesDto ConvertFromRepositoryEntity(Roles accountRoles)
        {
            if (accountRoles == null)
            {
                return(null);
            }
            var rolesDto = new RolesDto
            {
                Id          = accountRoles.Id,
                HotelID     = accountRoles.HotelID,
                RoleID      = accountRoles.RoleID,
                Title       = accountRoles.Title,
                Description = accountRoles.Description
            };

            if (accountRoles.CreateTime != null)
            {
                rolesDto.CreateTime = accountRoles.CreateTime.Value;
            }
            else
            {
                rolesDto.CreateTime = DateTime.MinValue;
            }

            if (accountRoles.UpdateTime != null)
            {
                rolesDto.UpdateTime = accountRoles.UpdateTime.Value;
            }
            else
            {
                rolesDto.UpdateTime = DateTime.MinValue;
            }

            return(rolesDto);
        }
コード例 #3
0
        private static Roles ConvertFromDto(RolesDto rolesDto)
        {
            if (rolesDto == null)
            {
                return(null);
            }
            var accountRole = new Roles
            {
                Id          = rolesDto.Id,
                HotelID     = rolesDto.HotelID,
                RoleID      = rolesDto.RoleID,
                Title       = rolesDto.Title,
                Description = rolesDto.Description
            };

            if ((rolesDto?.CreateTime ?? DateTime.MinValue) > DateTime.MinValue)
            {
                accountRole.CreateTime = rolesDto.CreateTime;
            }
            if ((rolesDto?.UpdateTime ?? DateTime.MinValue) > DateTime.MinValue)
            {
                accountRole.UpdateTime = rolesDto.UpdateTime;
            }
            return(accountRole);
        }
コード例 #4
0
        public async Task <TaskResult <RolesDto> > UpdateAsync(RolesDto roleDto)
        {
            var roles = new IdentityRole
            {
                Id   = roleDto.Id,
                Name = roleDto.Name
            };

            var result = new TaskResult <RolesDto>();

            try
            {
                _context.Roles.Add(roles);
                _context.Entry(roles).State = System.Data.Entity.EntityState.Modified;
                await _context.SaveChangesAsync();

                result.Data    = roleDto;
                result.Message = "El registro fue actualizado correctamente";
            }
            catch (Exception e)
            {
                result.Success = false;
                result.Message = $"Error al intentar actualizar información del role: {e.Message}";
            }
            return(result);
        }
コード例 #5
0
 public async Task <int> AddRoles(RolesDto model)
 {
     return(await _service.AddAsync(new Roles()
     {
         RolesName = model.RolesName
     }));
 }
コード例 #6
0
        public ActionResult <RolesDto> GetRights()
        {
            var claimsIdentity = User.Identity as ClaimsIdentity;

            var roles = new RolesDto();

            if (claimsIdentity == null || !claimsIdentity.IsAuthenticated)
            {
                return(roles);
            }
            else
            {
                roles.IsConnected = true;
            }

            var userRole = claimsIdentity.FindFirst(ClaimTypes.Role).Value;

            switch (userRole)
            {
            case "admin":
                roles.IsAdmin = true;
                break;

            case "groom":
                roles.IsGroom = true;
                break;

            case "secretary":
                roles.IsSecretary = true;
                break;
            }

            return(roles);
        }
コード例 #7
0
        public async Task <IActionResult> UpdateUserRoles(Guid userID, RolesDto userRoles)
        {
            var user = await this.Repository.GetUserWithRoles(userID);

            var addedRoles   = userRoles.Roles;
            var removedRoles = new List <string>();

            foreach (var role in user.UserRoles)
            {
                if (userRoles.Roles.Any(roleName => roleName.Equals(role.Role.Name, StringComparison.InvariantCultureIgnoreCase)))
                {
                    addedRoles.Remove(role.Role.Name);
                }
                else
                {
                    removedRoles.Add(role.Role.Name);
                }
            }

            var addResult = await this.UserManager.AddToRolesAsync(user, addedRoles);

            if (addResult.Succeeded == false)
            {
                return(this.BadRequest(addResult.Errors));
            }

            var removeResult = await this.UserManager.RemoveFromRolesAsync(user, removedRoles);

            if (removeResult.Succeeded == false)
            {
                return(this.BadRequest(removeResult.Errors));
            }

            return(this.Ok());
        }
コード例 #8
0
        public async Task <bool> UpdateAsync(RolesDto role)
        {
            var rolemapp = _mapper.Map <AppRole>(role);
            //for some strange reason it doesn not work since it give a tracking error...
            var rs = await _roleManager.UpdateAsync(rolemapp);

            return(rs.Succeeded);
        }
コード例 #9
0
        public async Task <bool> CreateAsync(RolesDto model)
        {
            var role = new AppRole();
            var map  = _mapper.Map(model, role);
            var rs   = await _roleManager.CreateAsync(map);

            return(rs.Succeeded);
        }
コード例 #10
0
 //编辑
 public static int Update(RolesDto model)
 {
     // UsersDto users;
     using (IDbConnection conn = MySqlConnection())
     {
         return(conn.Execute("update role set Name=@Name where Id=@Id", model));
     }
 }
コード例 #11
0
        public IActionResult GetRoles(string app)
        {
            var response = RolesDto.FromApp(App);

            Response.Headers[HeaderNames.ETag] = App.Version.ToString();

            return(Ok(response));
        }
コード例 #12
0
ファイル: AppRolesController.cs プロジェクト: yjpark/squidex
        private async Task <RolesDto> InvokeCommandAsync(ICommand command)
        {
            var context = await CommandBus.PublishAsync(command);

            var result   = context.Result <IAppEntity>();
            var response = RolesDto.FromApp(result, this);

            return(response);
        }
コード例 #13
0
        public async Task <ActionResult> Update([FromBody] RolesDto role)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var rs = await _rolesService.UpdateAsync(role);

            return(Ok(rs));
        }
コード例 #14
0
ファイル: AppRolesController.cs プロジェクト: yjpark/squidex
        public IActionResult GetRoles(string app)
        {
            var response = Deferred.Response(() =>
            {
                return(RolesDto.FromApp(App, this));
            });

            Response.Headers[HeaderNames.ETag] = App.ToEtag();

            return(Ok(response));
        }
コード例 #15
0
            //插入
            public static int Insert(RolesDto model)
            {
                int result;

                using (IDbConnection conn = MySqlConnection())
                {
                    result = conn.Execute("Insert into role values (@Id,@Name)", model);
                }

                return(result);
            }
コード例 #16
0
 public int Update(RolesDto model)
 {
     if (model == null)
     {
         return(0);
     }
     else
     {
         var accountRole = ConvertFromDto(model);
         return(_userRepository.UpdateNonDefaults(accountRole, x => x.Id == accountRole.Id));
     }
 }
コード例 #17
0
 public bool Add(RolesDto model)
 {
     if (model == null)
     {
         return(false);
     }
     else
     {
         var account = ConvertFromDto(model);
         return(_userRepository.Insert(account) > 0);
     }
 }
コード例 #18
0
        public async Task <ActionResult> Edit(RolesDto Data)
        {
            if (!ModelState.IsValid)
            {
                return(View(new TaskResult <RolesDto> {
                    Data = Data
                }));
            }

            var model = await _rolesRepository.UpdateAsync(Data);

            return(View(model));
        }
コード例 #19
0
        public async Task <IActionResult> Post([FromBody] RolesDto roleDto)
        {
            if (!User.Identity.IsAuthenticated)
            {
                throw new AuthenticationException();
            }
            var role = _mapper.Map <Roles>(roleDto);
            await _roleService.InsertRole(role);

            roleDto = _mapper.Map <RolesDto>(role);
            var response = new ApiResponse <RolesDto>(roleDto);

            return(Ok(response));
        }
コード例 #20
0
        public async Task <IActionResult> Put(int id, RolesDto roleDto)
        {
            if (!User.Identity.IsAuthenticated)
            {
                throw new AuthenticationException();
            }
            var role = _mapper.Map <Roles>(roleDto);

            role.Id = id;
            var result = await _roleService.UpdateRole(role);

            var response = new ApiResponse <bool>(result);

            return(Ok(response));
        }
コード例 #21
0
        public async Task <IActionResult> EditRoles(string username, RolesDto roles)
        {
            var user = await _userManager.FindByNameAsync(username);

            var currentRoles = _userManager.GetRolesAsync(user);

            if (roles.isAdmin && !currentRoles.Result.Contains("Admin"))
            {
                var result = await _userManager.AddToRoleAsync(user, "Admin");

                if (!result.Succeeded)
                {
                    return(BadRequest("Failed to add admin role"));
                }
            }
            else if (!roles.isAdmin && currentRoles.Result.Contains("Admin"))
            {
                var result = await _userManager.RemoveFromRoleAsync(user, "Admin");

                if (!result.Succeeded)
                {
                    return(BadRequest("Failed to remove admin role"));
                }
            }

            if (roles.isModerator && !currentRoles.Result.Contains("Moderator"))
            {
                var result = await _userManager.AddToRoleAsync(user, "Moderator");

                if (!result.Succeeded)
                {
                    return(BadRequest("Failed to add moderator role"));
                }
            }
            else if (!roles.isModerator && currentRoles.Result.Contains("Moderator"))
            {
                var result = await _userManager.RemoveFromRoleAsync(user, "Moderator");

                if (!result.Succeeded)
                {
                    return(BadRequest("Failed to remove moderator role"));
                }
            }

            var x = await _userManager.GetRolesAsync(user);

            return(Ok(x));
        }
コード例 #22
0
        public TeamEmployeeDto TeamEmployeeDetails(int teamID)
        {
            TeamEmployeeDto    teamEmpDetail = new TeamEmployeeDto();
            List <EmployeeDto> teamEmp       = new List <EmployeeDto>();

            try
            {
                var Team = Context.TeamDetails
                           .FirstOrDefault(td => td.TeamID == teamID);

                var TeamEmployee = Context.Employees
                                   .Include(emp => emp.employeeRoles)
                                   .Where(emp => emp.TeamDetails.TeamID == Team.TeamID)
                                   .ToList();
                teamEmpDetail.TeamId          = Team.TeamID;
                teamEmpDetail.TeamName        = Team.TeamName;
                teamEmpDetail.LeadName        = Team.TeamLeadName;
                teamEmpDetail.TeamDiscription = Team.TeamDiscription;

                foreach (Employee emp in TeamEmployee)
                {
                    EmployeeDto empDto  = new EmployeeDto();
                    RolesDto    roleDto = new RolesDto();
                    empDto.EmployeeId  = emp.EmployeeId;
                    empDto.FirstName   = emp.FirstName;
                    empDto.LastName    = emp.LastName;
                    empDto.PhotoUrl    = emp.EmployeePhotoURL;
                    empDto.Dob         = emp.Dob;
                    empDto.JoiningDate = emp.JoiningDate;
                    empDto.EmailId     = emp.EmailID;

                    roleDto.RoleName = emp.employeeRoles.RoleName;
                    empDto.Role      = roleDto;

                    teamEmp.Add(empDto);
                }
                teamEmpDetail.TeamEmployees = teamEmp;
            }
            catch (SqlException expSql)
            {
                throw expSql;
            }
            catch (NullReferenceException expNull)
            {
                throw expNull;
            }
            return(teamEmpDetail);
        }
コード例 #23
0
        public JsonResult Create(RolesDto item)
        {
            OperationResult r = new OperationResult();

            try
            {
                item.Id = Guid.NewGuid().ToString();
                Roles.Insert(item);
                r.ResultType = OperationResultType.Success;
            }
            catch (Exception ex)
            {
                r.Message    = "新增失败,请检查所填数据是否正确。";
                r.ResultType = OperationResultType.Error;
            }
            return(Json(r));
        }
コード例 #24
0
        private static RolesDto ConvertFromBllEntity(AccountsRoles accountRoles)
        {
            if (accountRoles == null)
            {
                return(null);
            }
            RolesDto accountDto = new RolesDto()
            {
                Id          = accountRoles.Id,
                HotelID     = accountRoles.HotelID,
                RoleID      = accountRoles.RoleID,
                Description = accountRoles.Description,
                Title       = accountRoles.Title
            };

            return(accountDto);
        }
コード例 #25
0
        private static AccountsRoles ConvertFromDto(RolesDto rolesDto)
        {
            if (rolesDto == null)
            {
                return(null);
            }
            AccountsRoles user = new AccountsRoles()
            {
                Id          = rolesDto.Id,
                HotelID     = rolesDto.HotelID,
                RoleID      = rolesDto.RoleID,
                Description = rolesDto.Description,
                Title       = rolesDto.Title
            };

            return(user);
        }
コード例 #26
0
        public ActionResult UpdateRole(RolesDto model)
        {
            var result = new StandardJsonResult <string>();

            result.Try(() =>
            {
                if (!ModelState.IsValid)
                {
                    throw new KnownException(ModelState.GetFirstError());
                }
                var service   = Ioc.GetService <IRolesManagementService>();
                model.OwnerID = "";
                bool i        = service.UpdateRole(model);
                result.Value  = i + "";
            });
            return(result);
        }
コード例 #27
0
        public JsonResult Edit(RolesDto item)
        {
            OperationResult r = new OperationResult();

            try
            {
                Roles.Update(item);
                r.ResultType = OperationResultType.Success;
            }
            catch
            {
                r.Message    = "失败,请检查数据。";
                r.ResultType = OperationResultType.Error;
            }

            return(Json(r));
        }
コード例 #28
0
        public IActionResult GetPerson(int id)
        {
            var Person = Roles.SingleOrDefault(x => x.id == id);

            if (Person == null)
            {
                logger.LogInformation($"Person with {id} was not found");
                return(NotFound());
            }
            var result = new RolesDto
            {
                id        = Person.id,
                name      = Person.name,
                shortName = Person.shortName,
            };

            return(Ok(result));
        }
コード例 #29
0
        public async Task <IActionResult> AddRolesToUser([FromRoute] string userId, [FromBody] RolesDto addRoles, CancellationToken ct)
        {
            var user = await _userManager.FindByIdAsync(userId);

            if (user == null)
            {
                return(NotFound());
            }

            var currentRoles = await _userManager.GetRolesAsync(user);

            await _userManager.RemoveFromRolesAsync(user, currentRoles.ToArray());

            await _userManager.AddToRolesAsync(user, addRoles.Roles.ToArray());

            var finalRoles = await _userManager.GetRolesAsync(user);

            return(Ok(finalRoles));
        }
コード例 #30
0
 public IActionResult AddNewRole([FromBody] RolesDto newRole,
                                 [FromHeader(Name = "id_token")] string googleToken)
 {
     try
     {
         if (googleAuth.ProcessRequestAtGoogle(googleToken))
         {
             var RoleAddStatus = empRepository.AddRole(newRole);
             return(Ok(Json(RoleAddStatus)));
         }
         else
         {
             return(BadRequest());
         }
     }
     catch (Exception exp)
     {
         return(NotFound(@"Can't add the given Department"));
     }
 }