Пример #1
0
        public IHttpActionResult PutUsersPermissions(int id, UsersPermissions usersPermissions)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != usersPermissions.Broj)
            {
                return(BadRequest());
            }

            db.Entry(usersPermissions).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UsersPermissionsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #2
0
 public static UserPermissionReturnDto ToUserPermissionReturnDto(this UsersPermissions userRole)
 {
     return(new UserPermissionReturnDto
     {
         User = userRole.User.ToUserReturnDto(),
         Permission = userRole.Permission.ToPermissionReturnDto()
     });
 }
Пример #3
0
        public IHttpActionResult GetUsersPermissions(int id)
        {
            UsersPermissions usersPermissions = db.UsersPermissions.Find(id);

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

            return(Ok(usersPermissions));
        }
Пример #4
0
        public IHttpActionResult PostUsersPermissions(UsersPermissions usersPermissions)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.UsersPermissions.Add(usersPermissions);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = usersPermissions.Broj }, usersPermissions));
        }
Пример #5
0
        public IHttpActionResult DeleteUsersPermissions(int id)
        {
            UsersPermissions usersPermissions = db.UsersPermissions.Find(id);

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

            db.UsersPermissions.Remove(usersPermissions);
            db.SaveChanges();

            return(Ok(usersPermissions));
        }
Пример #6
0
        public AuthorizationService()
        {
            Type serviceIdType = typeof (ServiceIDAttribute);
            object[] attrs = GetType().GetCustomAttributes(serviceIdType, false);
            if (attrs != null && attrs.Length != 0)
            {
                _ServiceId = new Guid(((ServiceIDAttribute) attrs[0]).ID);
            }

            _PermissionStorage = new PermissionStorage();
            _UsersPermissions = new UsersPermissions();

            GenuineGlobalEventProvider.GenuineChannelsGlobalEvent +=
                GenuineGlobalEventProvider_GenuineChannelsGlobalEvent;
        }
        public async Task <UserPermissionReturnDto> AddPermissionToUserAsync(long userId, long permissionId)
        {
            var user =
                await _userRepository.GetByIdAsync(userId);

            if (user == null)
            {
                throw new ObjectNotFoundException("User not found.");
            }

            var permission =
                await _permissionRepository.GetByIdAsync(permissionId);

            if (permission == null)
            {
                throw new ObjectNotFoundException("Permission not found.");
            }

            var userToRoleConnection =
                await(await _usersPermissionsRepository.GetAllAsync(d => d.User == user && d.Permission == permission))
                .FirstOrDefaultAsync();

            if (userToRoleConnection != null)
            {
                throw new ObjectNotFoundException("User already have permission.");
            }

            var userToRoleForDb = new UsersPermissions
            {
                User       = user,
                Permission = permission
            };

            var connection = (await _usersPermissionsRepository.InsertAsync(userToRoleForDb));

            connection.User       = user;
            connection.Permission = permission;
            return(connection.ToUserPermissionReturnDto());
        }
Пример #8
0
        public int Add(UsersPermissions model)
        {
            string sql = "insert into UsersPermissions(UsersPermissions_Id,UsersPermissions_RolesId,UsersPermissions_SystemMenuId,UsersPermissions_DeleteId,UsersPermissions_CreateTime,UsersPermissions_UpdateTime) values(@UsersPermissions_Id,@UsersPermissions_RolesId,@UsersPermissions_SystemMenuId,@UsersPermissions_DeleteId,@UsersPermissions_CreateTime,@UsersPermissions_UpdateTime)";

            return(SqlHelper <UsersPermissions> .ExceuteNonQuery(sql, model));
        }
Пример #9
0
 public int Add(UsersPermissions model)
 {
     return(dal.Add(model));
 }