parameter is always NULL in delete-method, dont know why - telerik-grid

i'm using telerik mvc 3.
i've got a Grid which is bound to a ViewModel.
#(Html.Telerik().Grid<SampleProject.ViewModels.Location.RoomViewModel>()
.Name("Grid")
.ToolBar(cmd => cmd.Insert())
.DataKeys(keys => keys.Add(c => c.RoomId))
.DataBinding(dataBinding => dataBinding
.Ajax()
.Select("Selecting", "Location")
.Insert("Inserting", "Location")
.Update("Updating", "Location")
.Delete("Deleting", "Location" )
)
.Columns(c =>
{
c.Bound(o => o.RoomName);
c.Bound(o => o.MaxSeats);
c.Bound(o => o.HasScanner);
c.Bound(o => o.HasPrinter);
c.Bound(o => o.HasFlipchart);
c.Bound(o => o.HasBeamer);
c.Command(cmd =>
{
cmd.Edit();
cmd.Delete();
});
})
)
the "Inserting"-method works fine (i get RoomViewModel as Parameter). The "Selecting"-Method works too, but the "Deleting"-Method doesnt work.
#region GridActions
[GridAction]
public ActionResult Selecting()
{
return View(new GridModel(this._currentLocation.Rooms));
}
[AcceptVerbs(HttpVerbs.Post)]
[GridAction]
public ActionResult Inserting(RoomViewModel rvm)
{
this._currentLocation.Rooms.Add(rvm);
return View(new GridModel(this._currentLocation.Rooms));
}
[AcceptVerbs(HttpVerbs.Post)]
[GridAction]
public ActionResult Deleting(RoomViewModel rvm)
{
this._currentLocation.Rooms.Remove(rvm);
return View(new GridModel(this._currentLocation.Rooms));
}
i tried also:
public ActionResult Deleting(int rvm) --> internal error 500 - doesnt hit the breakpoint
public ActionResult Deleting(string rvm)
public ActionResult Deleting(object rvm)
always "NULL", any idea???

Actually Deleting action method expects entity Identity as a parameter:
public ActionResult _DeleteAjaxEditing(int id)

Related

Cannot create a DbSet for 'OpenIddictApplication' because this type is not included in the model for the context

I am trying to customize the OpenIddictApplication table and i am succeeded about that.
My problem is that when i try to generate token i got the following error "Cannot create a DbSet for 'OpenIddictApplication' because this type is not included in the model for the context".
Here is my service configuration:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddXmlSerializerFormatters();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddDbContext<ApiHubContext>(options =>
{
options.UseMySql(Configuration.GetConnectionString("DefaultConnection"));
options.UseOpenIddict<ApplicationClient, ApplicationAuthorization, ApplicationScope, ApplicationToken, long>();
});
services.AddOpenIddict()
.AddCore(options =>
{
options.UseEntityFrameworkCore().UseDbContext<ApiHubContext>();
})
.AddServer(options =>
{
options.UseMvc();
options.EnableTokenEndpoint("/connect/token");
options.AllowClientCredentialsFlow().AllowRefreshTokenFlow();
options.SetAccessTokenLifetime(TimeSpan.FromMinutes(10));
options.SetRefreshTokenLifetime(TimeSpan.FromMinutes(4));
options.AcceptAnonymousClients();
})
.AddValidation();
services.AddAuthentication(options =>
{
options.DefaultScheme = OpenIddictValidationDefaults.AuthenticationScheme;
});
}
My Custom DbContext:
public class ApiHubContext : DbContext
{
public ApiHubContext(DbContextOptions options)
: base(options) { }
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
//builder.UseOpenIddict();
builder.UseOpenIddict<ApplicationClient, ApplicationAuthorization, ApplicationScope, ApplicationToken, long>();
}
}
public class ApplicationClient : OpenIddictApplication<long, ApplicationAuthorization, ApplicationToken>
{
public bool IsActive { get; set; }
public string Remarks { get; set; }
}
public class ApplicationAuthorization : OpenIddictAuthorization<long, ApplicationClient, ApplicationToken> { }
public class ApplicationScope : OpenIddictScope<long> { }
public class ApplicationToken : OpenIddictToken<long, ApplicationClient, ApplicationAuthorization> { }
I have already checked this link.
Is there anything i have missed ?
You simply forgot to configure the OpenIddict EF Core stores to use your custom entities:
services.AddOpenIddict()
.AddCore(options =>
{
options.UseEntityFrameworkCore()
.UseDbContext<ApiHubContext>()
.ReplaceDefaultEntities<ApplicationClient, ApplicationAuthorization, ApplicationScope, ApplicationToken, long>();
});

AutoMapper -- One-to-many mapping of tree

