コード例 #1
0
        private int?AddCharterer(string name)
        {
            var newObj = new Charterer()
            {
                Name = name
            };
            string sql =
                $"INSERT INTO Charterer (Name, IdSource) VALUES (@name,@_sourceClipper); SELECT CAST(SCOPE_IDENTITY() as int)";

            using (var connection = ConnectionFactory.GetOpenConnection())
            {
                newObj.Id = connection.Query <int>(sql, new { newObj.Name, _sourceClipper }).Single();
                CharterersList.Add(newObj);
            }

            return(newObj.Id);
        }
コード例 #2
0
        public int?GetChartererIdFromName(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return(null);
            }
            var charterer = GetTargoValue("Charterer", name);

            var result = CharterersList.Any(x => x.Name.ToLower() == charterer.ToLower())
                ? CharterersList.FirstOrDefault(x => x.Name.ToLower() == charterer.ToLower())?.Id
                : AddCharterer(charterer);

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