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 ZipArchive ExtractImages(CreativeSet c, ZipArchive zipArchive)
        {
            Type type = c.GetType();
            // get all public static properties of MyClass type
            var propertyInfos = type.GetProperties();

            foreach (var p in propertyInfos)
            {
                if (p.Name.Contains("Image"))
                {
                    //Create a zip entry for each attachment
                    var    zipEntry = zipArchive.CreateEntry(c.SetName + p.Name);
                    string name     = p.Name;
                    if (c.GetType().GetProperty(p.Name).GetValue(c) != null)
                    {
                        var url = c.GetType().GetProperty(p.Name).GetValue(c).ToString();

                        var    webClient  = new WebClient();
                        byte[] imageBytes = webClient.DownloadData(url);
                        //Get the stream of the attachment
                        using (var originalFileStream = new MemoryStream(imageBytes))
                            using (var zipEntryStream = zipEntry.Open())
                            {
                                //Copy the attachment stream to the zip entry stream
                                originalFileStream.CopyTo(zipEntryStream);
                            }
                    }
                }
            }
            return(zipArchive);
        }
Exemplo n.º 3
0
        public ActionResult Edit(CreativeSet set)
        {
            Type thisOne = set.GetType();

            return(View());
        }