Example #1
0
        private string UploadFile(string base64Path, AdvertisementType type)
        {
            if (base64Path.Contains(type == AdvertisementType.Image ? Constants.AdsImagesPath : Constants.AdsVideoPath))
            {
                return(base64Path);
            }

            var path         = string.Empty;
            var base64String = base64Path.Split(';')[1].Split(',')[1];
            var extension    = base64Path.Split(';')[0].Split(':')[1].Split('/')[1];
            var fileBytes    = Convert.FromBase64String(base64String);

            using (var ms = new MemoryStream(fileBytes, 0, fileBytes.Length))
            {
                var directoryPath = HttpContext.Current.Server.MapPath(type == AdvertisementType.Image ? Constants.AdsImagesPath : Constants.AdsVideoPath);
                if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }

                //upload file
                var filePathGuid = $"{Guid.NewGuid().ToString()}.{extension}";
                var fullPath     = Path.Combine(directoryPath, filePathGuid);
                FileUploader.UploadFile(ms, fullPath);

                path = type == AdvertisementType.Image
                    ? $"{Constants.AdsImagesPath}{filePathGuid}"
                    : $"{Constants.AdsVideoPath}{filePathGuid}";
            }

            return(path);
        }
Example #2
0
 //saves the advertisements
 public void saveAdvertisements()
 {
     foreach (AirlineAdvertisementMVVM advertisement in this.Advertisements)
     {
         AdvertisementType type = advertisement.SelectedType;
         this.Airline.setAirlineAdvertisement(type);
     }
 }
        public async Task <IViewComponentResult> InvokeAsync(AdvertisementType advertisementTypeToShow, int numberOfAdvertisementsToShow, BLL.DTOs.Advertisement?similarAdvertisement)
        {
            var         advertisements = new List <BasicAdvertisementCard>();
            SearchModel searchModel    = new SearchModel()
            {
                SortOrder = BLL.Services.SortOrder.Latest
            };

            switch (advertisementTypeToShow)
            {
            case AdvertisementType.Priorized:
                searchModel.IsPriorized = true;
                searchModel.IsWithPhoto = true;
                break;

            case AdvertisementType.Latest:
                searchModel.IsPriorized = false;
                searchModel.IsWithPhoto = true;
                searchModel.SortOrder   = BLL.Services.SortOrder.Latest;
                break;

            case AdvertisementType.Similar:
                if (similarAdvertisement == null)
                {
                    throw new NullReferenceException("Nincs megadva hasonló hirdetés");
                }
                searchModel.CategoryId = similarAdvertisement.CategoryId;
                if (similarAdvertisement.Seller == null)
                {
                    searchModel.IsBuying = true;
                }
                else
                {
                    searchModel.IsBuying = false;
                }
                break;
            }
            var dtoAdvertisements = await _advertisementService.GetAdvertisementsAsync(searchModel, numberOfAdvertisementsToShow);

            if (advertisementTypeToShow == AdvertisementType.Similar)
            {
                dtoAdvertisements = FilterAds(numberOfAdvertisementsToShow, dtoAdvertisements, similarAdvertisement !);
            }

            advertisements = dtoAdvertisements
                             .Select(a => new BasicAdvertisementCard
            {
                Id        = a.Id,
                Title     = a.Title,
                Price     = a.Price,
                ImagePath = a.AdvertisementImagePaths.FirstOrDefault(),
                City      = a.City.Name,
                AdType    = a.Seller == null ? AdType.Buying : AdType.Selling
            })
                             .ToList();
            return(View("AdvertisementList", advertisements));
        }
 public RealEstateOfferRequestModel(Province a_province, City a_city, PropertyType a_propertyType, AdvertisementType a_advertisementType)
 {
     //Always start from first page
     PageNumber        = 1;
     Province          = a_province;
     PropertyType      = a_propertyType;
     AdvertisementType = a_advertisementType;
     City = a_city;
 }
Example #5
0
        public AdvertisementType AddAdvertisementType(AdvertisementTypeViewModel viewModel)
        {
            var model = new AdvertisementType
            {
                TypeName = viewModel.AdvertisementType
            };

            _context.Add(model);
            _context.SaveChanges();
            return(model);
        }
Example #6
0
        public void Update(TypeDTO item)
        {
            AdvertisementType types = TypeMapper.CreateType().Map(item);

            using (var uow = _uowfactory.CreateUnitOfWork())
            {
                var repo = uow.GetRepo <AdvertisementType>();
                repo.Update(types);
                uow.BeginTransaction();
                uow.Commit();
            }
        }
Example #7
0
        private void btnSaveAdvertisement_Click(object sender, RoutedEventArgs e)
        {
            foreach (AdvertisementType.AirlineAdvertisementType type in Enum.GetValues(typeof(AdvertisementType.AirlineAdvertisementType)))
            {
                if (GameObject.GetInstance().GameTime.Year >= (int)type)
                {
                    ComboBox cbAdvertisement = cbAdvertisements[type];

                    AdvertisementType aType = (AdvertisementType)cbAdvertisement.SelectedItem;
                    this.Airline.setAirlineAdvertisement(aType);
                }
            }
        }
Example #8
0
        public IViewComponentResult SidebarBanner(AdvertisementType adType)
        {
            List <Advertisment> query = _cache.Get <List <Advertisment> >(SidebarBannerAdKey);

            if (query == null)
            {
                query = _db.Advertisments.Where(a => a.AdType == AdvertisementType.SidebarBanner1 || a.AdType == AdvertisementType.SidebarBanner2).ToList();
                _cache.Set(SidebarBannerAdKey, query);
            }
            var ads = query.Where(a => a.AdType == adType).GroupBy(a => a.AdOrder).OrderBy(_ => Guid.NewGuid()).FirstOrDefault()?.ToList();

            return(View("SidebarBanner", ads));
        }
