Exemplo n.º 1
0
        private async Task Process(string fid, string com)
        {
            // NOTE: Throw is null, only for now (should log error later is dest and flight are both null)
            if (string.IsNullOrWhiteSpace(fid))
            {
                throw new NotImplementedException();
            }

            int flightId;

            int.TryParse(fid, out flightId);

            if (flightId < 1)
            {
                throw new NotImplementedException();
            }

            decimal commission;

            decimal.TryParse(com, out commission);

            // Model
            var conversion = new DatabaseConversion
            {
                AddedDate = DateTimeOffset.Now,
                // TODO: Shit
                Flight      = flightId < 1 ? (int?)null : flightId,
                Destination = null,
                // TODO: Shit
                Value = commission == decimal.Zero ? (decimal?)null : commission
            };

            using (var sql = new SqlConnection(_conn))
            {
                await sql.OpenAsync();                            //.ConfigureAwait(false);

                var response = await sql.InsertAsync(conversion); //.ConfigureAwait(false);

                if (response < 1)
                {
                    // TODO: Log error
                }

                sql.Close();
            }

            // SignalR
            // TODO: [Optimization] If there are no clients connected to SignalR, don't push event message.
            // TODO: Refactor to own method (singleton or simpleinjector).
            _conversionHubContext.Clients
            .All
            .newConversion(new EmberConversion
            {
                Id          = conversion.Id,
                AddedDate   = conversion.AddedDate,
                Flight      = conversion.Flight,
                Destination = conversion.Destination,
                Value       = conversion.Value
            });
        }
Exemplo n.º 2
0
        private async Task Process(string fid, string com)
        {
            // NOTE: Throw is null, only for now (should log error later is dest and flight are both null)
            if (string.IsNullOrWhiteSpace(fid))
            {
                throw new NotImplementedException();
            }

            int flightId;
            int.TryParse(fid, out flightId);

            if (flightId < 1)
            {
                throw new NotImplementedException();
            }

            decimal commission;
            decimal.TryParse(com, out commission);

            // Model
            var conversion = new DatabaseConversion
            {
                AddedDate = DateTimeOffset.Now,
                // TODO: Shit
                Flight = flightId < 1 ? (int?)null : flightId,
                Destination = null,
                // TODO: Shit
                Value = commission == decimal.Zero ? (decimal?)null : commission
            };

            using (var sql = new SqlConnection(_conn))
            {
                await sql.OpenAsync();//.ConfigureAwait(false);

                var response = await sql.InsertAsync(conversion);//.ConfigureAwait(false);
                if (response < 1)
                {
                    // TODO: Log error
                }

                sql.Close();
            }

            // SignalR
            // TODO: [Optimization] If there are no clients connected to SignalR, don't push event message.
            // TODO: Refactor to own method (singleton or simpleinjector).
            _conversionHubContext.Clients
                                 .All
                                 .newConversion(new EmberConversion
                                 {
                                     Id = conversion.Id,
                                     AddedDate = conversion.AddedDate,
                                     Flight = conversion.Flight,
                                     Destination = conversion.Destination,
                                     Value = conversion.Value
                                 });
        }