Exemplo n.º 1
0
        public BaseCommands CommandFactory(string commandType)
        {
            BaseCommands command = null;

            switch (commandType)
            {
            case "create_product":
                command = new CreateProduct();
                break;

            case "create_campaign":
                command = new CreateCampaign();
                break;

            case "create_order":
                command = new CreateOrder();
                break;

            case "get_product_info":
                command = new GetProductInfo();
                break;

            case "get_campaign_info":
                command = new GetCampaignInfo();
                break;

            default:
                break;
            }
            return(command);
        }
Exemplo n.º 2
0
        internal Campaign InternalCreate(int accountId, CreateCampaign campaign)
        {
            IRestRequest  request  = TDClient.BuildRequest(Method.POST, LIST, new { accountId }, campaign);
            IRestResponse response = TDClient.InnerExecute(request);

            return(TDClient.ProcessOperationResponse <Campaign>(request, response, "add"));
        }
Exemplo n.º 3
0
 public ViewResult CreateCampaign(CreateCampaign campaign)
 {
     if (ValidateCampaign(campaign))
     {
         SaveCampaign(campaign);
         ViewBag.confirmation = "Campaña guardada";
     }
     else
     {
         ViewBag.confirmation = "No se pudo crear la campaña";
     }
     return(View("Confirm"));
 }
Exemplo n.º 4
0
        private void SaveCampaign(CreateCampaign campaign)
        {
            UserInformation user        = AuthenticatedUser();
            Campaign        newCampaign = new Campaign()
            {
                CampaignName = campaign.CampaignName,
                LocationID   = campaign.IdLoc,
                UserId       = user.UserId,
                Content      = campaign.Content
            };

            applicationDbContext.Add(newCampaign);
            applicationDbContext.SaveChanges();
        }
