Exemplo n.º 1
0
        private static void SendToVendorMulti(OrderVia orderVia, WfpictContext db, Campaign campaign, Vendor vendor, string[] segmentsSelected, string whiteLabelDomain)
        {
            var segments = db.CampaignSegments
                           .Where(c => c.CampaignId == campaign.Id && segmentsSelected.Contains(c.SegmentNumber))
                           .ToList();

            foreach (var segment in segments)
            {
                string sentOrder, queuedCampaignId = null;
                switch (orderVia)
                {
                case OrderVia.Email:
                    sentOrder = EmailHelper.SendApprovedToVendor(vendor, campaign, segment);
                    break;

                case OrderVia.Api:
                    var response = ProDataApiManager.Create(campaign, segment, whiteLabelDomain);
                    if (response.status != ProDataApiManager.Success)
                    {
                        throw new AdsException(response.ErrorMessage);
                    }
                    sentOrder        = response.RequestMessage;
                    queuedCampaignId = response.queued_pending_campaign_id.ToString();
                    break;

                default:
                    throw new AdsException("Invalid orderVia while sending to vendor multiple");
                }

                segment.SegmentStatus = (int)SegmentStatus.Monitoring;

                var campaignTracking =
                    db.CampaignTrackings.FirstOrDefault(x => x.CampaignId == campaign.Id && x.SegmentNumber == segment.SegmentNumber);

                if (campaignTracking == null)
                {
                    var trackingId = Guid.NewGuid();
                    var tracking   = new CampaignTracking()
                    {
                        Id                  = trackingId,
                        CreatedAt           = DateTime.Now,
                        CampaignId          = campaign.Id,
                        OrderNumber         = campaign.OrderNumber,
                        SegmentNumber       = segment.SegmentNumber,
                        Quantity            = segment.Quantity,
                        DateSent            = DateTime.Now,
                        SentOrder           = sentOrder,
                        IsCreatedThroughApi = orderVia == OrderVia.Api,
                        QueuedCampaignId    = queuedCampaignId
                    };
                    db.CampaignTrackings.Add(tracking);
                    db.SaveChanges();
                }
                else
                {
                    campaignTracking.Quantity            = segment.Quantity;
                    campaignTracking.DateSent            = DateTime.Now;
                    campaignTracking.SentOrder           = sentOrder;
                    campaignTracking.IsCreatedThroughApi = orderVia == OrderVia.Api;
                    campaignTracking.QueuedCampaignId    = queuedCampaignId;
                }

                LogHelper.AddLog(db, LogType.Vendor, campaign.OrderNumber, $"Multi {segment.SegmentNumber} has been sent to vendor successfully.");
            }
        }
Exemplo n.º 2
0
        private static void SendToVendorSingle(OrderVia orderVia, WfpictContext db, Campaign campaign, Vendor vendor, string whiteLabelDomain)
        {
            string sentOrder, queuedCampaignId = null;

            switch (orderVia)
            {
            case OrderVia.Email:
                sentOrder = EmailHelper.SendApprovedToVendor(vendor, campaign, null);
                break;

            case OrderVia.Api:
                var response = ProDataApiManager.Create(campaign, null, whiteLabelDomain);
                if (response.status != ProDataApiManager.Success)
                {
                    throw new AdsException(response.ErrorMessage);
                }
                sentOrder        = response.RequestMessage;
                queuedCampaignId = response.queued_pending_campaign_id.ToString();
                break;

            default:
                throw new AdsException("Invalid orderVia while sending to vendor single");
            }

            string orderNumberRdp = campaign.ReBroadcasted ? campaign.ReBroadcastedOrderNumber : campaign.OrderNumber;
            long   quantity       = campaign.ReBroadcasted ? campaign.ReBroadcastedQuantity : campaign.Approved.Quantity;

            var campaignTracking =
                db.CampaignTrackings.FirstOrDefault(x => x.CampaignId == campaign.Id && x.OrderNumber == orderNumberRdp && string.IsNullOrEmpty(x.SegmentNumber));

            if (campaignTracking == null)
            {
                var trackingId = Guid.NewGuid();
                var tracking   = new CampaignTracking()
                {
                    Id                  = trackingId,
                    CreatedAt           = DateTime.Now,
                    CampaignId          = campaign.Id,
                    OrderNumber         = orderNumberRdp,
                    SegmentNumber       = string.Empty,
                    Quantity            = quantity,
                    DateSent            = DateTime.Now,
                    SentOrder           = sentOrder,
                    IsCreatedThroughApi = orderVia == OrderVia.Api,
                    QueuedCampaignId    = queuedCampaignId
                };
                db.CampaignTrackings.Add(tracking);
            }
            else
            {
                campaignTracking.Quantity            = quantity;
                campaignTracking.DateSent            = DateTime.Now;
                campaignTracking.SentOrder           = sentOrder;
                campaignTracking.IsCreatedThroughApi = orderVia == OrderVia.Api;
                campaignTracking.QueuedCampaignId    = queuedCampaignId;
            }
            db.SaveChanges();

            LogHelper.AddLog(db, LogType.Vendor, campaign.OrderNumber, !campaign.ReBroadcasted
                    ? "Order has been sent to vendor successfully."
                    : "Order Rebroad has been sent to vendor sucessfully.");
        }