public async Task <IActionResult> CreatePost(EditLabelViewModel viewModel) { var user = await _contextFacade.GetAuthenticatedUserAsync(); if (user == null) { return(Unauthorized()); } if (!ModelState.IsValid) { return(View(viewModel)); } // Create label var label = new Label() { FeatureId = await GetFeatureIdAsync(), Name = viewModel.Name, Description = viewModel.Description, ForeColor = viewModel.ForeColor, BackColor = viewModel.BackColor, CreatedUserId = user.Id, CreatedDate = DateTimeOffset.UtcNow }; // Persist label var result = await _labelManager.CreateAsync(label); if (result.Succeeded) { // Indicate new label result.Response.IsNewLabel = true; // Execute view providers await _viewProvider.ProvideUpdateAsync(result.Response, this); // Add confirmation _alerter.Success(T["Label Added Successfully!"]); // Return return(RedirectToAction(nameof(Index))); } else { foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } return(View(viewModel)); }
async Task <ICommandResultBase> InstallLabelAsync(IShellFeature feature, int sortOrder = 0) { // Validate if (feature == null) { throw new ArgumentNullException(nameof(feature)); } if (string.IsNullOrEmpty(feature.ModuleId)) { throw new ArgumentNullException(nameof(feature.ModuleId)); } var user = await _contextFacade.GetAuthenticatedUserAsync(); // Our result var result = new CommandResultBase(); var foreColor = "#ffffff"; var backColor = $"#{_colorProvider.GetColor()}"; var categoryResult = await _labelManager.CreateAsync(new LabelBase() { FeatureId = feature.Id, ParentId = 0, Name = $"Example Label {_random.Next(0, 2000).ToString()}", Description = $"This is an example label description.", ForeColor = foreColor, BackColor = backColor, SortOrder = sortOrder, CreatedUserId = user?.Id ?? 0, CreatedDate = DateTimeOffset.UtcNow }); if (!categoryResult.Succeeded) { return(result.Failed(result.Errors.ToArray())); } return(result.Success()); }