public Campaign GetEntity(int agencyid, CampaignTypeCharge campaignTypeCharge, Core.Models.SettingModel setting, string code, string username)
        {
            //var accountChargeAmount = 0;
            //if (Type == CampaignType.CustomService || Type == CampaignType.JoinEvent)
            //{
            //    accountChargeAmount = AccountChargeAmount ?? 0;
            //}
            //else
            //{
            //    accountChargeAmount = campaignTypeCharge.AccountChargeAmount;
            //}


            //var accountChargeExtraPercent = 0;

            //if (Type == CampaignType.ShareContent || Type == CampaignType.ShareContentWithCaption)
            //{
            //    if (EnabledExtraType)
            //    {
            //        accountChargeExtraPercent = campaignTypeCharge.AccountChargeExtraPercent;
            //    }
            //}

            var start = "";
            var end   = "";

            if (!string.IsNullOrEmpty(ExecutionTime))
            {
                var arrDate = ExecutionTime.Split('-');
                if (arrDate.Length == 2)
                {
                    start = arrDate[0].Trim();
                    end   = arrDate[1].Trim();
                }
            }
            var image = string.Empty;

            if (Type == CampaignType.ChangeAvatar)
            {
                image = Image;
            }
            else if (Type == CampaignType.ShareContentWithCaption)
            {
                image = AddonImages.ToListString();
            }
            return(new Campaign()
            {
                DateCreated = DateTime.Now,
                AgencyId = agencyid,
                Data = Data,
                DateModified = DateTime.Now,
                Deleted = false,
                Description = Description,
                Image = image,
                Published = true,
                //Status = CampaignStatus.Created, // cap nhat status da duyet luon de facebook check,
                Status = CampaignStatus.Confirmed,
                Title = Title,
                UserCreated = username,
                UserModified = username,
                ExtraOptionChargePercent = setting.CampaignExtraOptionChargePercent,
                ServiceChargePercent = setting.CampaignServiceChargePercent,
                ServiceVATPercent = setting.CampaignVATChargePercent,
                ServiceChargeAmount = 0,
                AccountChargeExtraPercent = 0,
                AccountChargeAmount = 0,
                EnabledAccountChargeExtra = false,
                AccountChargeTime = 0,
                Requirement = Type == CampaignType.CustomService ? Requirement : string.Empty,
                Type = Type,

                Code = code,
                Quantity = Quantity,
                DateStart = start.ToViDateTime(),
                DateEnd = end.ToViDateTime(),
                AccountFeedbackBefore = FeedbackBefore.ToViDateTime(),
                CustomKolNames = CustomKolNames.ToListString(),
                Method = Method,
                SampleContent = SampleContent.ToListString(),
                Hashtag = HashTag.ToListString(),
                SampleContentText = SampleContentText
            });
        }
