Ejemplo n.º 1
0
        public ActionResult ManageAds(AdsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.CityId = meniuService.GetCitiesForDropDown();
                var enumValues = Enum.GetValues(typeof(Meniu.DataTypes.Enums.Zones))
                    .Cast<Meniu.DataTypes.Enums.Zones>()
                    .Select(e => new { Value = e.ToString(), Text = e.ToString() }).ToList();

                ViewBag.Zone = new SelectList(enumValues, "Value", "Text");
                return View(model);
            }
            if (!ImageService.ValidateImageForZone(model.Zone.ToString(), model.Image))
            {
                ViewBag.CityId = meniuService.GetCitiesForDropDown();
                var enumValues = Enum.GetValues(typeof(Meniu.DataTypes.Enums.Zones))
                    .Cast<Meniu.DataTypes.Enums.Zones>()
                    .Select(e => new { Value = e.ToString(), Text = e.ToString() }).ToList();

                ViewBag.Zone = new SelectList(enumValues, "Value", "Text");
                ModelState.AddModelError("", "La imagen estaba en formato invalido.");
                return View(model);
            }

            if (!service.ValidateAd(model.Zone.ToString(), model.CityId, model.StartsOn, model.ToBeConcluded))
            {
                ViewBag.CityId = meniuService.GetCitiesForDropDown();
                var enumValues = Enum.GetValues(typeof(Meniu.DataTypes.Enums.Zones))
                    .Cast<Meniu.DataTypes.Enums.Zones>()
                    .Select(e => new { Value = e.ToString(), Text = e.ToString() }).ToList();

                ViewBag.Zone = new SelectList(enumValues, "Value", "Text");
                ModelState.AddModelError("", "Ya existe publicidad para esas fechas.");
                return View(model);
            }

            service.SaveAds(model);
            return View("_success");
        }
Ejemplo n.º 2
0
        public void SaveAds(AdsViewModel model)
        {
            int cityId = int.Parse(model.CityId);
            if (locationRepository.CityExists(cityId))
            {
                string cityName = locationRepository.GetCityNameById(cityId);
                string imgUrl= String.Empty;
                if (model.Image != null)
                {
                    ImageService.Image = model.Image;
                    imgUrl = ImageService.SaveAdImage(model.Zone.ToString(), cityName);
                }
                var banner = new Banner
                {
                    CityId = cityId,
                    EndDate = model.ToBeConcluded,
                    StartDate = model.StartsOn,
                    ImgUrl = imgUrl,
                    Type = model.Zone.ToString()
                };

                adsRepository.SaveAd(banner);
            }
        }