Exemplo n.º 5
0
        public ActionResult Create(CreateCampaign model)
        {
            _db.Campaigns.Add(new Campaign
            {
                CampaignName           = model.CampaignName,
                CampaignDescription    = model.CampaignDescription,
                CampaignInitiatior     = model.CampaignInitiator,
                RelatedCompanyId       = model.RelatedCompanyId,
                CampaignType           = model.CampaignType,
                CampaignStatus         = Campaign.CampaignStatusEnum.Start,
                CampaignStartDate      = model.CampaignStartDate,
                CampaignPlannedEndDate = model.CampaignPlannedEndDate,
                InsertDate             = DateTime.Now
            });
            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 6
0
        private static bool ResolveIncludeRightSizer(CreateCampaign source)
        {
            if (!source.IncludeRightSizer.TryGetValueFromDescription(out IncludeRightSizer value))
            {
                return(false);
            }

            switch (value)
            {
            case IncludeRightSizer.No:
                return(false);

            case IncludeRightSizer.CampaignLevel:
            case IncludeRightSizer.DetailLevel:
                return(true);

            default:     //should we throw an exception here in case, when somehow validation was avoided and inappropriate value passed?
                return(false);
            }
        }
Exemplo n.º 7
0
        private static RightSizerLevel?ResolveRightSizerLevel(CreateCampaign source)
        {
            if (!source.IncludeRightSizer.TryGetValueFromDescription(out IncludeRightSizer value))
            {
                return(null);
            }

            switch (value)
            {
            case IncludeRightSizer.No:
                return(null);

            case IncludeRightSizer.CampaignLevel:
                return(RightSizerLevel.CampaignLevel);

            case IncludeRightSizer.DetailLevel:
                return(RightSizerLevel.DetailLevel);

            default:
                return(null);
            }
        }
Exemplo n.º 8
0
        public IHttpActionResult Put([FromUri] string externalId, [FromBody] CreateCampaign command)
        {
            if (command is null || String.IsNullOrWhiteSpace(externalId) || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (externalId != command.ExternalId)
            {
                ModelState.AddModelError(nameof(CreateCampaign.ExternalId), "ExternalId does not match");
            }

            try
            {
                command.Validate();
            }
            catch (BreakTypeException ex)
            {
                ModelState.AddModelError(
                    nameof(CreateCampaign.BreakType), BreakTypeValueErrorMessage(ex)
                    );
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var campaign = _campaignRepository.FindByRef(externalId).FirstOrDefault();

            if (_featureManager.IsEnabled(nameof(ProductFeature.IncludeChannelGroupFileForOptimiser)))
            {
                try
                {
                    ValidateCampaigns(new List <CreateCampaign> {
                        command
                    }, campaign == null);
                }
                catch (ArgumentException exception)
                    when(exception.ParamName == ReflectionUtilities.PropertyName <CreateCampaign>(c => c.IncludeRightSizer)) // Case for 400 Bad Request Code for IncludeRightSizer value validation
                    {
                        return(this.Error().BadRequest(ApiError.BadRequest(exception.Message)));
                    }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }
            }

            if (campaign is null)
            {
                AddCampaign(new List <CreateCampaign>()
                {
                    command
                });
            }
            else
            {
                var newCampaign = _mapper.Map <Campaign>(command);

                campaign.Update(newCampaign);
                ApplyDeliveryCurrency(newCampaign);
                ApplyBookingPositionAndSequencing(newCampaign);
                _campaignRepository.Update(campaign);
            }

            _campaignRepository.SaveChanges();

            _campaignPassPrioritiesService.AddNewCampaignPassPrioritiesToAllScenariosInLibrary();

            return(Ok(_mapper.Map <CampaignModel>(campaign)));
        }
Exemplo n.º 9
0
        private CreateCampaign CreateValidCampaignObject()
        {
            var campaign = new CreateCampaign()
            {
                ExternalId    = "External Id",
                Name          = "Campaign Name",
                DemoGraphic   = "demographic",
                StartDateTime = DateTime.Today,
                EndDateTime   = DateTime.Today.AddDays(1),
                Product       = "product",
                TargetRatings = 1,
                DeliveryType  = CampaignDeliveryType.Rating.ToString(),
                BreakType     = new List <string>()
                {
                    "VA-ValidBreakType"
                },
                SalesAreaCampaignTarget = new List <SalesAreaCampaignTargetViewModel>()
                {
                    new SalesAreaCampaignTargetViewModel()
                    {
                        SalesAreaGroup = new SalesAreaGroup()
                        {
                            GroupName  = "GroupName",
                            SalesAreas = new List <string>()
                            {
                                "SalesAreas"
                            }
                        },
                        Multiparts = new List <MultipartModel>()
                        {
                            new MultipartModel()
                            {
                                Lengths = new List <Duration>
                                {
                                    Duration.FromMinutes(1)
                                },
                                DesiredPercentageSplit = 1
                            }
                        },
                        CampaignTargets = new List <CampaignTarget>()
                        {
                            new CampaignTarget()
                            {
                                StrikeWeights = new List <StrikeWeight>()
                                {
                                    new StrikeWeight()
                                    {
                                        StartDate = DateTime.Now,
                                        EndDate   = DateTime.Now.AddDays(1),
                                        DesiredPercentageSplit = 1,
                                        Lengths = new List <Length>()
                                        {
                                            new Length()
                                            {
                                                length = Duration.FromMinutes(1),
                                                DesiredPercentageSplit = 1
                                            }
                                        },
                                        DayParts = new List <DayPart>()
                                        {
                                            new DayPart()
                                            {
                                                DesiredPercentageSplit = 1,
                                                Timeslices             = new List <Timeslice>()
                                                {
                                                    new Timeslice()
                                                    {
                                                        FromTime   = "01:00",
                                                        ToTime     = "02:00",
                                                        DowPattern = new List <string>()
                                                        {
                                                            "Mon"
                                                        }
                                                    }
                                                },
                                                Lengths = new List <DayPartLength>
                                                {
                                                    new DayPartLength
                                                    {
                                                        DesiredPercentageSplit = 1
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                TimeRestrictions = new List <TimeRestriction>()
                {
                    new TimeRestriction()
                    {
                        StartDateTime = DateTime.Now,
                        EndDateTime   = DateTime.Now.AddDays(1),
                        DowPattern    = new List <string>()
                        {
                            "MON"
                        },
                        IsIncludeOrExclude = "I"
                    }
                },
                ProgrammeRestrictions = new List <ProgrammeRestriction>()
                {
                    new ProgrammeRestriction()
                    {
                        IsCategoryOrProgramme = "C",
                        IsIncludeOrExclude    = "I"
                    }
                },
                CampaignGroup        = "CampaignGroup",
                IncludeRightSizer    = "Campaign Level",
                IncludeOptimisation  = true,
                CampaignPassPriority = 2
            };

            return(campaign);
        }
Exemplo n.º 10
0
 private static DayPartLength GetFirstDayPartLength(CreateCampaign payload)
 {
     return(payload.SalesAreaCampaignTarget?.FirstOrDefault()?.CampaignTargets?.FirstOrDefault()
            ?.StrikeWeights?.FirstOrDefault()?.DayParts?.FirstOrDefault()?.Lengths.FirstOrDefault());
 }
Exemplo n.º 11
0
        private static CreateCampaign ChangeCurrentPercentageSplitInFirstDayPartLength(CreateCampaign payload,
                                                                                       decimal currentPercentageSplitValue)
        {
            var dayPartLength = GetFirstDayPartLength(payload);

            if (dayPartLength is null)
            {
                throw new ArgumentException($"Provided campaign {nameof(payload)} does not have day part length");
            }

            dayPartLength.CurrentPercentageSplit = currentPercentageSplitValue;

            return(payload);
        }
Exemplo n.º 12
0
 private bool ValidateCampaign(CreateCampaign campaign)
 {
     return(ModelState.IsValid && campaign.IdLoc != 0);
 }
Exemplo n.º 13
0
 internal Campaign InternalCreate(int accountId, CreateCampaign campaign)
 {
     return(Api.Post <Campaign>($"/account/{accountId}/campaign", campaign));
 }