Exemplo n.º 1
0
        public static ErrorCodes OnDocumentTransfer(CorporationDocument corporationDocument, Character targetCharacter)
        {
            var ec = ErrorCodes.NoError;

            //check amount per type on target character
            if (corporationDocument.DocumentConfig.maxPerCharacter > 0)
            {
                var amount = GetAmountByType(corporationDocument._documentType, targetCharacter);

                if (amount >= corporationDocument.DocumentConfig.maxPerCharacter)
                {
                    return(ErrorCodes.NotEnoughDocumentSlots);
                }
            }


            return(ec);
        }
Exemplo n.º 2
0
        private static ErrorCodes GetSingleDocumentFromSql(int documentId, out CorporationDocument corporationDocument)
        {
            corporationDocument = null;
            const string commandStr = LowDetailSelect + " where id=@id";


            var record =
                Db.Query().CommandText(commandStr).SetParameter("@id", documentId)
                .ExecuteSingleRow();

            if (record == null)
            {
                return(ErrorCodes.ItemNotFound);
            }

            corporationDocument = new CorporationDocument(record);

            return(ErrorCodes.NoError);
        }
        public static ErrorCodes CreateNewToSql(Character character, CorporationDocumentType corporationDocumentType, DateTime?validUntil, string body, out CorporationDocument corporationDocument)
        {
            corporationDocument = null;
            const string cmdStr = InsertQuery + ";select cast(scope_identity() as int)";

            var freshId =
                Db.Query().CommandText(cmdStr).SetParameter("@characterId", character.Id).SetParameter("@type", (int)corporationDocumentType).SetParameter("@validUntil", validUntil).SetParameter("@body", body)
                .ExecuteScalar <int>();


            if (freshId <= 0)
            {
                return(ErrorCodes.SQLInsertError);
            }


            corporationDocument = new CorporationDocument(freshId, character, corporationDocumentType, validUntil, body);

            return(ErrorCodes.NoError);
        }
Exemplo n.º 4
0
        public static ErrorCodes CheckOwnerAccess(int documentId, Character character, out CorporationDocument corporationDocument)
        {
            ErrorCodes ec;

            if ((ec = GetSingleDocumentFromSql(documentId, out corporationDocument)) != ErrorCodes.NoError)
            {
                return(ec);
            }

            //owner mindig tudja
            if (corporationDocument._ownerCharacter == character)
            {
                return(ErrorCodes.NoError);
            }

            return(ErrorCodes.AccessDenied);
        }
Exemplo n.º 5
0
        public static ErrorCodes CheckRegisteredAccess(int documentId, Character character, out CorporationDocument corporationDocument, bool forWrite = false)
        {
            ErrorCodes ec;

            if ((ec = GetSingleDocumentFromSql(documentId, out corporationDocument)) != ErrorCodes.NoError)
            {
                return(ec);
            }

            //owner mindig tudja
            if (corporationDocument._ownerCharacter == character)
            {
                return(ErrorCodes.NoError);
            }

            ReadWriteRole role;

            if ((ec = corporationDocument.IsRegistered(character.Id, out role)) != ErrorCodes.NoError)
            {
                return(ec);
            }

            if (forWrite)
            {
                if (role == ReadWriteRole.read)
                {
                    return(ErrorCodes.InsufficientPrivileges);
                }
            }

            return(ec);
        }