/// <inheritdoc />
        public int CreateAblieferndeStelle(string bezeichnung, string kuerzel, List <int> tokenIdList, List <string> kontrollstelleList,
                                           string currentUserId)
        {
            if (kontrollstelleList == null)
            {
                kontrollstelleList = new List <string>();
            }

            const string query =
                "INSERT INTO AblieferndeStelle (Bezeichnung, Kuerzel, Kontrollstellen, CreatedBy, ModifiedBy) OUTPUT INSERTED.AblieferndeStelleId VALUES (@p1, @p2, @p3, (SELECT EmailAddress FROM ApplicationUser WHERE ID = @p4), (SELECT EmailAddress FROM ApplicationUser WHERE ID = @p4))";

            var parameterList = new List <SqlParameter>
            {
                new SqlParameter
                {
                    Value         = bezeichnung,
                    ParameterName = "p1",
                    SqlDbType     = SqlDbType.VarChar
                },
                new SqlParameter
                {
                    Value         = kuerzel,
                    ParameterName = "p2",
                    SqlDbType     = SqlDbType.VarChar
                },
                new SqlParameter
                {
                    Value         = string.Join(",", kontrollstelleList),
                    ParameterName = "p3",
                    SqlDbType     = SqlDbType.VarChar
                },
                new SqlParameter
                {
                    Value         = currentUserId,
                    ParameterName = "p4",
                    SqlDbType     = SqlDbType.NVarChar
                }
            };

            var result = DataAccessExtensions.CreateNewItem(connectionString, query, parameterList);

            var ablieferndeStelleId = Convert.ToInt32(result);

            if (tokenIdList == null)
            {
                return(ablieferndeStelleId);
            }

            // Alle Tokens zuordnen
            var queryInsertToken = GetQueryForCleanAndInsertTokens(ablieferndeStelleId, tokenIdList);

            DataAccessExtensions.ExecuteQuery(connectionString, queryInsertToken);

            return(ablieferndeStelleId);
        }
        /// <inheritdoc />
        public AmtTokenDto CreateToken(string token, string bezeichnung)
        {
            if (string.IsNullOrEmpty(token))
            {
                return(null);
            }

            if (string.IsNullOrEmpty(bezeichnung))
            {
                return(null);
            }

            if (!TokenIsUnique(token))
            {
                return(null);
            }

            var newToken = new AmtTokenDto
            {
                TokenId     = 0,
                Token       = token,
                Bezeichnung = bezeichnung
            };

            const string query =
                "INSERT INTO AblieferndeStelleToken (Token, Bezeichnung) OUTPUT INSERTED.TokenId VALUES (@p1, @p2)";

            var parameterList = new List <SqlParameter>
            {
                new SqlParameter
                {
                    Value         = token,
                    ParameterName = "p1",
                    SqlDbType     = SqlDbType.NVarChar
                },
                new SqlParameter
                {
                    Value         = bezeichnung,
                    ParameterName = "p2",
                    SqlDbType     = SqlDbType.VarChar
                }
            };

            var result = DataAccessExtensions.CreateNewItem(connectionString, query, parameterList);

            if (result == null)
            {
                return(null);
            }

            newToken.TokenId = Convert.ToInt32(result);
            return(newToken);
        }
Exemple #3
0
        bool IDownloadTokenDataAccess.CreateToken(string token, int recordId, DownloadTokenType tokenType, DateTime tokenExpiryTime, string ipAdress,
                                                  string userId)
        {
            if (string.IsNullOrEmpty(token))
            {
                return(false);
            }

            if (recordId <= 0)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(ipAdress))
            {
                return(false);
            }

            const string query =
                "INSERT INTO DownloadToken (Token, ExpiryTime, IpAdress, recordId, UserId, TokenType) VALUES (@token, @expiryTime, @ipAddress, @recordId, @userId, @tokenType)";

            var parameterList = new List <SqlParameter>
            {
                new SqlParameter
                {
                    Value         = token,
                    ParameterName = "token",
                    SqlDbType     = SqlDbType.NVarChar
                },
                new SqlParameter
                {
                    Value         = tokenExpiryTime,
                    ParameterName = "expiryTime",
                    SqlDbType     = SqlDbType.DateTime2
                },
                new SqlParameter
                {
                    Value         = ipAdress,
                    ParameterName = "ipAddress",
                    SqlDbType     = SqlDbType.NVarChar
                },
                new SqlParameter
                {
                    Value         = recordId,
                    ParameterName = "recordId",
                    SqlDbType     = SqlDbType.Int
                },
                new SqlParameter
                {
                    Value         = userId,
                    ParameterName = "userId",
                    SqlDbType     = SqlDbType.NVarChar
                },
                new SqlParameter
                {
                    Value         = tokenType.ToString(),
                    ParameterName = "tokenType",
                    SqlDbType     = SqlDbType.NVarChar
                }
            };

            return(DataAccessExtensions.CreateNewItem(connectionString, query, parameterList) != null);
        }