public ActionResult Render(int id) { var page = Umbraco.TypedContent(id); if (page == null) { return(null); } var banners = _bannerService.GetBannersByPage(page); if (banners == null) { return(null); } var location = _locationService.GetLocationByIp(Request.UserHostAddress); if (location == null) { return(null); } var relevantBanners = banners.Where(x => x.All || x.Countries.InvariantContains(location?.Country) || x.Continents.InvariantContains(location?.Continent)).ToList(); var vm = new BannersViewModel() { Collection = relevantBanners }; return(PartialView("Home/Banners", vm)); }
public void MessagePropertyValueUpdated() { var vm = new BannersViewModel(_regionManagerMock.Object, _messageServiceMock.Object); //_messageServiceMock.Verify(x => x.GetMessage(), Times.Once); //Assert.Equal(MessageServiceDefaultMessage, vm.Message); }
public ActionResult Create([Bind(Include = "id,title,url,state,site_id")] BannersViewModel banner) { if (ModelState.IsValid) { Mapper.Initialize(cfg => cfg.CreateMap <BannersViewModel, Banners>()); Banners banners = Mapper.Map <BannersViewModel, Banners>(banner); bannersHandler.Add(banners); return(RedirectToAction("Index")); } ViewBag.site_id = new SelectList(sitesHandler.All(), "id", "title", banner.site_id); return(View(banner)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Mapper.Initialize(cfg => cfg.CreateMap <Banners, BannersViewModel>()); BannersViewModel banner = Mapper.Map <Banners, BannersViewModel>(bannersHandler.GetById(id)); if (banner == null) { return(HttpNotFound()); } ViewBag.site_id = new SelectList(sitesHandler.All(), "id", "title", banner.site_id); return(View(banner)); }
/// <summary> /// Обрабатывается до вызова экшенов /// </summary> /// <param name="filterContext"></param> protected override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); model = new BannersViewModel { DomainName = Domain, Account = AccountInfo, Settings = SettingsInfo, UserResolution = UserResolutionInfo, ControllerName = ControllerName, ActionName = ActionName }; #region Метатеги ViewBag.Title = UserResolutionInfo.Title; ViewBag.Description = ""; ViewBag.Keywords = ""; #endregion }
public ActionResult Item(Guid id, BannersViewModel back_model, HttpPostedFileBase upload) { ErrorMessage userMessage = new ErrorMessage(); userMessage.title = "Информация"; #region Данные, необходимые для сохранения back_model.Item.Section = back_model.Item.Section != null ? back_model.Item.Section : Guid.Parse(Request.Form["Item_Section"]); back_model.Item.Site = Domain; #endregion if (ModelState.IsValid) { back_model.Item.Id = id; #region Сохранение изображения // путь для сохранения изображения string savePath = Settings.UserFiles + Domain + Settings.BannersDir; // секция if (!back_model.Item.Section.HasValue) { throw new Exception("BannerController: В back_model не определена секция"); } var _section = _cmsRepository.getSectionItem(back_model.Item.Section.Value); int width = _section.Width; // ширина int height = _section.Height; // высота if (upload != null && upload.ContentLength > 0) { string fileExtension = upload.FileName.Substring(upload.FileName.LastIndexOf(".")).ToLower(); var validExtension = (!string.IsNullOrEmpty(Settings.PicTypes)) ? Settings.PicTypes.Split(',') : "jpg,jpeg,png,gif".Split(','); if (!validExtension.Contains(fileExtension.Replace(".", ""))) { model.Item = _cmsRepository.getBannerItem(id); model.ErrorInfo = new ErrorMessage() { title = "Ошибка", info = "Вы не можете загружать файлы данного формата", buttons = new ErrorMassegeBtn[] { //Без перезагрузки, просто отменяем new ErrorMassegeBtn { url = "#", text = "ок", action = "false", style = "primary" } } }; return(View("Item", model)); } Photo photoNew = new Photo() { Name = id.ToString() + fileExtension, Size = Files.FileAnliz.SizeFromUpload(upload), Url = Files.SaveImageResizeRename(upload, savePath, id.ToString(), width, height) }; back_model.Item.Photo = photoNew; } #endregion var res = false; if (!_cmsRepository.checkBannerExist(id)) { userMessage.info = "Запись добавлена"; res = _cmsRepository.createBanner(id, back_model.Item); } else { userMessage.info = "Запись обновлена"; res = _cmsRepository.updateBanner(id, back_model.Item); } string backUrl = back_model.Item.Section != null ? "index/" + back_model.Item.Section : string.Empty; if (res) { string currentUrl = Request.Url.PathAndQuery; userMessage.buttons = new ErrorMassegeBtn[] { new ErrorMassegeBtn { url = StartUrl + backUrl, text = "Вернуться в список" }, new ErrorMassegeBtn { url = currentUrl, text = "ок" } }; } else { userMessage.info = "Произошла ошибка"; userMessage.buttons = new ErrorMassegeBtn[] { new ErrorMassegeBtn { url = StartUrl + backUrl, text = "Вернуться в список" }, new ErrorMassegeBtn { url = "#", text = "ок", action = "false" } }; } } else { userMessage.info = "Ошибка в заполнении формы. Поля в которых допушены ошибки - помечены цветом."; userMessage.buttons = new ErrorMassegeBtn[] { //Без перезагрузки action = "false" new ErrorMassegeBtn { url = "#", text = "ок", action = "false" } }; } model.Item = _cmsRepository.getBannerItem(id); model.ErrorInfo = userMessage; if (model.Item != null && model.Item.Photo != null && !string.IsNullOrEmpty(model.Item.Photo.Url)) { model.Item.Photo = Files.getInfoImage(model.Item.Photo.Url); } return(View(model)); }
public void MessageINotifyPropertyChangedCalled() { var vm = new BannersViewModel(_regionManagerMock.Object, _messageServiceMock.Object); //Assert.PropertyChanged(vm, nameof(vm.Message), () => vm.Message = "Changed"); }