Example #9
0
        private string GetAdViewName(AdvertisementType t)
        {
            switch (t)
            {
            case AdvertisementType.SidebarBanner1:
            case AdvertisementType.SidebarBanner2:
                return("_SidebarBannerManage");

            default:
                return($"_{t.ToString()}Manage");
            }
            throw new ArgumentException();
        }
Example #10
0
        private string GetAdCacheKey(AdvertisementType t)
        {
            switch (t)
            {
            case AdvertisementType.Banner:
                return(CacheService.BannerAdKey);

            case AdvertisementType.Carousel:
            case AdvertisementType.CarouselBanner:
                return(CacheService.CarouselAdKey);

            case AdvertisementType.Sidebar:
                return(CacheService.SidebarAdKey);

            case AdvertisementType.SidebarBanner1:
            case AdvertisementType.SidebarBanner2:
                return(CacheService.SidebarBannerAdKey);
            }
            throw new ArgumentException();
        }
Example #11
0
        public IViewComponentResult Invoke(AdvertisementType AdType, string pos)
        {
            switch (AdType)
            {
            case AdvertisementType.Carousel:
            case AdvertisementType.CarouselBanner:
                return(Carousel());

            case AdvertisementType.Sidebar:
                return(Sidebar(pos));

            case AdvertisementType.Banner:
                return(Banner());

            case AdvertisementType.SidebarBanner1:
            case AdvertisementType.SidebarBanner2:
                return(SidebarBanner(AdType));

            default:
                throw new ArgumentException("Unknown Ad type", "AdType");
            }
        }
Example #12
0
        public Advertising(
            Guid id,
            [NotNull] string name,
            string label,
            AdvertisementType advertisementType,
            int width,
            int height,
            int?itemPrice,
            bool isActive,
            string expiredContent
            ) : base(id)
        {
            Check.NotNullOrEmpty(name, nameof(name));

            Name              = name;
            Label             = label;
            AdvertisementType = advertisementType;
            Width             = width;
            Height            = height;
            ItemPrice         = itemPrice;
            IsActive          = isActive;
            ExpiredContent    = expiredContent;
        }
Example #13
0
        public async Task <List <Models.Advertisement> > GetAllAsync(int siteId, AdvertisementType advertisementType)
        {
            var advertisements = await GetAllAsync(siteId);

            return(advertisements.Where(x => x.AdvertisementType == advertisementType).ToList());
        }
Example #14
0
        public ActionResult Search(string city = "all", string propType = "all", string province = "all", string advType = "all", int page = 1)
        {
            List <RealEstateOfferModel> list = null;

            try
            {
                if (city == "")
                {
                    city = "all";
                }
                RealEstateOfferRequestModel requestModel = new RealEstateOfferRequestModel(Province.FromString(province), City.FromString(city), PropertyType.FromString(propType), AdvertisementType.FromString(advType));
                list = WebsitesManagement.GetFilteredOffers(requestModel);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                TempData["Error"] = ex.Message;
            }
            ViewBag.cityFilter          = city;
            ViewBag.propertyFilter      = propType;
            ViewBag.provinceFilter      = province;
            ViewBag.advertisementFilter = advType;
            ViewBag.cities    = DataManagement.getCities();
            ViewBag.provinces = DataManagement.getProvinces();
            if (list == null)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(list.ToPagedList(page, 10)));
            }
        }
Example #15
0
        public ActionResult AdManage(Advertisment ad, string action)
        {
            AdvertisementType AdType = ad.AdType;

            switch (action)
            {
            case "new":
                if (string.IsNullOrWhiteSpace(ad.AdUrl))
                {
                    return(Json(new { err = "请输入URL" }));
                }
                else if (string.IsNullOrWhiteSpace(ad.AdTitle) && ad.AdType == AdvertisementType.Carousel)
                {
                    return(Json(new { err = "请输入标题" }));
                }
                else
                {
                    _db.Advertisments.Add(ad);
                    _db.SaveChanges();
                }
                break;

            case "edit":
                if (string.IsNullOrWhiteSpace(ad.AdUrl))
                {
                    return(Json(new { err = "请输入URL" }));
                }
                else
                {
                    var a = _db.Advertisments.Find(ad.AdID);
                    if (a != null)
                    {
                        a.AdTitle = ad.AdTitle;
                        a.AdUrl   = ad.AdUrl;
                        a.ImgUrl  = ad.ImgUrl;
                        a.AdOrder = ad.AdOrder;
                        _db.SaveChanges();
                        AdType = a.AdType;
                    }
                    else
                    {
                        return(Json(new { err = "未找到" }));
                    }
                }
                break;

            case "del":
            {
                var a = _db.Advertisments.Find(ad.AdID);
                if (a != null)
                {
                    _db.Advertisments.Remove(a);
                    _db.SaveChanges();
                    AdType = a.AdType;
                }
                else
                {
                    return(Json(new { err = "未找到" }));
                }
            }
            break;
            }
            _cache.Remove(GetAdCacheKey(AdType));
            if (!User.IsInRole("Administrator"))
            {
                _adminUtil.log(User.Identity.Name, action + " AD", AdType.ToString(), ad.AdID + " " + ad.AdTitle);
            }
            return(PartialView(GetAdViewName(AdType), new AdViewModel {
                Ads = _db.Advertisments.Where(aa => aa.AdType == AdType).ToList(), Type = AdType
            }));
        }