Пример #2
0
        public static Campaign GetEntity(int agencyid, CreateCampaignInfoViewModel info, CreateCampaignTargetViewModel target,
                                         CampaignTypeCharge campaignTypeCharge, Core.Models.SettingModel setting, string code, string username)
        {
            var executionTime = DateRangeHelper.GetDateRange(target.ExecutionTime);
            var regTime       = DateRangeHelper.GetDateRange(target.RegisterTime);
            var feedbackTime  = DateRangeHelper.GetDateRange(target.FeedbackBefore);

            var reviewTime = DateRangeHelper.GetDateRange(info.ReviewDate);


            var image = string.Empty;

            if (!string.IsNullOrEmpty(info.Image))
            {
                image = info.Image;
            }
            else
            {
                image = info.AddonImages.ToListString();
            }



            //if (info.Type == CampaignType.ChangeAvatar)
            //{

            //}
            //else if (info.Type == CampaignType.ShareContentWithCaption)
            //{
            //    image = info.AddonImages.ToListString();
            //}

            var reviewaddress = "";
            var reviewpayback = false;

            if (info.Type == CampaignType.ReviewProduct && info.ReviewType.HasValue)
            {
                if (info.ReviewType == CampaignReviewType.GuiSanPham)
                {
                    if (1 == info.ReviewPayback)
                    {
                        reviewaddress = info.ReviewAddress;
                        reviewpayback = true;
                    }
                }
                else
                {
                    reviewaddress = info.ReviewAddress2;
                }
            }

            var campaign = new Campaign()
            {
                DateCreated  = DateTime.Now,
                AgencyId     = agencyid,
                Data         = info.Data,
                DateModified = DateTime.Now,
                Deleted      = false,
                Description  = info.Description,
                Image        = image,
                Published    = true,
                Status       = CampaignStatus.Created, // cap nhat status da duyet luon de facebook check,
                //Status = CampaignStatus.Confirmed,
                Title                     = info.Title,
                UserCreated               = username,
                UserModified              = username,
                ExtraOptionChargePercent  = setting.CampaignExtraOptionChargePercent,
                ServiceChargePercent      = setting.CampaignServiceChargePercent,
                ServiceVATPercent         = setting.CampaignVATChargePercent,
                ServiceChargeAmount       = 0,
                AccountChargeExtraPercent = 0,
                AccountChargeAmount       = 0,
                EnabledAccountChargeExtra = false,
                AccountChargeTime         = info.AccountChargeTime ?? 1, //change avatar campaign
                Requirement               = info.Requirement,
                Type      = info.Type,
                Code      = code,
                Quantity  = target.Quantity,
                DateStart = regTime != null ? (DateTime?)regTime.Value.Start : null,
                DateEnd   = regTime != null ? (DateTime?)regTime.Value.End.AddSeconds(59) : null,
                //AccountFeedbackBefore = target.FeedbackBefore.ToViDateTime(),
                CustomKolNames    = target.CustomKolNames.ToListString(),
                Method            = CampaignMethod.OpenJoined,
                SampleContent     = info.SampleContent.ToListString(),
                Hashtag           = info.HashTag.ToListString(),
                SampleContentText = info.SampleContentText,
                KPIMin            = target.KPIMin,
                //InteractiveMin = target.InteractiveMin,
                InteractiveMin = target.KPIMin + target.InteractiveMin,

                ExecutionStart = executionTime != null ? (DateTime?)executionTime.Value.Start : null,
                ExecutionEnd   = executionTime != null ? (DateTime?)executionTime.Value.End : null,

                FeedbackStart = feedbackTime != null ? (DateTime?)feedbackTime.Value.Start : null,
                FeedbackEnd   = feedbackTime != null ? (DateTime?)feedbackTime.Value.End : null,
                AmountMax     = target.AmountMax,
                AmountMin     = target.AmountMin,
                IsSendProduct = info.SendProduct,
                ReviewStart   = reviewTime != null ? (DateTime?)reviewTime.Value.Start : null,
                ReviewEnd     = reviewTime != null ? (DateTime?)reviewTime.Value.End : null,

                ReviewAddress = reviewaddress,
                ReviewType    = info.ReviewType,
                ReviewPayback = reviewpayback
            };


            try {
                AccountType _accountType = target.AccountType[0];
                campaign.FilterAccountType = (int)_accountType;


                if (_accountType == AccountType.HotMom)
                {
                    if (target.ChildType.HasValue)
                    {
                        campaign.FilterAccountChildrenGender = target.ChildType.Value;
                    }

                    if (target.ChildAgeMin.HasValue)
                    {
                        campaign.FilterAccountAgeChildrenFrom = target.ChildAgeMin.Value;
                    }

                    if (target.ChildAgeMax.HasValue)
                    {
                        campaign.FilterAccountAgeChildrenTo = target.ChildAgeMax.Value;
                    }
                }
            }
            catch { }

            try
            {
                if (target.EnabledCity && target.CityId != null && target.CityId.Count > 0)
                {
                    string _arrCity = string.Empty;
                    foreach (var cityId in target.CityId)
                    {
                        _arrCity += _arrCity == string.Empty ? $" {cityId.ToString()} " : $"| {cityId} ";
                    }
                    campaign.FilterAccountRegion = _arrCity;
                }
            }
            catch { }

            try {
                if (target.EnabledGender && target.Gender.HasValue)
                {
                    campaign.FilterAccountGender = (int)target.Gender.Value;
                }
            }
            catch { }

            try {
                if (target.EnabledAgeRange && target.AgeEnd.HasValue && target.AgeStart.HasValue)
                {
                    campaign.FilterAccountAgeFrom = target.AgeStart.Value;
                    campaign.FilterAccountAgeTo   = target.AgeEnd.Value;
                }
            }
            catch { }

            try
            {
                if (target.EnabledCategory && target.CategoryId != null && target.CategoryId.Count > 0)
                {
                    string _arrCategories = string.Empty;
                    foreach (var categoryid in target.CategoryId)
                    {
                        _arrCategories += _arrCategories == string.Empty ? $" {categoryid.ToString()} " : $"| {categoryid} ";
                    }
                    campaign.FilterAccountCategories = _arrCategories;
                }
            }
            catch { }


            return(campaign);
        }