Exemplo n.º 1
0
        public ActionResult Add(int LineItemId, string GivenType)
        {
            CreativeSet s = (CreativeSet)Activator.CreateInstance(Type.GetType(GivenType));

            var context = new ApplicationDbContext();

            var lineItem = context.LineItems.Where(l => l.LineItemID == LineItemId).FirstOrDefault();
            var baseName = lineItem.Creative.OrderBy(m => m.CreativeSetID).FirstOrDefault().SetName;
            var index    = lineItem.Creative.Count() + 1;

            s.SetName = baseName.Replace("Set_1", $"Set_{index}");

            if (Type.GetType(GivenType) == typeof(PremiumAd))
            {
                BannerAds b = new BannerAds();
                NativeAds n = new NativeAds();
                ((PremiumAd)s).NativAds  = n;
                ((PremiumAd)s).BannerAds = b;
            }
            lineItem.Creative.Add(s);

            context.SaveChanges();

            EditCreativeSettViewModel vm = new EditCreativeSettViewModel {
                CreativeSet = s, Index = index - 1
            };

            return(PartialView("Edit", vm));
        }
Exemplo n.º 2
0
    private TaplighNativeAd SetNativeDTO(string data, string unit)
    {
        TaplighNativeAd nativeAd = new TaplighNativeAd();

        //new edit
        string json     = data;
        int    position = data.IndexOf("***");

        if (!(position < 0))
        {
            var A = data.Substring(0, position);
            json = data.Substring(position + 1);
        }
        Debug.Log("Json :" + json);

        NativeAds nAdJson = JsonUtility.FromJson <NativeAds> (json);

        nativeAd.nAd = nAdJson;
        Debug.Log(nAdJson.banners.AR9x16);

        StartCoroutine(SetNativeAdImages(nativeAd, unit));

        return(nativeAd);
    }
Exemplo n.º 3
0
        public ActionResult UpsertOrder(APIOrders order, string secret)
        {
            try
            {
                ValidationContext vc = new ValidationContext(order);                    // The simplest form of validation context. It contains only a reference to the object being validated.

                ICollection <ValidationResult> results = new List <ValidationResult>(); // Will contain the results of the validation
                bool isValid = Validator.TryValidateObject(order, vc, results, true);
                if (!isValid)
                {
                    string message = "The following fields are either missing or not in the correct format:";
                    foreach (var r in results)
                    {
                        foreach (var m in r.MemberNames)
                        {
                            message += r.MemberNames + ",";
                        }
                    }
                    message.TrimEnd(new char[] { ',' });
                    return(Json(new { succes = false, ErrorMessage = message }));
                }
                ApplicationDbContext context = new ApplicationDbContext();
                var newOrder = false;

                if (secret == ConfigurationManager.AppSettings["APISecret"])
                {
                    var o = context.Orders.Where(c => c.BHIOrderNumber == order.workOrderNumber).FirstOrDefault();
                    if (o == null)
                    {
                        o = new Order();
                        context.Orders.Add(o);
                        newOrder = true;
                    }
                    o.BHIOrderNumber    = order.workOrderNumber;
                    o.OrderName         = order.orderName;
                    o.ContractStartDate = order.contractStartDate;
                    o.ContractEndDate   = order.contractEndDate;


                    foreach (var p in order.products)
                    {
                        var line = new LineItem();
                        if (!newOrder)
                        {
                            line = context.LineItems.Where(c => c.Order.BHIOrderNumber == o.BHIOrderNumber && c.Taxonomy == p.campaignName).FirstOrDefault();
                        }
                        if (line == null)
                        {
                            line = new LineItem();
                            context.LineItems.Add(line);
                        }


                        line.Taxonomy             = p.campaignName;
                        line.Order                = o;
                        line.LocationSublocation  = p.advertisingLocation + "/" + p.advertisingSubLocation;
                        line.LocationSublocation += p.advertisingCommunity == null ? "" : "/" + p.advertisingCommunity;
                        line.StartDate            = p.applicableStartDate;
                        line.EndDate              = p.applicableEndDate;
                        line.Product              = p.productName;


                        if (line.Creative == null || line.Creative.Count == 0)
                        {
                            CreativeSet set;
                            if (p.productName.Contains("BDX Premium"))
                            {
                                set = new PremiumAd();
                            }
                            else if (p.productName.Contains("BDX Native"))
                            {
                                set = new NativeAds();
                            }
                            else
                            {
                                set = new NativeAds();
                            }
                            set.SortOrder = 0;
                            set.SetName   = p.campaignName + "_Set_1";

                            set.Line = line;
                            context.CreativeSets.Add(set);
                        }
                    }

                    context.SaveChanges();


                    return(Json(new { success = true, AssetPortalID = o.ID }));
                }
                else
                {
                    return(Json(new { succes = false, ErrorMessage = "Secret Key is invalid" }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { succes = false, message = ex.Message }));
            }
        }