Exemple #1
0
        public async Task <long> CreateTradeFavouriteAsync(TradeFavoriteDetail tradeFavorite, string companyId)
        {
            var queryParameters = new DynamicParameters();

            queryParameters.Add("@FavoriteTrade", FavouriteTradeUDTT(tradeFavorite));
            queryParameters.Add("@FavoriteTradeCost", FavouriteTradeCostUDTT(tradeFavorite));
            queryParameters.Add("@CompanyId", companyId);

            var tradeFavoriteId = await ExecuteQueryFirstOrDefaultAsync <long>(StoredProcedureNames.CreateFavouriteTrade, queryParameters, true);

            return(tradeFavoriteId);
        }
Exemple #2
0
        public static DataTable FavouriteTradeUDTT(TradeFavoriteDetail tradeFavorite)
        {
            DataTable table = new DataTable();

            table.SetTypeName("[Trading].[UDTT_FavoriteTrade]");
            DataColumn name = new DataColumn("[Name]", typeof(string));

            table.Columns.Add(name);
            DataColumn description = new DataColumn("[Description]", typeof(string));

            table.Columns.Add(description);
            DataColumn contractTypeId = new DataColumn("[ContractTypeId]", typeof(long));

            table.Columns.Add(contractTypeId);
            DataColumn departmentId = new DataColumn("[DepartmentId]", typeof(long));

            table.Columns.Add(departmentId);
            DataColumn traderId = new DataColumn("[TraderId]", typeof(long));

            table.Columns.Add(traderId);
            DataColumn buyerId = new DataColumn("[BuyerId]", typeof(long));

            table.Columns.Add(buyerId);
            DataColumn sellerId = new DataColumn("[SellerId]", typeof(long));

            table.Columns.Add(sellerId);
            DataColumn counterparty = new DataColumn("[Counterparty]", typeof(string));

            table.Columns.Add(counterparty);
            DataColumn commodityId = new DataColumn("[CommodityId]", typeof(long));

            table.Columns.Add(commodityId);
            DataColumn cropYear = new DataColumn("[CropYear]", typeof(int));

            table.Columns.Add(cropYear);
            DataColumn weightUnitId = new DataColumn("[WeightUnitId]", typeof(long));

            table.Columns.Add(weightUnitId);
            DataColumn quantity = new DataColumn("[Quantity]", typeof(decimal));

            table.Columns.Add(quantity);
            DataColumn pricingMethodId = new DataColumn("[PricingMethodId]", typeof(int));

            table.Columns.Add(pricingMethodId);
            DataColumn priceCurrency = new DataColumn("[PriceCurrency]", typeof(string));

            table.Columns.Add(priceCurrency);
            DataColumn priceUnitId = new DataColumn("[PriceUnitId]", typeof(long));

            table.Columns.Add(priceUnitId);
            DataColumn price = new DataColumn("[Price]", typeof(decimal));

            table.Columns.Add(price);
            DataColumn paymentTermId = new DataColumn("[PaymentTermId]", typeof(long));

            table.Columns.Add(paymentTermId);
            DataColumn premiumDiscountValue = new DataColumn("[PremiumDiscountValue]", typeof(decimal));

            table.Columns.Add(premiumDiscountValue);
            DataColumn contractTermId = new DataColumn("[ContractTermId]", typeof(long));

            table.Columns.Add(contractTermId);
            DataColumn contractTermLocationId = new DataColumn("[ContractTermLocationId]", typeof(long));

            table.Columns.Add(contractTermLocationId);
            DataColumn arbitrationId = new DataColumn("[ArbitrationId]", typeof(int));

            table.Columns.Add(arbitrationId);
            DataColumn periodTypeId = new DataColumn("[PeriodTypeId]", typeof(int));

            table.Columns.Add(periodTypeId);
            DataColumn deliveryPeriodStart = new DataColumn("[DeliveryPeriodStart]", typeof(DateTime));

            table.Columns.Add(deliveryPeriodStart);
            DataColumn deliveryPeriodEnd = new DataColumn("[DeliveryPeriodEnd]", typeof(DateTime));

            table.Columns.Add(deliveryPeriodEnd);
            DataColumn positionMonthType = new DataColumn("[PositionMonthType]", typeof(int));

            table.Columns.Add(positionMonthType);
            DataColumn portOriginId = new DataColumn("[PortOriginId]", typeof(long));

            table.Columns.Add(portOriginId);
            DataColumn portDestinationId = new DataColumn("[PortDestinationId]", typeof(long));

            table.Columns.Add(portDestinationId);
            DataColumn marketSectorId = new DataColumn("[MarketSectorId]", typeof(long));

            table.Columns.Add(marketSectorId);
            DataColumn memorandum = new DataColumn("[Memorandum]", typeof(string));

            table.Columns.Add(memorandum);
            DataColumn contractedValue = new DataColumn("[ContractedValue]", typeof(decimal));

            table.Columns.Add(contractedValue);
            var row = table.NewRow();

            row[name]                   = tradeFavorite.Name;
            row[description]            = tradeFavorite.Description;
            row[contractTypeId]         = (int)tradeFavorite.ContractType;
            row[departmentId]           = (tradeFavorite.DepartmentId != null) ? tradeFavorite.DepartmentId : (object)DBNull.Value;
            row[traderId]               = (tradeFavorite.TraderId != null) ? tradeFavorite.TraderId : (object)DBNull.Value;
            row[buyerId]                = tradeFavorite.BuyerId;
            row[sellerId]               = tradeFavorite.SellerId;
            row[counterparty]           = tradeFavorite.CounterpartyReference;
            row[commodityId]            = tradeFavorite.CommodityId;
            row[cropYear]               = tradeFavorite.CropYear;
            row[weightUnitId]           = tradeFavorite.WeightUnitId;
            row[quantity]               = tradeFavorite.Quantity;
            row[pricingMethodId]        = (int)tradeFavorite.PricingMethod;
            row[priceCurrency]          = tradeFavorite.Currency;
            row[priceUnitId]            = tradeFavorite.PriceUnitId;
            row[price]                  = tradeFavorite.Price;
            row[paymentTermId]          = tradeFavorite.PaymentTermsId;
            row[premiumDiscountValue]   = tradeFavorite.PremiumDiscountValue;
            row[contractTermId]         = tradeFavorite.ContractTermId;
            row[contractTermLocationId] = tradeFavorite.ContractTermLocationId ?? (object)DBNull.Value;
            row[arbitrationId]          = tradeFavorite.ArbitrationId;
            row[periodTypeId]           = tradeFavorite.PeriodTypeId;
            row[deliveryPeriodStart]    = tradeFavorite.DeliveryPeriodStartDate ?? (object)DBNull.Value;
            row[deliveryPeriodEnd]      = tradeFavorite.DeliveryPeriodEndDate ?? (object)DBNull.Value;
            row[positionMonthType]      = tradeFavorite.PositionMonthType;
            row[portOriginId]           = tradeFavorite.OriginPortId ?? (object)DBNull.Value;
            row[portDestinationId]      = tradeFavorite.DestinationPortId ?? (object)DBNull.Value;
            row[marketSectorId]         = tradeFavorite.MarketSectorId ?? (object)DBNull.Value;
            row[memorandum]             = tradeFavorite.Memorandum;
            row[contractedValue]        = tradeFavorite.ContractedValue;
            table.Rows.Add(row);
            return(table);
        }
