breeze js به همراه ایجاد سایت آگهی قسمت دوم
نویسنده: حسین حقیقیان
تاریخ: ۱۳۹۵/۰۲/۲۵ ۱۹:۵۰
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
Install-Package Breeze.WebApi2.EF6
var instance = breeze.config.initializeAdapterInstance("ajax", "angular");
instance.setHttp($http); Install-Package Breeze.Angular
var manager = new breeze.EntityManager({
dataService: dataService,
metadataStore: metadataStore,
saveOptions: new breeze.SaveOptions({ allowConcurrentSaves: true, tag: [{}] })
}); var dataService = new breeze.DataService({
serviceName: "/breeze/"+ "Automobile",
hasServerMetadata: false,
namingConvention: breeze.NamingConvention.camelCase
});
var metadataStore = new breeze.MetadataStore({}); var myMetadataStore = new breeze.MetadataStore();
myMetadataStore.addEntityType({...}); var customer = function () {
this.City = "";
};
myMetadataStore.registerEntityTypeCtor("Customer", customer); [BreezeController]
public class AutomobileController : ApiController
{
readonly EFContextProvider<ApplicationDbContext> _contextProvider =
new EFContextProvider<ApplicationDbContext>();
[HttpGet]
public string Metadata()
{
return _contextProvider.Metadata();
}
[HttpGet]
public IQueryable<Customer> Customers() {
return _contextProvider.Context.Customers;
}
[System.Web.Http.HttpPost]
public SaveResult SaveChanges(JObject saveBundle)
{
_contextProvider.BeforeSaveEntitiesDelegate = BeforeSaveEntities;
_contextProvider.AfterSaveEntitiesDelegate = afterSaveEntities;
return _contextProvider.SaveChanges(saveBundle);
}
protected Dictionary<Type, List<EntityInfo>> BeforeSaveEntities(Dictionary<Type, List<EntityInfo>> saveMap)
{
}
private void afterSaveEntities(Dictionary<Type, List<EntityInfo>> saveMap, List<KeyMapping> keyMappings)
{
}
} manger.saveChanges().then(function success() {
}, function failer(e) {
}); manger.rejectChanges()
var query = breeze.EntityQuery
.from("Customer")
.orderBy("Id");
var result= manager.executeQuery(query);
result.then(querySucceeded)
.fail(queryFailed);
query = query.where("Id", "==", 1) var predicate = new breeze.Predicate("Id", "==", false);
query = query.where(predicate)
var p1 = new breeze.Predicate("IsArchived", "==", false);
var p2 = breeze.Predicate("IsDone", "==", false);
var predicate = p1.and(p2);
query = query.where(predicate).orderBy("Id") ?$filter=IsArchived eq false&IsDone eq false &$orderby=Id
breeze.Validator.required({ allowEmptyStrings: true }); manager.createEntity('Customer', jsonValue); manager.createEntity("Customer", jsonValue, breeze.EntityState.Modified, breeze.MergeStrategy.OverwriteChanges) manager.createEntity("Customer", item, breeze.EntityState.Deleted) Install-Package angularjs Install-Package angularjs.TypeScript.DefinitelyTyped Install-Package bootstrap Install-Package bootstrap.TypeScript.DefinitelyTyped Install-Package jQuery Install-Package jquery.TypeScript.DefinitelyTyped Install-Package RequireJS Install-Package requirejs.TypeScript.DefinitelyTyped bower install angularAMD
public class BaseEntity
{
public int Id { get; set; }
public bool Status { get; set; }
public DateTime CreatedDateTime { get; set; }
} public class Ad : BaseEntity
{
public string Title { get; set; }
public float Price { get; set; }
public double Rating { get; set; }
public int? RatingNumber { get; set; }
public string UserId { get; set; }
public DateTime ModifieDateTime { get; set; }
public string Description { get; set; }
public virtual ICollection<Comment> Comments { get; set; }
public virtual IdentityUser User { get; set; }
public virtual ICollection<AdLabel> Labels { get; set; }
public virtual ICollection<AdMedia> Medias { get; set; }
} public class Label
{
public int Id { get; set; }
public string Title { get; set; }
public int? ParentId { get; set; }
public virtual Label Parent { get; set; }
public virtual ICollection<Label> Items { get; set; }
} public class Media
{
public int Id { get; set; }
public string Name { get; set; }
public string MimeType { get; set; }
} public class AdLabel
{
public int Id { get; set; }
public virtual Ad Ad { get; set; }
public virtual Label Label { get; set; }
[Index("IX_AdLabel", 1, IsUnique = true)]
public int AdId { get; set; }
[Index("IX_AdLabel", 2, IsUnique = true)]
public int LabelId { get; set; }
public string Value { get; set; }
} public class AdMedia
{
public int Id { get; set; }
public virtual Ad Ad { get; set; }
public virtual Media Media { get; set; }
[Index("IX_AdMedia", 1, IsUnique = true)]
public int AdId { get; set; }
[Index("IX_AdMedia", 2, IsUnique = true)]
public int MediaId { get; set; }
} public class Comment : BaseEntity
{
public string Body { get; set; }
public double Rating { get; set; }
public int? RatingNumber { get; set; }
public string EntityName { get; set; }
public string UserId { get; set; }
public int? ParentId { get; set; }
public int? AdId { get; set; }
public virtual Comment Parent { get; set; }
public virtual Ad Ad { get; set; }
public virtual ICollection<Comment> Items { get; set; }
public virtual IdentityUser User { get; set; }
} public class Customer:BaseEntity
{
public string UserId { get; set; }
public virtual string DisplayName { get; set; }
public virtual string BirthDay { get; set; }
public string City { get; set; }
public string Address { get; set; }
public int? MediaId { get; set; }
public bool? NewsLetterSubscription { get; set; }
public string PhoneNumber { get; set; }
public virtual IdentityUser User { get; set; }
public virtual Media Media { get; set; }
} public class Rating
{
public int Id { get; set; }
public string UserId { get; set; }
public Double Rate { get; set; }
public string EntityName { get; set; }
public int DestinationId { get; set; }
} public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public DbSet<Ad> Ads { get; set; }
public DbSet<AdLabel> AdLabels { get; set; }
public DbSet<AdMedia> AdMedias { get; set; }
public DbSet<Comment> Comments { get; set; }
public DbSet<Label> Labels { get; set; }
public DbSet<Media> Medias { get; set; }
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
} <script src="~/Scripts/require.js" data-main="/app/main"></script>
requirejs.config({
paths: {
"app": "app",
"angularAmd":"/Scripts/angularAmd",
"angular": "/Scripts/angular",
"bootstrap": "/Scripts/bootstrap",
"angularRoute": "/Scripts/angular-route",
"jquery": "/Scripts/jquery-2.2.2",
},
waitSeconds: 0,
shim: {
"angular": { exports: "angular" },
"angularRoute": { deps: ["angular"] },
"bootstrap": { deps: ["jquery"] },
"app": {
deps: ["bootstrap","angularRoute"]
}
}
});
require(["app"]); <body ng-controller="SecurityCtrl"> ... </body>
"use strict";
module AdApps {
class SecurityCtrl {
private $scope: Interfaces.IAdvertismentScope;
constructor($scope: Interfaces.IAdvertismentScope) {
// security check
this.$scope = $scope;
}
}
define(["angularAmd", "angular"], (angularAmd, ng) => {
angularAmd = angularAmd.__proto__;
var app = ng.module("AngularTypeScript", ['ngRoute']);
var viewPath = "app/views/";
var controllerPath = "app/controller/";
app.config(['$routeProvider', $routeProvider => {
$routeProvider
.when("/", angularAmd.route({
templateUrl: viewPath + "home.html",
controllerUrl: controllerPath + "home .js"
}))
.otherwise({ redirectTo: '/' });
}
]);
app.controller('SecurityCtrl', ['$scope', SecurityCtrl]);
return angularAmd.bootstrap(app);
})}