public ViewResult CreateChannel() { var model = new EditChannelViewModel { Channel = new Channel(-1), Channels = channelRepository.Channels.ToHashSet() }; return(View("EditChannel", model)); }
public ViewResult EditChannel(int id) { var channel = channelRepository.Channels.Find(id); var model = new EditChannelViewModel { Channel = channel, Channels = channelRepository.Channels.ToHashSet(), ParentId = channel.Parent.Id }; return(View(model)); }
public async Task <IActionResult> CreatePost(EditChannelViewModel viewModel) { if (!ModelState.IsValid) { return(await Create(viewModel.Id)); } var iconCss = viewModel.IconCss; if (!string.IsNullOrEmpty(iconCss)) { iconCss = viewModel.IconPrefix + iconCss; } var feature = await GetCurrentFeature(); var category = new Category() { ParentId = viewModel.ParentId, FeatureId = feature.Id, Name = viewModel.Name, Description = viewModel.Description, ForeColor = viewModel.ForeColor, BackColor = viewModel.BackColor, IconCss = iconCss }; var result = await _categoryManager.CreateAsync(category); if (result.Succeeded) { await _viewProvider.ProvideUpdateAsync(result.Response, this); _alerter.Success(T["Category Added Successfully!"]); return(RedirectToAction(nameof(Index))); } else { foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } return(View(viewModel)); }
public ActionResult EditChannel(EditChannelViewModel model) { model.Channels = channelRepository.Channels.ToHashSet(); model.Channel.Parent = channelRepository.Channels.Find(model.ParentId); ModelState.Clear(); TryValidateModel(model); TryValidateModel(model.Channel, "Channel"); TryValidateModel(model.Channel.Parent, "Channel.Parent"); if (ModelState.IsValid) { channelRepository.CreateOrUpdate(model.Channel); TempData["message"] = string.Format("{0} has been saved.", model.Channel.Name); return(RedirectToAction("Channels")); } return(View(model)); }
public override async Task <IViewProviderResult> BuildEditAsync(CategoryAdmin categoryBase, IViewProviderContext updater) { var defaultIcons = new DefaultIcons(); EditChannelViewModel editChannelViewModel = null; if (categoryBase.Id == 0) { editChannelViewModel = new EditChannelViewModel() { IconPrefix = defaultIcons.Prefix, ChannelIcons = defaultIcons, IsNewChannel = true, ParentId = categoryBase.ParentId, AvailableChannels = await GetAvailableCategories() }; } else { editChannelViewModel = new EditChannelViewModel() { Id = categoryBase.Id, ParentId = categoryBase.ParentId, Name = categoryBase.Name, Description = categoryBase.Description, ForeColor = categoryBase.ForeColor, BackColor = categoryBase.BackColor, IconCss = categoryBase.IconCss, IconPrefix = defaultIcons.Prefix, ChannelIcons = defaultIcons, AvailableChannels = await GetAvailableCategories() }; } return(Views( View <EditChannelViewModel>("Admin.Edit.Header", model => editChannelViewModel).Zone("header").Order(1), View <EditChannelViewModel>("Admin.Edit.Content", model => editChannelViewModel).Zone("content").Order(1), View <EditChannelViewModel>("Admin.Edit.Actions", model => editChannelViewModel).Zone("actions").Order(1), View <EditChannelViewModel>("Admin.Edit.Footer", model => editChannelViewModel).Zone("footer").Order(1) )); }
public override async Task <IViewProviderResult> BuildUpdateAsync(CategoryAdmin categoryBase, IViewProviderContext context) { var model = new EditChannelViewModel(); if (!await context.Updater.TryUpdateModelAsync(model)) { return(await BuildEditAsync(categoryBase, context)); } model.Name = model.Name?.Trim(); model.Description = model.Description?.Trim(); if (context.Updater.ModelState.IsValid) { var iconCss = model.IconCss; if (!string.IsNullOrEmpty(iconCss)) { iconCss = model.IconPrefix + iconCss; } var result = await _categoryManager.UpdateAsync(new Category() { Id = categoryBase.Id, FeatureId = categoryBase.FeatureId, ParentId = model.ParentId, Name = model.Name, Description = model.Description, ForeColor = model.ForeColor, BackColor = model.BackColor, IconCss = iconCss, SortOrder = categoryBase.SortOrder }); foreach (var error in result.Errors) { context.Updater.ModelState.AddModelError(string.Empty, error.Description); } } return(await BuildEditAsync(categoryBase, context)); }