I have the following classes:
public class OneToManySource {
public OneToManySource SourceChild { get;set; } // will sometimes be null
public int Value { get; set; }
}
public interface IDestination
{
}
public class ChildlessDestination: IDestination
{
public int DestValue { get; set; }
}
public class ChildedDestination: IDestination
{
public int DestValue { get; set; }
public IDestination DestinationChild { get; set; } // Never null. If it would be null, use a ChildlessDestination instead.
}
I want to map these back and forth in the sensible way. If a source has a child, it goes to a ChildedDestination. Otherwise, it goes to a ChildlessDestination.
I have the following, which works, but it's ugly. I'm wondering if it can be cleaned up. In particular, the "ConstructUsing" gets the job done, but it also seems to be (understandably) opaque to AutoMapper's internal smarts. So ReverseMap() there doesn't work. Instead of that, we are stuck with two other ReverseMap() calls, and also the last CreateMap().
For example, would I be better off starting with the reverse map?
public MapperConfigurationExpression Configure(MapperConfigurationExpression expression) {
expression.CreateMap<OneToManySource, ChildedDestination>()
.ForMember(d => d.DestValue, cfg => cfg.MapFrom(s => s.Value))
.ForMember(d => d.DestinationChild, opt => opt.MapFrom(s => s.SourceChild))
.ReverseMap();
expression.CreateMap<OneToManySource, ChildlessDestination>()
.ForMember(d => d.DestValue, cfg => cfg.MapFrom(s => s.Value))
.ReverseMap();
expression.CreateMap<OneToManySource, IDestination>()
.ConstructUsing((source, context) =>
{
if (source.SourceChild == null) {
return context.Mapper.Map<ChildlessDestination>(source);
}
return context.Mapper.Map<ChildedDestination>(source);
});
expression.CreateMap<IDestination, OneToManySource>()
.ConstructUsing((source, context) =>
{
return context.Mapper.Map<OneToManySource>(source);
});
return expression;
}

Saving data on postback in Orchard

I'm an Orchard newbie and I'm having difficulty trying to get the form data when a new item is created.
What I have is a module that creates a menu item on the admin dashboard. That menu item will load a page where a user can enter a new "Coach".
There are 3 things needed for a coach, first name, last name and email.
Here's the code I have implemented for this...
migrations.cs
public class SDSDataMigration : DataMigrationImpl
{
public int Create()
{
SchemaBuilder..CreateTable("CoachPartRecord", table => table.ContentPartRecord()
.Column("FirstName", DbType.AnsiString, c => c.WithLength(50))
.Column("LastName", DbType.AnsiString, c => c.WithLength(50))
.Column("Email", DbType.AnsiString, c => c.WithLength(200)))
ContentDefinitionManager.AlterPartDefinition("CoachPart", part => part
.WithField("FirstName", f => f.OfType("TextField"))
.WithField("LastName", f => f.OfType("TextField"))
.WithField("Email", f => f.OfType("TextField"))
);
ContentDefinitionManager.AlterTypeDefinition("Coach", type => type.WithPart("CommonPart")
.WithPart("CoachPart"));
return 1;
}
}
parts/records
public class CoachPartRecord : ContentPartRecord
{
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
public virtual string Email { get; set; }
}
public class CoachPart : ContentPart<CoachPartRecord>
{
public string FirstName
{
get { return Record.FirstName; }
set { Record.FirstName = value; }
}
public string LastName
{
get { return Record.LastName; }
set { Record.LastName = value; }
}
public string Email
{
get { return Record.Email; }
set { Record.Email = value; }
}
}
view for creating editor
#{ Layout.Title = T("Add Coach").ToString(); }
#using (Html.BeginFormAntiForgeryPost()) {
// Model is a Shape, calling Display() so that it is rendered using the most specific template for its Shape type
#Display(Model)
}
handler
public class CoachPartHandler : ContentHandler
{
public CoachPartHandler(IRepository<CoachPartRecord> repository)
{
Filters.Add(StorageFilter.For(repository));
}
}
driver
protected override DriverResult Editor(CoachPart part, IUpdateModel updater, dynamic shapeHelper)
{
updater.TryUpdateModel(part, Prefix, null, null);
return Editor(part, shapeHelper);
}
controller (for dashboard menu item)
public ActionResult Create()
{
var coach = _services.ContentManager.New("Coach");
var model = _services.ContentManager.BuildEditor(coach);
return View(model);
}
[HttpPost, ActionName("Create")]
public ActionResult CreatePOST()
{
var contentItem = _services.ContentManager.New("Coach");
_services.ContentManager.Publish(contentItem);
return View("Index");
}
Right now I can get the form to appear to create a new coach. When I hit "Publish" all of the fields (i.e. FirstName, LastName, Email) for the CoachPart parameter in the driver are null.
I can look at the http request and I can see the values I put on the form, but they're not making it to the CoachPart.
Any ideas why the CoachPart fields aren't getting filed in?
Thanks!
First of all, you are defining the properties on your own record. Therefore you don't need new textfields attached to your part, so you should remove this:
ContentDefinitionManager.AlterPartDefinition("CoachPart", part => part
.WithField("FirstName", f => f.OfType("TextField"))
.WithField("LastName", f => f.OfType("TextField"))
.WithField("Email", f => f.OfType("TextField")));
Secondly, because you use your custom controller istead of orchard's content controller, you must implement the IUpdateModel and act on it:
[Admin]
public class MyController : Controller, IUpdateModel {
private readonly IContentManager _contentManager;
private readonly ITransactionManager _transactionManager;
public MyController(IContentManager contentManager,
ITransactionManager transactionManager) {
_contentManager = contentManager;
_transactionManager = transactionManager;
}
[HttpPost, ActionName("Create")]
public ActionResult CreatePOST()
{
var contentItem = _contentManager.New<CoachPart>("Coach");
// The implementation of IUpdateModel is necessary for this next line:
var model = _contentManager.UpdateEditor(contentItem, this);
if (!ModelState.IsValid) {
_transactionManager.Cancel();
return View(model);
}
_contentManager.Publish(contentItem);
return View("Index");
}
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
}
void IUpdateModel.AddModelError(string key, LocalizedString errorMessage) {
ModelState.AddModelError(key, errorMessage.ToString());
}
}

