public NamedEntityModule(IRetrieveEntitiesByType entityRetriever) { Get["/NamedEntities/{type}/{filter}"] = parameters => { var typeName = parameters.type.ToString(); var type = Type.GetType(typeName); var valueEntities = entityRetriever.GetNamedEntities(type, parameters.filter); var dto = Mapper.Map<IEnumerable<NamedEntity>, IEnumerable<NamedEntityDto>>(valueEntities); return Negotiate .WithView("Index") .WithModel(new LookupViewModel(type)) .WithMediaRangeModel(MediaRange.FromString("application/json"), new { dto }); }; Get["/NamedEntities/{industryIds}/{type}/{filter}"] = parameters => { var typeName = parameters.type.ToString(); var type = Type.GetType(typeName); var industryString = (string)parameters.industryIds.Value; var industryIds = industryString.Split(',').Select(x => new Guid(x)).ToArray(); var valueEntities = entityRetriever.GetIndustryEntities(type, parameters.filter, industryIds); var dto = Mapper.Map<IEnumerable<NamedEntity>, IEnumerable<NamedEntityDto>>(valueEntities); return Negotiate .WithView("Index") .WithModel(new LookupViewModel(type)) .WithMediaRangeModel(MediaRange.FromString("application/json"), new { dto }); }; }
private static void AddLookupData(IPipelines pipelines, IRetrieveEntitiesByType entityRetriever) { pipelines.AddLookupDataToViewBag<CommercialState>(entityRetriever); pipelines.AddLookupDataToViewBag<ContractType>(entityRetriever); pipelines.AddLookupDataToViewBag<Country>(entityRetriever); pipelines.AddLookupDataToViewBag<Province>(entityRetriever); pipelines.AddLookupDataToViewBag<Role>(entityRetriever); }
public ValueEntityModule(IBus bus, IRetrieveEntitiesByType entityRetriever, IValueEntityRepository<ValueEntity> entities) { this.RequiresAnyClaim(new[] { RoleType.Admin.ToString(), RoleType.ProductManager.ToString() }); Get["/ValueEntities/{type}"] = parameters => { var model = this.Bind<DataTablesViewModel>(); var typeName = parameters.type.ToString(); var type = Type.GetType(typeName); var valueEntities = entityRetriever.GetValueEntities(type);//, Context.Request.Query["search[value]"].Value, //model.Start, model.Length); //var dto = (DataTablesViewModel)Mapper.Map<PagedList<ValueEntity>, DataTablesViewModel>(valueEntities, model); return Negotiate .WithView("Index") .WithModel(new LookupViewModel(type)) //.WithMediaRangeModel(MediaRange.FromString("application/json"), dto); .WithMediaRangeModel(MediaRange.FromString("application/json"), new {data = valueEntities}); }; Get["/ValueEntities/Add/{type}"] = parameters => { return View["Save", new ValueEntityDto { AssemblyQualifiedName = parameters.type.ToString() }]; }; Post["/ValueEntities"] = _ => { var dto = this.Bind<ValueEntityDto>(); dto.CreatedBy = Context.CurrentUser.UserName; if (ModelValidationResult.IsValid) { var entity = (ValueEntity) Mapper.Map(dto, null, typeof (ValueEntityDto), Type.GetType(dto.AssemblyQualifiedName)); bus.Publish(new CreateUpdateEntity(entity, "Read")); } return Response.AsJson(dto.AssemblyQualifiedName); }; Get["/ValueEntities/{id:guid}"] = parameters => { var id = (Guid)parameters.id; var valueEntity = entities.First(x => x.Id == id); var dto = Mapper.Map(valueEntity, new ValueEntityDto(), valueEntity.GetType(), typeof(ValueEntityDto)); //todo: repo.Get() not loading entity return View["Save", dto]; }; Get["/ValueEntities/Lookup/{id:guid}"] = parameters => { var id = (Guid)parameters.id; var valueEntity = entities.First(x => x.Id == id); var dto = Mapper.Map(valueEntity, new ValueEntityDto(), valueEntity.GetType(), typeof(ValueEntityDto)); //todo: repo.Get() not loading entity return Response.AsJson(new {data = dto}); }; Put["/ValueEntities/{id}"] = parameters => { var dto = this.Bind<ValueEntityDto>(); dto.ModifiedBy = Context.CurrentUser.UserName; if (ModelValidationResult.IsValid) { var valueEntity = entities.First(x => x.Id == dto.Id); var entity = (ValueEntity) Mapper.Map(dto, valueEntity, typeof (ValueEntityDto), valueEntity.GetType()); bus.Publish(new CreateUpdateEntity(entity, "Create")); } return Response.AsJson(dto.AssemblyQualifiedName); }; Get["/ValueEntities/{type}/{filter}"] = parameters => { var typeName = parameters.type.ToString(); var type = Type.GetType(typeName); var valueEntities = entityRetriever.GetValueEntities(type, parameters.filter); var dto = Mapper.Map<IEnumerable<ValueEntity>, IEnumerable<ValueEntityDto>>(valueEntities); return Negotiate .WithView("Index") .WithModel(new LookupViewModel(type)) .WithMediaRangeModel(MediaRange.FromString("application/json"), new { dto }); }; Delete["/ValueEntities/{id}"] = _ => { var dto = this.Bind<ValueEntityDto>(); var valueEntity = entities.First(x => x.Id == dto.Id); bus.Publish(new DeleteLookupEntity(valueEntity)); return Response.AsJson("TEST"); }; }