count.Result
равносильноcount = db.Image.CountAsync().Result
Task.WaitAll(count, notReady);
Вы запустили задачи параллельно, но результат из них так не получите.public class RazorTemplateGenerator
{
public void SetupReportTemplating(string baseDirectory = null)
{
var cfg = new TemplateServiceConfiguration
{
Debug = true
};
Engine.Razor = RazorEngineService.Create(cfg);
var folder = Path.Combine(baseDirectory ?? System.AppDomain.CurrentDomain.BaseDirectory, "Pages","PageTemplates");
var templates = Directory.GetFiles(folder, "*.cshtml");
foreach (var fName in templates)
{
var info = new FileInfo(fName);
var tName = Path.GetFileNameWithoutExtension(info.Name);
var template = File.ReadAllText(fName);
var src = new LoadedTemplateSource(template, fName.Replace(@"\bin",String.Empty));
Engine.Razor.AddTemplate(tName, src);
}
}
public void CheckCompile(string name)
{
Engine.Razor.Compile(name);
}
public string RenderPage(string viewName, object model)
{
return Engine.Razor.RunCompile(viewName, model.GetType(), model);
}
}
$.ajax({
type: "POST",
url: window.baseUrl + "Controller/Action",
data: params,
success: function (result) {
if (result) {
$(".modal").html(result);
}
})
public ActionResult Action(IncomingParameters params)
{
var model = Anything(params);
return PartialView("Action", model);
}
var timeout = 600;
var optionsBuilder = new DbContextOptionsBuilder<InstituteContext>()
.UseSqlServer(new SqlConnection(connectionString), opt =>
{
opt.CommandTimeout(timeout);
});
using (var context = new InstituteContext (optionsBuilder.Options))
{
// your code
}
var orders = db.Orders
.Where(x => x.Kod == kod)
.GroupBy(x => x.Nomenklatura)
.ToDictionary(x => x.FirstOrDefault().Nomenklatura, x => x.ToList() )
orders["anyNomenklatura"]
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthorization(x =>
{
x.AddPolicy("RoleStartWith", policy => {
policy.RequireRole(roles.Where(r => r.StartsWith("ad")));
});
});
}
[Authorize(Policy = "RoleStartWith")]
public IActionResult Index()
{
return View();
}
public class CustomAutorizeAttribute : AuthorizeAttribute
{
private string _prefix;
private string[] _roles;
public CustomAutorizeAttribute(string prefix)
{
_prefix = prefix;
_roles = base.Roles.Split(',').Select(x => x.Trim()).ToArray();
}
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
return _roles.Where(x => x.StartsWith(_prefix)).Any(x => httpContext.User.IsInRole(x));
}
}
[CustomAutorize(prefix = "ad")]
public IActionResult Index()
{
return View();
}
<connectionStrings>
<add name="DB1Connection" connectionString="data source=(local);initial catalog=myDB1;" />
<add name="DB2Connection1" connectionString="data source=(local);initial catalog=myDB2;" />
<add name="DB3Connection1" connectionString="data source=(local);initial catalog=myDB3;" />
</connectionStrings>
connectionStringName = "DB3Connection1";
public class MyDbContext : DbContext
{
public MyDbContext(string connectionStringName) : base(connectionStringName)
{ }
}
@model Dictionary<string, string> AdditionalFields
<script>
var additionalFields = [];
@foreach(var field in AdditionalFields)
{
@:additionalFields.push({ '@field.Key', '@field.Value' })
}
</script>