Ejemplo n.º 1
0
        public IActionResult DeleteAdvertisementSubmit(Advertisement myAdvertisement)
        {
            if (HttpContext.Session.GetString("auth") != "true")
            {
                return(RedirectToAction("Index", "Login"));
            }
            //delete Advertisement

            ImageManager imageManager = new ImageManager(environment, "images");
            bool         result       = imageManager.deleteImage(myAdvertisement.imgFile);

            if (result)
            {
                try {
                    AdvertRelations rel = new AdvertRelations();
                    rel = revenueManager.getAdvertRelations(myAdvertisement.adId);
                    revenueManager.Remove(rel);
                    revenueManager.SaveChanges();
                } catch {}
                revenueManager.Remove(myAdvertisement);
                revenueManager.SaveChanges();
            }
            else
            {
                Console.WriteLine("\n\n\n***There has been an error deleting the imagefile!***\n\n\n");
            }

            return(RedirectToAction("ViewAdvertisements"));
        }
Ejemplo n.º 2
0
        public IActionResult ViewAdvertisement(int myAdId)
        {
            if (HttpContext.Session.GetString("auth") != "true")
            {
                return(RedirectToAction("Index", "Login"));
            }
            Advertisement advertisement = new Advertisement();

            advertisement = revenueManager.getAdvertisement(myAdId);
            Sponsor         sponsor = new Sponsor();
            AdvertRelations rel     = new AdvertRelations();

            rel             = revenueManager.getAdvertRelations(myAdId);
            sponsor         = revenueManager.getSponsor(rel.sponsorId);
            ViewBag.sponsor = sponsor.company;
            return(View(advertisement));
        }
Ejemplo n.º 3
0
        public IActionResult EditAdvertisementSubmit(Advertisement ad, int mySponsorId, String adSize, IFormFile newImgFile)
        {
            if (HttpContext.Session.GetString("auth") != "true")
            {
                return(RedirectToAction("Index", "Login"));
            }
            ImageManager imageManager = new ImageManager(environment, "images");

            if (!ModelState.IsValid)
            {
                return(RedirectToAction("EditAdvertisement", ad.adId));
            }
            //check if sponsor is changed
            try {
                AdvertRelations oldRel = new AdvertRelations();
                oldRel = revenueManager.getAdvertRelations(ad.adId);
                if (oldRel.sponsorId != mySponsorId)
                {
                    revenueManager.Remove(oldRel);
                    revenueManager.SaveChanges();
                    AdvertRelations newRel = new AdvertRelations();
                    newRel.sponsorId = mySponsorId;
                    newRel.adId      = ad.adId;
                    revenueManager.Add(newRel);
                    revenueManager.SaveChanges();
                }
            } catch {}
            //change adSize
            if (adSize == "full")
            {
                ad.adSize = "full";
            }
            else if (adSize == "half")
            {
                ad.adSize = "half";
            }
            else if (adSize == "quarter")
            {
                ad.adSize = "quarter";
            }
            //upload new image if changed
            Console.WriteLine("\n\n\n***Image file of ad, currently: " + ad.imgFile);
            if ((newImgFile != null) && (newImgFile.FileName != "") && (ad.imgFile != newImgFile.FileName))
            {
                bool delete = imageManager.deleteImage(ad.imgFile);
                if (delete)
                {
                    int result = imageManager.uploadImage(newImgFile);
                    switch (result)
                    {
                    case 1:
                        ViewData["feedback"] = "Wrong File Type";
                        return(RedirectToAction("EditAdvertisement", ad.adId));

                    case 2:
                        ViewData["feedback"] = "File Too Large";
                        return(RedirectToAction("EditAdvertisement", ad.adId));

                    case 3:
                        ViewData["feedback"] = "File Name Too Long";
                        return(RedirectToAction("EditAdvertisement", ad.adId));

                    case 4:
                        ViewData["feedback"] = "Error Saving File";
                        return(RedirectToAction("EditAdvertisement", ad.adId));

                    case 5:
                        //image has been replaced
                        ViewData["feedback"] = "Success";
                        Console.WriteLine("\n\n\n***Successfully uploaded image to server!***");
                        ad.imgFile = imageManager.fileName;
                        revenueManager.Update(ad);
                        revenueManager.SaveChanges();
                        return(RedirectToAction("ViewAdvertisements"));

                    default:
                        ViewData["feedback"] = "No File Selected";
                        return(RedirectToAction("EditAdvertisement", ad.adId));
                    }
                }
                else
                {
                    Console.WriteLine("\n\n\n***There has been an error deleting old image file!***");
                    return(RedirectToAction("EditAdvertisement", ad.adId));
                }
            }
            else
            {
                //image not changed -> save changes to ad
                revenueManager.Update(ad);
                revenueManager.SaveChanges();
                return(RedirectToAction("ViewAdvertisements"));
            }
        }
Ejemplo n.º 4
0
        public IActionResult AddAdvertisementSubmit(Advertisement myAdvertisement, int mySponsorId, String adSize, IFormFile imgFile)
        {
            if (HttpContext.Session.GetString("auth") != "true")
            {
                return(RedirectToAction("Index", "Login"));
            }
            ImageManager imageManager = new ImageManager(environment, "images");

            if (!ModelState.IsValid)
            {
                return(RedirectToAction("AddAdvertisement"));
            }
            //submit new ad to db
            if (adSize == "full")
            {
                myAdvertisement.adSize = "full";
            }
            else if (adSize == "half")
            {
                myAdvertisement.adSize = "half";
            }
            else if (adSize == "quarter")
            {
                myAdvertisement.adSize = "quarter";
            }
            myAdvertisement.date = DateTime.Now;
            int result = imageManager.uploadImage(imgFile);

            switch (result)
            {
            case 1:
                Console.WriteLine("\n\n\n*** Wrong File Type! ***");
                ViewData["feedback"] = "Wrong File Type";
                return(RedirectToAction("AddAdvertisement"));

            case 2:
                Console.WriteLine("\n\n\n*** File Too Large! ***");
                ViewData["feedback"] = "File Too Large";
                return(RedirectToAction("AddAdvertisement"));

            case 3:
                Console.WriteLine("\n\n\n*** File Name Too Long! ***");
                ViewData["feedback"] = "File Name Too Long";
                return(RedirectToAction("AddAdvertisement"));

            case 4:
                Console.WriteLine("\n\n\n*** Error Saving File! ***");
                ViewData["feedback"] = "Error Saving File";
                return(RedirectToAction("AddAdvertisement"));

            case 5:
                ViewData["feedback"]    = "Success";
                myAdvertisement.imgFile = imageManager.fileName;
                revenueManager.Add(myAdvertisement);
                revenueManager.SaveChanges();
                //build rel with sponsor
                AdvertRelations rel = new AdvertRelations();
                rel.sponsorId = mySponsorId;
                rel.adId      = revenueManager.newAdId();
                revenueManager.Add(rel);
                revenueManager.SaveChanges();
                return(RedirectToAction("ViewAdvertisements"));

            default:
                Console.WriteLine("\n\n\n*** No File Selected! ***");
                ViewData["feedback"] = "No File Selected";
                return(RedirectToAction("AddAdvertisement"));
            }
        }