Exemple #1
0
        public ActionResult <RightItem> getRight(int id)
        {
            RightItem right = rightsDB.getRight(id);

            if (right == null)
            {
                return(NotFound($"No right found for id: {id}"));
            }
            else
            {
                return(Ok(right));
            }
        }
Exemple #2
0
        /// <summary>
        /// Validate all Rights
        /// Throws RightIDNotFoundException and RightItemNotFoundException
        /// </summary>
        /// <param name="rights"></param>
        private void validateRights(RightItem[] rights)
        {
            if (rights.Length == 0)
            {
                throw new RightsNotFoundException();
            }
            foreach (RightItem right in rights)
            {
                if (String.IsNullOrWhiteSpace(right.RightID.ToString()))
                {
                    throw new RightIDNotFoundException(right.Path);
                }
                else
                {
                    RightItem databaseRight = rightsDB.getRight(right.RightID);
                    if (databaseRight == null)
                    {
                        throw new RightItemNotFoundException(right.RightID);
                    }
                }
                if (String.IsNullOrWhiteSpace(right.Path))
                {
                    throw new RightPathInvalidException(right.Path);
                }

                bool duplicateRightsID = rights.Where(x => x.RightID == right.RightID).ToArray().Length > 1;
                if (duplicateRightsID)
                {
                    throw new DuplicateRightsItemFoundException(right.RightID);
                }
            }
        }