private void PreparePollModel(PollModel model, Poll poll, bool excludeProperties) { model.AvailableStores = _storeService.GetAllStores().Select(s => s.ToModel()).ToList(); if (!excludeProperties) { if (poll != null) model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(poll); else model.SelectedStoreIds = new int[0]; } }
public ActionResult Create() { if (!_permissionService.Authorize(StandardPermissionProvider.ManagePolls)) return AccessDeniedView(); ViewBag.AllLanguages = _languageService.GetAllLanguages(true); var model = new PollModel(); model.Published = true; model.ShowOnHomePage = true; PreparePollModel(model, null, false); return View(model); }
public ActionResult Edit(PollModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManagePolls)) return AccessDeniedView(); var poll = _pollService.GetPollById(model.Id); if (poll == null) return RedirectToAction("List"); if (ModelState.IsValid) { poll = model.ToEntity(poll); poll.StartDateUtc = model.StartDate; poll.EndDateUtc = model.EndDate; _pollService.UpdatePoll(poll); _storeMappingService.SaveStoreMappings<Poll>(poll, model.SelectedStoreIds); NotifySuccess(_localizationService.GetResource("Admin.ContentManagement.Polls.Updated")); return continueEditing ? RedirectToAction("Edit", new { id = poll.Id }) : RedirectToAction("List"); } //If we got this far, something failed, redisplay form ViewBag.AllLanguages = _languageService.GetAllLanguages(true); PreparePollModel(model, poll, true); return View(model); }
public ActionResult Create(PollModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManagePolls)) return AccessDeniedView(); if (ModelState.IsValid) { var poll = model.ToEntity(); poll.StartDateUtc = model.StartDate; poll.EndDateUtc = model.EndDate; _pollService.InsertPoll(poll); NotifySuccess(_localizationService.GetResource("Admin.ContentManagement.Polls.Added")); return continueEditing ? RedirectToAction("Edit", new { id = poll.Id }) : RedirectToAction("List"); } //If we got this far, something failed, redisplay form ViewBag.AllLanguages = _languageService.GetAllLanguages(true); return View(model); }