本文整理汇总了C#中Framework.ExecuteCommand方法的典型用法代码示例。如果您正苦于以下问题:C# Framework.ExecuteCommand方法的具体用法?C# Framework.ExecuteCommand怎么用?C# Framework.ExecuteCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Framework
的用法示例。
在下文中一共展示了Framework.ExecuteCommand方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ListsModule
public ListsModule(Framework framework, IDocumentStore documentStore, CreateListCommand createListCommand)
: base("/lists")
{
_createListCommand = createListCommand;
_documentStore = documentStore;
_framework = framework;
Put["/upload-list"] = api =>
{
var model = this.Bind<ServiceEndpoints.Lists.UploadContacts>();
var file = Request.Files.FirstOrDefault();
if (file == null)
throw new ArgumentNullException("no files was provided");
var path = Guid.NewGuid().ToString();
using (var diskFile = File.OpenWrite(path))
{
file.Value.CopyTo(diskFile);
}
var importContactsFromCsvTask = new ImportContactsFromCsvTask
{
File = path,
ListId = model.ListId
};
_framework.ExecuteTask(importContactsFromCsvTask);
return importContactsFromCsvTask.Id;
};
Get["/"] = api =>
{
using (var session = _documentStore.OpenSession())
{
return Response.AsJson(session.Query<ListDescriptor>().ToList());
}
};
Get["/stats"] = api =>
{
using (var session = _documentStore.OpenSession())
{
var lists = session.Query<ListDescriptor>().ToList();
var listStats = lists.Select(listDescriptor => new
{
TotalContacts = session.Query<Contact>().Count(x => x.MemberOf.Any(p => p == listDescriptor.Id)),
listDescriptor.Id,
listDescriptor.Name
}).ToList();
return Response.AsJson(listStats);
}
};
Post["/"] = api =>
{
var model = this.Bind<ServiceEndpoints.Lists.CreateList>();
_createListCommand.Name = model.Name;
var listId = _framework.ExecuteCommand(_createListCommand);
return Response.AsJson(new ApiStringResult { Result = listId });
};
}