Ejemplo n.º 1
0
        //check if Advert already exist in the following locations
        //"leader board,MediumRectangle1-3, and square board "
        public JsonResult is_Ads_In_Loc(AdvertManagerViewModel model)
        {
            try{
                var adloc = model.AdsLocOnPage.locId;
                if (adloc == "LeaderBoard")
                {
                    //check if advert already exist in selected location
                    var adv = db.AdvertManagerTb.Where(a => a.AdsLocOnPage == adloc && a.AdsStatus == "Active");
                    if (adv.Count() > 0)
                    {
                        return(Json("Advert already exist in this location selected, kindly select a different location", JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(true, JsonRequestBehavior.AllowGet));
                    }
                }
                else if (adloc == "MediumRectangle1")
                {
                    //check if advert already exist in selected location
                    var adv = db.AdvertManagerTb.Where(a => a.AdsLocOnPage == adloc && a.AdsStatus == "Active");
                    if (adv.Count() > 0)
                    {
                        return(Json("Advert already exist in this location selected, kindly select a different location", JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(true, JsonRequestBehavior.AllowGet));
                    }
                }
                else if (adloc == "MediumRectangle2")
                {
                    //check if advert already exist in selected location
                    var adv = db.AdvertManagerTb.Where(a => a.AdsLocOnPage == adloc && a.AdsStatus == "Active");
                    if (adv.Count() > 0)
                    {
                        return(Json("Advert already exist in this location selected, kindly select a different location", JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(true, JsonRequestBehavior.AllowGet));
                    }
                }
                else if (adloc == "MediumRectangle3")
                {
                    //check if advert already exist in selected location
                    var adv = db.AdvertManagerTb.Where(a => a.AdsLocOnPage == adloc && a.AdsStatus == "Active");
                    if (adv.Count() > 0)
                    {
                        return(Json("Advert already exist in this location selected, kindly select a different location", JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(true, JsonRequestBehavior.AllowGet));
                    }
                }

                //    return Json(true, JsonRequestBehavior.AllowGet);
            }
            catch {
                return(Json("error exist", JsonRequestBehavior.AllowGet));
            }
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> createAds(AdvertManagerViewModel model, HttpPostedFileBase AdsImage)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    AdvertManagerTb ads = new AdvertManagerTb();
                    ads.AdsOwner = model.AdsOwner;
                    //ads.AdsName = model.AdsName;
                    ads.Adspage      = model.adspage.pageId;
                    ads.AdsLocOnPage = model.AdsLocOnPage.locId;
                    ads.AdsURL       = model.AdsUrl;
                    ads.AdsStatus    = "Active";
                    ads.CreatedDate  = DateTime.UtcNow;
                    var adloc = model.AdsLocOnPage.locId;
                    if (adloc == "SquareBoard")
                    {
                        //check if advert already exist in selected location
                        string getAdsPage = model.adspage.pageId;
                        if (getAdsPage == "FindHospitalPage")
                        {
                            var adv = db.AdvertManagerTb.Where(a => a.AdsLocOnPage == adloc && a.AdsStatus == "Active" && a.Adspage == getAdsPage);
                            if (adv.Count() > 0)
                            {
                                ModelState.AddModelError("", "Advert already exist in the page '" + model.adspage.pageId + "' for the location selected, kindly select a different page or location");
                                ViewBag.errorMsg = "Advert already exist in the page '" + model.adspage.pageId + "' for the location selected, kindly select a different page or location";
                                return(View());
                            }
                        }
                        else if (getAdsPage == "SearchPharmacyPage")
                        {
                            var adv = db.AdvertManagerTb.Where(a => a.AdsLocOnPage == adloc && a.AdsStatus == "Active" && a.Adspage == getAdsPage);
                            if (adv.Count() > 0)
                            {
                                ModelState.AddModelError("", "Advert already exist in the page '" + model.adspage.pageId + "' for the location selected, kindly select a different page or location");
                                ViewBag.errorMsg = "Advert already exist in the page '" + model.adspage.pageId + "' for the location selected, kindly select a different page or location";
                                return(View());
                            }
                        }
                        else if (getAdsPage == "SearchDrugPage")
                        {
                            var adv = db.AdvertManagerTb.Where(a => a.AdsLocOnPage == adloc && a.AdsStatus == "Active" && a.Adspage == getAdsPage);
                            if (adv.Count() > 0)
                            {
                                ModelState.AddModelError("", "Advert already exist in the page '" + model.adspage.pageId + "' for the location selected, kindly select a different page or location");
                                ViewBag.errorMsg = "Advert already exist in the page '" + model.adspage.pageId + "' for the location selected, kindly select a different page or location";
                                return(View());
                            }
                        }
                        else if (getAdsPage == "FindLabPage")
                        {
                            var adv = db.AdvertManagerTb.Where(a => a.AdsLocOnPage == adloc && a.AdsStatus == "Active" && a.Adspage == getAdsPage);
                            if (adv.Count() > 0)
                            {
                                ModelState.AddModelError("", "Advert already exist in the page '" + model.adspage.pageId + "' for the location selected, kindly select a different page or location");
                                ViewBag.errorMsg = "Advert already exist in the page '" + model.adspage.pageId + "' for the location selected, kindly select a different page or location";
                                return(View());
                            }
                        }
                        else if (getAdsPage == "MedEquipCompPage")
                        {
                            var adv = db.AdvertManagerTb.Where(a => a.AdsLocOnPage == adloc && a.AdsStatus == "Active" && a.Adspage == getAdsPage);
                            if (adv.Count() > 0)
                            {
                                ModelState.AddModelError("", "Advert already exist in the page '" + model.adspage.pageId + "' for the location selected, kindly select a different page or location");
                                ViewBag.errorMsg = "Advert already exist in the page '" + model.adspage.pageId + "' for the location selected, kindly select a different page or location";
                                return(View());
                            }
                        }
                        else if (getAdsPage == "FindMedEquipPage")
                        {
                            var adv = db.AdvertManagerTb.Where(a => a.AdsLocOnPage == adloc && a.AdsStatus == "Active" && a.Adspage == getAdsPage);
                            if (adv.Count() > 0)
                            {
                                ModelState.AddModelError("", "Advert already exist in the page '" + model.adspage.pageId + "' for the location selected, kindly select a different page or location");
                                ViewBag.errorMsg = "Advert already exist in the page '" + model.adspage.pageId + "' for the location selected, kindly select a different page or location";
                                return(View());
                            }
                        }
                        else if (getAdsPage == "SearchHerbalCentrePage")
                        {
                            var adv = db.AdvertManagerTb.Where(a => a.AdsLocOnPage == adloc && a.AdsStatus == "Active" && a.Adspage == getAdsPage);
                            if (adv.Count() > 0)
                            {
                                ModelState.AddModelError("", "Advert already exist in the page '" + model.adspage.pageId + "' for the location selected, kindly select a different page or location");
                                ViewBag.errorMsg = "Advert already exist in the page '" + model.adspage.pageId + "' for the location selected, kindly select a different page or location";
                                return(View());
                            }
                        }
                        else if (getAdsPage == "SearchHerbalDrugPage")
                        {
                            var adv = db.AdvertManagerTb.Where(a => a.AdsLocOnPage == adloc && a.AdsStatus == "Active" && a.Adspage == getAdsPage);
                            if (adv.Count() > 0)
                            {
                                ModelState.AddModelError("", "Advert already exist in the page '" + model.adspage.pageId + "' for the location selected, kindly select a different page or location");
                                ViewBag.errorMsg = "Advert already exist in the page '" + model.adspage.pageId + "' for the location selected, kindly select a different page or location";
                                return(View());
                            }
                        }
                        else if (getAdsPage == "SearchVetDrugPage")
                        {
                            var adv = db.AdvertManagerTb.Where(a => a.AdsLocOnPage == adloc && a.AdsStatus == "Active" && a.Adspage == getAdsPage);
                            if (adv.Count() > 0)
                            {
                                ModelState.AddModelError("", "Advert already exist in the page '" + model.adspage.pageId + "' for the location selected, kindly select a different page or location");
                                ViewBag.errorMsg = "Advert already exist in the page '" + model.adspage.pageId + "' for the location selected, kindly select a different page or location";
                                return(View());
                            }
                        }
                        else if (getAdsPage == "SearchVetCentrePage")
                        {
                            var adv = db.AdvertManagerTb.Where(a => a.AdsLocOnPage == adloc && a.AdsStatus == "Active" && a.Adspage == getAdsPage);
                            if (adv.Count() > 0)
                            {
                                ModelState.AddModelError("", "Advert already exist in the page '" + model.adspage.pageId + "' for the location selected, kindly select a different page or location");
                                ViewBag.errorMsg = "Advert already exist in the page '" + model.adspage.pageId + "' for the location selected, kindly select a different page or location";
                                return(View());
                            }
                        }
                    }
                    if (AdsImage != null)
                    {
                        byte[] img = new byte[AdsImage.InputStream.Length];
                        AdsImage.InputStream.Read(img, 0, (int)AdsImage.InputStream.Length);
                        System.Drawing.Image image2validate = System.Drawing.Image.FromStream(AdsImage.InputStream, true, true);
                        if (ads.AdsLocOnPage == "LeaderBoard")
                        {
                            if (image2validate.Height == 90 && image2validate.Width == 728)
                            {
                                ads.AdsImage = img;
                                db.AdvertManagerTb.Add(ads);
                                await db.SaveChangesAsync();

                                TempData["success"] = "Advert created successfully";
                                ModelState.Clear();
                                return(View());
                            }
                            else
                            {
                                TempData["error"] = "Advert image does not match Ads location, please kindly upload an image of equal size with image location";
                                ViewBag.errorMsg  = "Advert Image does not match Advert location size!";
                                return(View());
                            }
                        }
                        else if (ads.AdsLocOnPage == "MediumRectangle1" || ads.AdsLocOnPage == "MediumRectangle2" || ads.AdsLocOnPage == "MediumRectangle3")
                        {
                            if (image2validate.Height == 250 && image2validate.Width == 300)
                            {
                                //     AdsImage.InputStream.Read(img, 0, (int)AdsImage.InputStream.Length);
                                ads.AdsImage = img;
                                db.AdvertManagerTb.Add(ads);
                                await db.SaveChangesAsync();

                                TempData["success"] = "Advert created successfully";
                                ModelState.Clear();
                                return(View());
                            }
                            else
                            {
                                TempData["error"] = "Advert image does not match Ads location, please kindly upload an image of equal size with image location";
                                ViewBag.errorMsg  = "Advert Image does not match Advert location size!";
                                return(View());
                            }
                        }
                        else if (ads.AdsLocOnPage == "Slider")
                        {
                            if (image2validate.Height == 450 && image2validate.Width == 1000)
                            {
                                //   AdsImage.InputStream.Read(img, 0, (int)AdsImage.InputStream.Length);
                                ads.AdsImage = img;
                                db.AdvertManagerTb.Add(ads);
                                await db.SaveChangesAsync();

                                TempData["success"] = "Advert created successfully";
                                ModelState.Clear();
                                return(View());
                            }
                            else
                            {
                                TempData["error"] = "Advert image does not match Ads location, please kindly upload an image of equal size with image location";
                                ViewBag.errorMsg  = "Advert Image does not match Advert location size!";
                                return(View());
                            }
                        }
                        else if (ads.AdsLocOnPage == "SquareBoard")
                        {
                            if (image2validate.Height == 300 && image2validate.Width == 280)
                            {
                                // AdsImage.InputStream.Read(img, 0, (int)AdsImage.InputStream.Length);
                                ads.AdsImage = img;
                                db.AdvertManagerTb.Add(ads);
                                await db.SaveChangesAsync();

                                TempData["success"] = "Advert created successfully";
                                ModelState.Clear();
                                return(View());
                            }
                            else
                            {
                                TempData["error"] = "Advert image does not match Ads location, please kindly upload an image of equal size with image location";
                                ViewBag.errorMsg  = "Advert Image does not match Advert location size!";
                                return(View());
                            }
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "All fields marked with (*) are compulsory");
                        TempData["warning"] = "All fields marked with (*) are compulsory";
                        return(View());
                    }
                }
                else
                {
                    ModelState.AddModelError("", "All fields marked with (*) are compulsory");
                    TempData["warning"] = "All fields marked with (*) are compulsory";
                    return(View());
                }
            }
            catch (Exception ex)
            {
                TempData["error"] = "an error has occurred!!!";
                ModelState.AddModelError("", ex);
                return(View());
            }
            return(View());
        }