module-zero-core-template | NET Core MVC / Angular Startup Project | Model View Controller library
kandi X-RAY | module-zero-core-template Summary
Support
Quality
Security
License
Reuse
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample Here
module-zero-core-template Key Features
module-zero-core-template Examples and Code Snippets
Trending Discussions on module-zero-core-template
Trending Discussions on module-zero-core-template
QUESTION
Using the module-zero-core-template (fully updated), I recently had problems when a user asked for account deletion (it was the first time), a lot of places in my code were getting the "User" entity using Repository.Get(TPrimaryKey id) or Repository.GetAsync(TPrimaryKey id):
var user = _userRepository.Get(model.UserId);
Until now I didn't realize it was throwing an exception when the entity doesn't exists, but I had to replace all the calls by (or the equivalent async):
var user = _userRepository.FirstOrDefault(u => u.Id == model.UserId);
My code wasn't made to handle such exception, but only a null value in return.
My questions are:
- Why an exception instead of a null value returned?
- Is there a way to modify this behavior?
Thanx in advance.
ANSWER
Answered 2019-May-09 at 12:46This is because the implementation is doing it like that.
If you want to find an entity without the exception being thrown, you have to use the FirstOrDefault(TPrimaryKey id)
function.
Edit(explanation):
Is like saying Single(x => x.Id == 1)
. You are expecting a result, if it doesn't have that, it will throw an exception. That's why we have SingleOrDefault(expr)
and SingleOrDefault(expr)
or FirstOrDefault(expr)
and First(expr)
. Same principal involved
QUESTION
I am trying to remove all build warnings in the .net core template. I have reduced it to one:
- Code: CS0108
- Description: 'Views_Shared__Layout.SettingManager' hides inherited member 'AbpRazorPage.SettingManager'. Use the new keyword if hiding was intended.
- Project: AbpCompanyName.AbpProjectName.Web.Mvc
- File: module-zero-core-template\aspnet-core\src\AbpCompanyName.AbpProjectName.Web.Mvc\obj\Debug\netcoreapp2.2\Razor\Views\Shared_Layout.g.cshtml.cs
- Line: 1869
I am trying to find a way to eliminate or suppress this warning in the smallest possible scope.
ANSWER
Answered 2019-May-01 at 07:14you can remove the setting manager in the layout.cshtml directly.
Remove unnecessary setting manager injection since it has been injected in AbpRazorPage
See the changes in https://github.com/aspnetboilerplate/module-zero-core-template/pull/450
QUESTION
I use the free multi-page template for ASP.NET Core v4.0.0, which is based on the ASP.NET Boilerplate v3.8.1. The template already implements AppSettingProvider, in which you can add the necessary settings for the application or user scope like so on. The problem is that I need to use a very large number of settings, which makes sense to group. To do this, the SettingDefinition class has the SettingDefinitionGroup group property. But how to use it? The official documentation says that this serves just for use in the UI, but does not give an example of its use.
For example, there is such a structure of settings:
namespace ProjectName.Configuration {
public static class AppSettingNames {
public const string UiTheme = "App.UiTheme";
public static class BaseData {
public static class Company {
public const string Name = "BaseData.Company.Name";
// ...
public static class PostAddress {
public const string Country = "BaseData.Company.PostAddress.Country";
// ...
}
}
public static class UI {
public static class Footer {
public const bool IsVisible = "BaseData.UI.Footer.IsVisible";
// ...
}
public static class Widget {
public static class Weather {
public const bool IsVisible = "BaseData.UI.Widget.IsVisible";
// ...
}
}
}
}
}
}
How, in this case, to specify it in the SettingProvider
and use setting groups in UI?
namespace ProjectName.Configuration {
public class AppSettingProvider : SettingProvider {
public override IEnumerable GetSettingDefinitions(SettingDefinitionProviderContext context) {
return new[]
{
new SettingDefinition(AppSettingNames.UiTheme,
"red",
scopes: SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User,
isVisibleToClients: true
),
/* BaseData */
new SettingDefinition(AppSettingNames.BaseData.Company.Name,
"default value",
displayName: "setting name",
description: "setting description",
scopes: SettingScopes.Application | SettingScopes.Tenant,
isVisibleToClients: true,
group: ?,
clientVisibilityProvider: new RequiresAuthenticationSettingClientVisibilityProvider()
)
};
}
}
}
ANSWER
Answered 2018-Aug-19 at 16:38It is not currently being used, so there is a little work to do to actually use it.
Configuration:
public class AppSettingProvider : SettingProvider
{
// Hold groups
public static List Groups = new List();
public override IEnumerable GetSettingDefinitions(SettingDefinitionProviderContext context)
{
// Create groups
var group1 = new SettingDefinitionGroup("group1", new LocalizableString("group1_displayName", "sourceName"));
var group2 = new SettingDefinitionGroup("group2", new LocalizableString("group2_displayName", "sourceName"));
// Add groups
Groups.Add(group1);
Groups.Add(group2);
// Configure hierarchy
group1.AddChild(group2);
return new[]
{
new SettingDefinition(AppSettingNames.UiTheme,
"red",
scopes: SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User,
isVisibleToClients: true
),
// Grouped
new SettingDefinition("setting1_name",
"setting1_defaultValue",
group: group1
),
new SettingDefinition("setting2_name",
"setting2_defaultValue",
group: group2
)
};
}
}
UI model:
public class SettingGroup
{
public List Children { get; set; }
public string Name { get; set; }
public List Settings { get; set; }
}
Helpers:
private async Task GetSettingGroup(string name)
{
var groupList = AppSettingProvider.Groups.Where(g => g.Name == name).ToList();
var settingDefinitions = _settingDefinitionManager.GetAllSettingDefinitions();
var settings = await SettingManager.GetAllSettingValuesAsync();
return GetSettingGroupsRecursively(groupList, settingDefinitions, settings).FirstOrDefault();
}
private List GetSettingGroupsRecursively(IReadOnlyList groups, IReadOnlyList settingDefinitions, IReadOnlyList settings)
{
return groups
.Select(group => new SettingGroup
{
Children = GetSettingGroupsRecursively(group.Children, settingDefinitions, settings),
Name = group.Name,
Settings = GetGroupSettings(group, settingDefinitions, settings)
})
.ToList();
}
private List GetGroupSettings(SettingDefinitionGroup group, IReadOnlyList settingDefinitions, IReadOnlyList settings)
{
return settingDefinitions
.Where(sd => sd.Group?.Name == group?.Name)
.Select(sd => settings.Where(s => s.Name == sd.Name).FirstOrDefault())
.Where(s => s != null)
.ToList();
}
Usage:
var group1SettingGroup = await GetSettingGroup("group1");
var group1Settings = group1SettingGroup.Settings;
// Check hierarchy
// var group2SettingGroup = group1SettingGroup.Children.First();
// var group2Settings = group2SettingGroup.Settings;
QUESTION
I have the same problem as this: https://forum.aspnetboilerplate.com/viewtopic.php?f=5&t=4865, but I have ABP v2.1 with module-zero-core-template.
I'm using Web.Mvc project as my startup project and I want to make API calls.
When I perform an unauthorized request to the API, I got a "200 OK" response instead of a "401". Where did I make a mistake?
ANSWER
Answered 2018-Jan-27 at 20:09This authorization doc will give you each and every detail.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install module-zero-core-template
Support
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesExplore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits
Save this library and start creating your kit
Share this Page