我正在创建一个演示项目,其中包含使用存储库模式和依赖注入的crud操作.
这是我的结构:
方法1(非常受欢迎,许多开发人员使用)
我的存储库界面:
public partial interface IRepository<T>
{
void Insert(T entity);
}
Run Code Online (Sandbox Code Playgroud)
我的服务层:
public partial interface IEmployeeService
{
void InsertCategory(EmployeeMaster employeeMaster);
}
Run Code Online (Sandbox Code Playgroud)
我的类将实现该接口(服务):
public partial class EmployeeService : IEmployeeService
{
private readonly IRepository<EmployeeMaster> _employeeMasterRepository;
public EmployeeService(IRepository<EmployeeMaster> employeeMasterRepository)
{
this._employeeMasterRepository = employeeMasterRepository;
}
public virtual void InsertCategory(EmployeeMaster employeeMaster)
{
_employeeMasterRepository.Insert(employeeMaster);
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
public class HomeController : Controller
{
private readonly IEmployeeService _employeeService;
public HomeController(IEmployeeService employeeService)
{
this._employeeService = employeeService;
}
Run Code Online (Sandbox Code Playgroud)
以上是我从Nop Commerce项目(http://www.nopcommerce.com)关注的结构,我认为现在大多数开发人员现在只关注这种结构,即存储库模式和依赖注入.
以前我做的就像在我的应用程序中制作一个Bal(业务访问层)项目,然后在Bal中制作类文件并执行如下插入:
方法2:
public class …Run Code Online (Sandbox Code Playgroud) c# asp.net-mvc entity-framework repository-pattern nopcommerce
function friendControllerTest($scope, $http) {
$scope.loading = true;
$scope.addMode = false;
$scope.countryList = [];
$scope.stateList = [];
function getAllCountry() {
$http({
method: 'Get',
url: '/Home/GetCountry'
}).success(function (data) {
$scope.countryList = data;
}).error(function () {
$scope.errorMessage = 'Not found';
});
}
function getStatebyCountryId(Id) {
$scope.stateList = null;
if (Id) { // Check here country Id is null or not
$http({
method: 'POST',
url: '/Home/GetStateByCountryId/',
data: JSON.stringify({ CountryId:Id })
}).success(function (data) {
$scope.stateList = data;
}).error(function (data) {
alert(data.message);
$scope.message = 'not found'; …Run Code Online (Sandbox Code Playgroud)我想在我的存储过程中执行排序和过滤.
我为Holiday表创建表:
CREATE TABLE [dbo].[Holiday](
[HolidaysId] [int] IDENTITY(1,1) NOT NULL,
[HolidayDate] [date] NULL,
[HolidayDiscription] [nvarchar](500) NULL,
[Name] [nvarchar](max) NULL,
CONSTRAINT [PK_Holiday] PRIMARY KEY CLUSTERED
(
[HolidaysId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
Run Code Online (Sandbox Code Playgroud)
我的过滤标准如下:
注意:请在过滤器比较中忽略HolidayId.
我的表:假日
HolidaysId int,Name nvarchar(500),HolidayDate date.
Run Code Online (Sandbox Code Playgroud)
样本输入:
HolidayId Name Date
1 abc 1/1/2015
2 pqr 1/2/2015
3 xyz 1/3/2015
Run Code Online (Sandbox Code Playgroud)
输出:
Case 1:Starts with(This is just for name column …Run Code Online (Sandbox Code Playgroud) 我在azure云存储上使用我的数据库和其他存储.我正在使用实体代码首次使用但问题是当我尝试使用CloudConfigurationManager.GetSetting()从云存储中读取连接字符串时,我收到以下错误:
错误:参数'nameOrConnectionString'不能为null,为空或仅包含空格.EntityFramework.dll中出现"System.ArgumentException"类型的异常,但未在用户代码中处理
这是我的Azure项目:Demo.Web.Azure
它有2个配置文件:
1)ServiceConfiguration.Cloud.cscfg:
<Role name="Demo.Web">
<Setting name="MyConnectionString"
value="Server=----;Database=DemoEntity;User ID=---;Password=---&w;Trusted_Connection=False;
Encrypt=True;MultipleActiveResultSets=True;" />
<Setting name="Demo.Storage"
value="DefaultEndpointsProtocol=https;AccountName=---;AccountKey=------"
/>
Run Code Online (Sandbox Code Playgroud)
2)ServiceConfiguration.Local.cscfg:
<Role name="Demo.Worker">
<Setting name="Demo.Storage"
value="DefaultEndpointsProtocol=https;AccountName=---;AccountKey=------"
/>
Run Code Online (Sandbox Code Playgroud)
3)ServiceDefinition.csdef中:
<ServiceDefinition name="Demo.Web.Azure" schemaVersion="2014-06.2.4">
<WebRole name="RepuGuard.Web" vmsize="Small">
<ConfigurationSettings>
<Setting name="MyConnectionString" />
<Setting name="Demo.Storage" />
</ConfigurationSettings>
</WebRole>
<WorkerRole name="Demo.Worker" vmsize="Small">
<ConfigurationSettings>
<Setting name="MyConnectionString" />
<Setting name="Demo.Storage" />
</ConfigurationSettings>
</WorkerRole>
</ServiceDefinition>
Run Code Online (Sandbox Code Playgroud)
这是我的Context文件,它读取数据库连接字符串:
public partial class MyDemoDBContext : DbContext, IDisposable
{
public ObjectContext Context { get; set; }
public MyDemoDBContext()
: base(CloudConfigurationManager.GetSetting("MyConnectionString"))//Getting Error here
{
Context = …Run Code Online (Sandbox Code Playgroud) asp.net-mvc entity-framework azure azure-configuration azure-sql-database
这是我在页面加载状态和城市下拉列表上加载的方式:
我的控制器方法:
这是第一个在加载页面时调用的方法.
public ActionResult Index()
{
var states = GetStates();
var cities = Enumerable.Empty<SelectListItem>();
ViewBag.States = states;
ViewBag.Cities = cities;
}
private IEnumerable<SelectListItem> GetStates()
{
using (var db = new DataEntities())
{
return db.States.Select(d => new SelectListItem { Text = d.StateName, Value =d.Id.ToString() });
}
}
[HttpGet]
public ActionResult GetCities(int id)
{
using (var db = new DataEntities())
{
var data = db.Cities.Where(d=>d.StateId==id).Select(d => new { Text = d.CityName, Value = d.Id }).ToList();
return Json(data, JsonRequestBehavior.AllowGet);
}
} …Run Code Online (Sandbox Code Playgroud) 以下是我的页面:

现在,当我点击Capture1.png时,我想首先在新标签上显示该图像,而不会弹出如上图所示.
当我点击sample.pdf时,我想首先在新标签上显示pdf.
这是我的HTML:
<div ng-controller="MyController">
<a target="_blank" href="/Account/FetchFile/{{File_Id}}" ng-click="OpenFile(File_Id)" style="line-height:20px">Capture1.png</a>
<a target="_blank" href="/Account/FetchFile/{{File_Id}}" ng-click="OpenFile(File_Id)" style="line-height:20px">sample.pdf</a>
</div>
Run Code Online (Sandbox Code Playgroud)
我的控制器:
var app = angular.module('MyController', ['ur.file', 'ngResource']);
app.controller('MyController', function ($scope, $resource, $http,$window) {
var url = "http://localhost:47000/Account/FetchFile/" + fileId;
$window.open(url, '_blank');
}
Run Code Online (Sandbox Code Playgroud)
服务器端:
public FileContentResult FetchFile(int id)
{
byte[] fileContent = null;
string fileType = "";
string fileName = "";
var file = GetFileByID(id);
if (file != null)
{
fileContent = file.Data;
fileType = file.ContentType;
fileName = file.FileName;
return File(fileContent, fileType, fileName);
} …Run Code Online (Sandbox Code Playgroud) 我正在将我的图像转换为二进制数据并以二进制格式存储:
byte[] bytes = System.IO.File.ReadAllBytes(@"F:\Image\Img1.jpg");
Run Code Online (Sandbox Code Playgroud)
我存储图像的数据库字段是:Varbinary(Max)
现在我正从我的数据库中读取这个二进制数据,我正在获取二进制数据.
我想在此Div标签中显示图像.
这是我的观点:
<div class="Image-ad"></div>
Run Code Online (Sandbox Code Playgroud)
我的课:
public class ImageAdd
{
public Guid ImageAddId { get; set; }
public byte[] Image { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的控制器:
public ActionResult Index()
{
var data=db.ImageAdd.ToList();
return View(db);
}
Run Code Online (Sandbox Code Playgroud)
如何将此二进制数据转换为图像并在Div标签中显示???
asp.net-mvc ×5
c# ×3
angularjs ×2
azure ×1
blob ×1
image ×1
javascript ×1
nopcommerce ×1
select ×1
sql ×1
sql-server ×1