Exemple #3
0
        public static DataTable FavouriteTradeCostUDTT(TradeFavoriteDetail tradeFavorite)
        {
            DataTable tablecost = new DataTable();

            tablecost.SetTypeName("[Trading].[UDTT_FavoriteTradeCost]");
            DataColumn costTypeId = new DataColumn("[CostTypeId]", typeof(long));

            tablecost.Columns.Add(costTypeId);
            DataColumn supplierId = new DataColumn("[SupplierId]", typeof(string));

            tablecost.Columns.Add(supplierId);
            DataColumn costDirectionId = new DataColumn("[CostDirectionId]", typeof(long));

            tablecost.Columns.Add(costDirectionId);
            DataColumn currencyCode = new DataColumn("[CurrencyCode]", typeof(string));

            tablecost.Columns.Add(currencyCode);
            DataColumn rateTypeId = new DataColumn("[RateTypeId]", typeof(long));

            tablecost.Columns.Add(rateTypeId);
            DataColumn priceUnitId = new DataColumn("[PriceUnitId]", typeof(string));

            tablecost.Columns.Add(priceUnitId);
            DataColumn rate = new DataColumn("[Rate]", typeof(long));

            tablecost.Columns.Add(rate);
            DataColumn inPL = new DataColumn("[InPL]", typeof(string));

            tablecost.Columns.Add(inPL);
            DataColumn noAction = new DataColumn("[NoAction]", typeof(long));

            tablecost.Columns.Add(noAction);
            DataColumn narrative = new DataColumn("[Narrative]", typeof(string));

            tablecost.Columns.Add(narrative);
            DataColumn costMatrixName = new DataColumn("[CostMatrixName]", typeof(string));

            tablecost.Columns.Add(costMatrixName);
            DataColumn origEstPMT = new DataColumn("[OrigEstPMT]", typeof(string));

            tablecost.Columns.Add(origEstPMT);
            DataColumn origEstRateTypeId = new DataColumn("[OrigEstRateTypeId]", typeof(string));

            tablecost.Columns.Add(origEstRateTypeId);
            DataColumn origEstPriceUnitId = new DataColumn("[OrigEstPriceUnitId]", typeof(long));

            tablecost.Columns.Add(origEstPriceUnitId);
            DataColumn origEstCurrencyCode = new DataColumn("[OrigEstCurrencyCode]", typeof(string));

            tablecost.Columns.Add(origEstCurrencyCode);
            DataColumn origEstRate = new DataColumn("[OrigEstRate]", typeof(long));

            tablecost.Columns.Add(origEstRate);
            if (tradeFavorite.Costs != null && tradeFavorite.Costs.ToList().Count > 0)
            {
                tradeFavorite.Costs.ToList().ForEach(cost =>
                {
                    var row                  = tablecost.NewRow();
                    row[costTypeId]          = cost.CostTypeId ?? (object)DBNull.Value;
                    row[supplierId]          = cost.SupplierId ?? (object)DBNull.Value;
                    row[costDirectionId]     = cost.CostDirectionId;
                    row[currencyCode]        = cost.CurrencyCode;
                    row[rateTypeId]          = cost.RateTypeId;
                    row[priceUnitId]         = cost.PriceUnitId;
                    row[rate]                = cost.Rate;
                    row[inPL]                = cost.InPL;
                    row[noAction]            = cost.NoAction;
                    row[narrative]           = cost.Narrative;
                    row[costMatrixName]      = cost.CostMatrixName ?? (object)DBNull.Value;
                    row[origEstPMT]          = cost.OriginalEstimatedPMTValue;
                    row[origEstRateTypeId]   = cost.OriginalEstRateTypeId;
                    row[origEstPriceUnitId]  = cost.OriginalEstPriceUnitId ?? (object)DBNull.Value;
                    row[origEstCurrencyCode] = cost.OriginalEstCurrencyCode;
                    row[origEstRate]         = cost.OriginalEstRate ?? (object)DBNull.Value;
                    tablecost.Rows.Add(row);
                });
            }

            return(tablecost);
        }
        public async Task <IActionResult> CreateTradeFavorite(string company, [FromBody] CreateFavouriteCommand tradeFavoriteCommand)
        {
            List <TradeImageColumnDto> tradeImageSetupDetails   = (await _sectionQueries.GetTradeImageFieldDetailsAsync(company)).Where(i => i.CopyAsFavorite).ToList();
            TradeFavoriteDetail        tradeFavoriteTobeCreated = new TradeFavoriteDetail
            {
                Name        = tradeFavoriteCommand.Name,
                Description = tradeFavoriteCommand.Description
            };
            var sectionObject = await _sectionQueries.GetSectionByIdAsync(tradeFavoriteCommand.SectionId, company, null);

            foreach (TradeImageColumnDto element in tradeImageSetupDetails)
            {
                switch (element.TradeFieldName)
                {
                case "Type":
                    tradeFavoriteTobeCreated.ContractType = sectionObject.ContractType;

                    if (tradeFavoriteTobeCreated.ContractType == ContractType.Purchase)
                    {
                        tradeFavoriteTobeCreated.CounterpartyReference = sectionObject.SellerCode;
                    }
                    else if (tradeFavoriteTobeCreated.ContractType == ContractType.Sale)
                    {
                        tradeFavoriteTobeCreated.CounterpartyReference = sectionObject.BuyerCode;
                    }

                    tradeFavoriteTobeCreated.SellerCode = sectionObject.SellerCode;
                    tradeFavoriteTobeCreated.BuyerCode  = sectionObject.BuyerCode;

                    break;

                case "DepartmentId":
                    tradeFavoriteTobeCreated.DepartmentId = sectionObject.DepartmentId;
                    break;

                case "CommodityId":
                    tradeFavoriteTobeCreated.CommodityId = sectionObject.CommodityId;
                    break;

                case "CropYear":
                    tradeFavoriteTobeCreated.CropYear = sectionObject.CropYear;
                    break;

                case "WeightUnitId":
                    tradeFavoriteTobeCreated.WeightUnitId = sectionObject.WeightUnitId;
                    break;

                case "Quantity":
                    tradeFavoriteTobeCreated.Quantity = sectionObject.Quantity;
                    break;

                case "PricingMethodId":
                    tradeFavoriteTobeCreated.PricingMethod = sectionObject.PricingMethod;
                    break;

                case "CurrencyCode":
                    tradeFavoriteTobeCreated.Currency = sectionObject.Currency;
                    break;

                case "PriceUnitId":
                    tradeFavoriteTobeCreated.PriceUnitId = sectionObject.PriceUnitId;
                    break;

                case "Price":
                    tradeFavoriteTobeCreated.Price = sectionObject.Price;
                    break;

                case "PaymentTermId":
                    tradeFavoriteTobeCreated.PaymentTermCode = sectionObject.PaymentTermCode;
                    break;

                case "ContractTermId":
                    tradeFavoriteTobeCreated.ContractTermCode = sectionObject.ContractTermCode;
                    break;

                case "TraderId":
                    tradeFavoriteTobeCreated.TraderId = sectionObject.Header.TraderId;
                    break;

                case "ContractTermLocationId":
                    tradeFavoriteTobeCreated.ContractTermLocationCode = sectionObject.ContractTermLocationCode;
                    break;

                case "ArbitrationId":
                    tradeFavoriteTobeCreated.ArbitrationCode = sectionObject.ArbitrationCode;
                    break;

                case "PeriodTypeId":
                    tradeFavoriteTobeCreated.PeriodTypeId = sectionObject.PeriodTypeId;
                    break;

                case "DeliveryPeriodStart":
                    tradeFavoriteTobeCreated.ShippingPeriod          = sectionObject.ShippingPeriod;
                    tradeFavoriteTobeCreated.DeliveryPeriodEndDate   = sectionObject.DeliveryPeriodEndDate;
                    tradeFavoriteTobeCreated.DeliveryPeriodStartDate = sectionObject.DeliveryPeriodStartDate;
                    break;

                case "PositionMonthType":
                    tradeFavoriteTobeCreated.PositionMonthType = sectionObject.PositionMonthType;
                    break;

                case "PortOriginId":
                    tradeFavoriteTobeCreated.PortOriginCode = sectionObject.PortOriginCode;
                    break;

                case "PortDestinationId":
                    tradeFavoriteTobeCreated.PortDestinationCode = sectionObject.PortDestinationCode;
                    break;

                case "MarketSectorId":
                    tradeFavoriteTobeCreated.MarketSectorId = (sectionObject.MarketSectorId != 0) ? (int?)sectionObject.MarketSectorId : null;
                    break;

                default:
                    break;
                }
            }

            tradeFavoriteTobeCreated.ContractedValue      = sectionObject.ContractedValue;
            tradeFavoriteTobeCreated.Costs                = sectionObject.Costs;
            tradeFavoriteCommand.CompanyId                = company;
            tradeFavoriteCommand.TradeFavoriteToBeCreated = tradeFavoriteTobeCreated;
            var tradeFavoriteId = await _mediator.Send(tradeFavoriteCommand);

            return(Ok(tradeFavoriteId));
        }