public IActionResult createTheme(CreateThemeViewModel themeViewModel) { if (themeViewModel == null) { terminalResultBuilder.AddAspView(this, "CreateTheme"); return(Json(terminalResultBuilder.Build())); } else { if (db.themes.Any(t => t.name == themeViewModel.name)) { ModelState.AddModelError(nameof(themeViewModel.name), "Theme with the same name already exists"); } if (ModelState.IsValid) { Theme newTheme = themeViewModel.GetDBModel(db.users.First(u => u.login == User.Identity.Name).id); db.themes.Add(newTheme); db.SaveChanges(); terminalResultBuilder.AddAjaxFunc("Terminal/select", new Dictionary <string, string> { { "themeId", newTheme.id.ToString() } }); return(Json(terminalResultBuilder.Build())); } terminalResultBuilder.AddAspView(this, "CreateTheme", themeViewModel); return(Json(terminalResultBuilder.Build())); } }
public async Task <IActionResult> CreatePost(CreateThemeViewModel viewModel) { // Ensure we have permission if (!await _authorizationService.AuthorizeAsync(User, Permissions.CreateThemes)) { return(Unauthorized()); } var user = await _contextFacade.GetAuthenticatedUserAsync(); if (user == null) { return(Unauthorized()); } if (!ModelState.IsValid) { // Add model state errors foreach (var modelState in ViewData.ModelState.Values) { foreach (var error in modelState.Errors) { _alerter.Danger(T[error.ErrorMessage]); } } // Return return(RedirectToAction(nameof(Index))); } // Create theme var result = _themeCreator.CreateTheme(viewModel.ThemeId, viewModel.Name); if (result.Succeeded) { // Execute view providers await _viewProvider.ProvideUpdateAsync(new ThemeAdmin() { ThemeId = viewModel.ThemeId, Path = viewModel.Name }, this); // Add confirmation _alerter.Success(T["Theme Added Successfully!"]); // Return return(RedirectToAction(nameof(Index))); } else { // Report any errors foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } return(View(viewModel)); }
// Create theme. public ActionResult CreateTheme() { var theme = _themeRepository.GetActiveTheme(); var vm = new CreateThemeViewModel { SelectedThemeId = theme.ThemeId, SelectedThemeName = theme.Name }; return(View(vm)); }
public string showInputDialog(string title = null) { var modaltitle = string.IsNullOrEmpty(title) ? "Entrez le nom de votre thème" : title; ModalWindow modalWindow = new ModalWindow(); var vm = new CreateThemeViewModel(modaltitle); modalWindow.DataContext = vm; if (modalWindow.ShowDialog().Value) { return(vm.ResultJson); } return(null); }
public ActionResult CreateTheme(CreateThemeViewModel model) { if (ModelState.IsValid) { Regex regex = new Regex(@"\r\n"); model.ThemeText = regex.Replace(model.ThemeText, ""); model.ThemeText = model.ThemeText.Trim(); model.UserId = User.Identity.GetUserId(); var createThemeDto = Mapper.Map <DTOCreateThemeViewModel>(model); ThemeService.CreateTheme(createThemeDto); return(RedirectToAction("Index")); } return(View(model)); }
public async Task <ActionResult> Create(CreateThemeViewModel model) { var themeId = await ThemeService.CreateThemeAsync(model.SubjectId, User.GetId(), model.Title); var message = new CreateMessageModel { ThemeId = themeId, AuthorId = User.GetId(), Content = model.Content, AttachedFiles = Mapper.Map <ICollection <HttpPostedFileBase>, ICollection <UploadFileModel> >(model.AttachedFiles) }; await MessageService.CreateMessageAsync(message); return(RedirectToAction("Theme", new { themeId })); }
public ActionResult SaveNewTheme(CreateThemeViewModel vm) { if (!ModelState.IsValid) { return(SiteErrorHandler.GetBadRequestActionResult(ModelState)); } // Check if the theme name is already in use. if (_themeRepository.IsThemeNameAlreadyInUse(vm.ThemeId, vm.Name)) { return(SiteErrorHandler.GetBadRequestActionResult($"The theme name {vm.Name} is already in use.", nameof(vm.Name))); } var theme = _mapper.Map <ThemeModel>(vm); int id = _themeRepository.CreateTheme(theme, vm.SelectedThemeId); return(Json(new { message = "<strong>Success</strong>: The theme has been created.", themeId = id })); }
public override async Task <IViewProviderResult> BuildEditAsync(ThemeAdmin model, IViewProviderContext updater) { // We are adding a new theme if (String.IsNullOrEmpty(model.ThemeId)) { var createViewModel = new CreateThemeViewModel() { AvailableThemes = GetAvailableThemes() }; return(Views( View <CreateThemeViewModel>("Admin.Create.Header", viewModel => createViewModel).Zone("header").Order(1), View <CreateThemeViewModel>("Admin.Create.Content", viewModel => createViewModel).Zone("content").Order(1), View <CreateThemeViewModel>("Admin.Create.Footer", viewModel => createViewModel).Zone("footer").Order(1) )); } var file = _siteThemeFileManager.GetFile(model.ThemeId, model.Path); // We are editing an existing theme var editViewModel = new EditThemeViewModel() { ThemeId = model.ThemeId, Path = model.Path, File = file, FileContents = await _siteThemeFileManager.ReadFileAsync(file), Files = !string.IsNullOrEmpty(model.Path) ? _siteThemeFileManager.GetFiles(model.ThemeId, model.Path) : _siteThemeFileManager.GetFiles(model.ThemeId) }; return(Views( View <EditThemeViewModel>("Admin.Edit.Header", viewModel => editViewModel).Zone("header").Order(1), View <EditThemeViewModel>("Admin.Edit.Content", viewModel => editViewModel).Zone("content").Order(1) )); }
public CreateTheme() { InitializeComponent(); DataContext = new CreateThemeViewModel(); }