Пример #1
0
        public IHttpActionResult SaveDelegation([FromUri] int userRoleId, [FromBody] MyDelegationsModel myDelegations)
        {
            var sourceUserRole = _adminUserRoleService.GetById(userRoleId);
            var delegation     = new DelegationDTO
            {
                Id                  = myDelegations.DelegationId,
                SourceUserRole      = sourceUserRole,
                DestinationUserRole = new UserRoleDTO
                {
                    RoleId    = sourceUserRole.RoleId,
                    UserId    = myDelegations.UserId,
                    StartDate = myDelegations.StartDate,
                    EndDate   = myDelegations.EndDate
                }
            };

            var newGroups = _groupService.GetByIds(myDelegations.GroupCheckedIds).Select(x => x.Description);

            IList <string> oldGroupsFixed = new List <string>();

            if (myDelegations.DelegationId != 0)
            {
                var existingDelegation = _delegationService.Get(myDelegations.DelegationId);
                var oldGroups          = _authorizationService.GetAllowedGroups(existingDelegation.DestinationUserRole.Id);
                oldGroupsFixed = _groupService.GetByIds(oldGroups).Select(x => x.Description).ToList();
            }

            _delegationService.Save(delegation, myDelegations.GroupCheckedIds);

            var user = _userService.GetUserById(myDelegations.UserId);
            var role = _roleService.GetRoleByUserRoleId(userRoleId);

            _auditService.Log(AuditEntryDTOBuilder.Build(
                                  myDelegations.DelegationId == 0 ? AuditAction.DelegationCreated : AuditAction.DelegationEdited,
                                  _connectionInfo.UserId,
                                  null,
                                  myDelegations.DelegationId == 0 ? null : new[] { _connectionInfo.UserName, role.Name, user.Username, myDelegations.StartDate?.ToShortDateString() ?? "", myDelegations.EndDate?.ToShortDateString() ?? "", string.Join <string>(",", oldGroupsFixed) },
                                  new[] { _connectionInfo.UserName, role.Name, user.Username, myDelegations.StartDate?.ToShortDateString() ?? "", myDelegations.EndDate?.ToShortDateString() ?? "", string.Join <string>(",", newGroups) },
                                  _auditHelper.GetIdentity()));
            return(Ok(delegation));
        }
Пример #2
0
        public IHttpActionResult DeleteDelegation(int id)
        {
            var existingDelegation = _delegationService.Get(id);
            var oldGroups          = _authorizationService.GetAllowedGroups(existingDelegation.DestinationUserRole.Id);
            var oldGroupsFixed     = _groupService.GetByIds(oldGroups).Select(x => x.Description).ToList();

            _delegationService.Delete(id);

            _auditService.Log(AuditEntryDTOBuilder.Build(
                                  AuditAction.DelegationDeleted,
                                  _connectionInfo.UserId,
                                  null,
                                  new[] { _connectionInfo.UserName,
                                          existingDelegation.DestinationUserRole.Role.Name,
                                          existingDelegation.DestinationUserRole.User.Username,
                                          existingDelegation.DestinationUserRole.StartDate?.ToShortDateString() ?? "",
                                          existingDelegation.DestinationUserRole.EndDate?.ToShortDateString() ?? "",
                                          string.Join <string>(",", oldGroupsFixed) },
                                  null,
                                  _auditHelper.GetIdentity()));
            return(Ok("Delegation removed successfully!"));
        }