Orchard CMS: ContentPart not added to ContentItem in migration

I am trying to build a module with the following in a migration:
public class XyzzyPartRecord : ContentPartRecord
{
public virtual string Plugh { get; set; }
}
public class XyzzyPart : ContentPart<XyzzyPartRecord>
{
public string Plugh {
get { return Retrieve( r => r.Plugh ); }
set { Store( r => r.Plugh, value ); }
}
}
public int Create() {
SchemaBuilder.CreateTable( "XyzzyPartRecord", table => table
.ContentPartRecord()
.Column<string>( "Plugh" )
);
ContentDefinitionManager.AlterPartDefinition( "XyzzyPart", cfg => cfg
.WithDescription( "XyzzyPart" ) );
ContentDefinitionManager.AlterTypeDefinition( "XyzzyItem", cfg => cfg
.WithPart( "XyzzyPart" )
);
return 1;
}
When accessing an XyzzyItem, there is no XyzzyPart in the Parts collection. Instead there is a ContentPart.
How do I get my Content Part to allow it to be added to a Content Item's Parts collection?
I had neglected to create either a Driver or a Handler for my part. Once those were in place my code worked as expected.
namespace MyProject.Drivers {
public class XyzzyPartDriver : ContentPartDriver<XyzzyPart> {
protected override DriverResult Display( XyzzyPart part, string displayType, dynamic shapeHelper ) {
return ContentShape( "Parts_Xyzzy",
() => shapeHelper.Parts_Xyzzy(
Xyzzy: part ) );
}
}
}
namespace MyProject.Handlers {
public class XyzzyPartHandler : ContentHandler {
public XyzzyPartHandler( IRepository<XyzzyPartRecord> repository ) {
Filters.Add( StorageFilter.For( repository ) );
}
}
}

Add field to Site Settings in Orchard CMS

this question is similar to this one but it targets Orchard CMS 1.8, where Site Settings were redesigned.
I've implemented HomeSettingsPart to store my custom settings for Home page.
public class HomeSettingsPart : ContentPart {
public int NewsCount {
get { return this.Retrieve(x => x.NewsCount); }
set { this.Store(x => x.NewsCount, value); }
}
public int MaterialsCount {
get { return this.Retrieve(x => x.MaterialsCount); }
set { this.Store(x => x.MaterialsCount, value); }
}
public string WelcomeText {
get { return this.Retrieve(x => x.WelcomeText); }
set { this.Store(x => x.WelcomeText, value); }
}
}
Also I've added a handler for this part:
public class HomeSettingsHandler : ContentHandler {
public HomeSettingsHandler() {
T = NullLocalizer.Instance;
Filters.Add(new ActivatingFilter<HomeSettingsPart>("Site"));
Filters.Add(new TemplateFilterForPart<HomeSettingsPart>("HomeSettings", "Parts.HomeSettings", "HomePage"));
}
public Localizer T { get; set; }
protected override void GetItemMetadata(GetContentItemMetadataContext context) {
if (context.ContentItem.ContentType != "Site")
return;
base.GetItemMetadata(context);
context.Metadata.EditorGroupInfo.Add(new GroupInfo(T("HomePage")));
}
}
Everything is like in this tutorial and this code works fine.
Now I want to add an MediaLibraryPickerField to this content part. I've added this field in migrations as usual and I see it in AdminUI ContentManagement/Parts section.
ContentDefinitionManager.AlterPartDefinition("HomeSettingsPart", x => x
.WithField("HomeSlider", y => y
.OfType("MediaLibraryPickerField")
.WithDisplayName("...")
.WithSetting("MediaLibraryPickerFieldSettings.Multiple", "true")
)
);
But, when I open my Settings/HomeSettings I see only 3 editors for my HomeSettingsPart and nothing is rendered for picker field.
So, how do I add this field correctly?
thanks.
You can also see this page in the documentation site : http://docs.orchardproject.net/Documentation/Adding-custom-settings

Resources