iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
Hi
I use the ClientUI MVVM data application (WCF RIA SP1) Template.I would like to integrate a duplicating function. That is, that I would like to copy the selected row and insert it as a duplicate. All column values should be copied except the primary key (GUID). This is to be regenerated by the application.
I have now created a new command (DuplicateRowCommand) in the class EditableGridViewModelBase. I've bound the command to a UXButton.
{
}
How / where do I change the primary key? I have problems, because it is a generic class. Should I override ExecuteDuplicateRow in each ViewModel?How do to I best this?
// It's possible to initialize the new row with default values
// Example:
// product.ProductName = "New Product";
this.NewItem = this.EditableProductsSource.Create() as T;
this.EditableProductsSource.Insert(this.NewItem); }
Thanks for help!
Michael
I’m currently still investigating this issue and need more time to provide you with solution, suggestion, or sample.
I’ll get back to you as soon as possible.
Edited: adding reply information
It is suggested to create the new command in the view model class rather than create it in the ViewModelBase, in this case is in the EditableGridViewModelBase.
The snippet code below shows how add the new command in ProductsViewModel class.
internal override void ExecuteUpdateRow(object parameter) { Product oldValue = parameter as Product; Product prod = new Product(); prod.ProductID = 0; prod.ProductName = oldValue.ProductName; prod.Category = oldValue.Category; prod.UnitPrice = oldValue.UnitPrice; prod.UnitsInStock = oldValue.UnitsInStock; prod.UnitsOnOrder = oldValue.UnitsOnOrder; prod.QuantityPerUnit = oldValue.QuantityPerUnit; prod.Discontinued = oldValue.Discontinued; ExecuteInsertRow(prod); base.ExecuteUpdateRow(parameter); }
In order to set/change the primary key, you can try to set it to 0 value (using technique that mimic when user add new row)
internal override void ExecuteUpdateRow(object parameter) { Product oldValue = parameter as Product; Product prod = new Product(); prod.ProductID = 0; ... }
The same approach also shows how to get the “Product” object.
Hope this helps.
Hi Yudi
Thanks for very helpful sample! For all with the same problem. I've implemented it like this:
Changes in EditableGridViewModelGenericBase.cs
public EditableGridViewModelBase() : base() { // Batch update is not supported in WCF RIA Services. this.IsBatchUpdate = false; this.AutoEditOperation = false; this.DeleteRowCommand = new DelegateCommand(ExecuteDeleteRow); ... this.DuplicateRowCommand = new DelegateCommand(ExecuteDuplicateRow); } public DelegateCommand DuplicateRowCommand { get; set; } protected virtual void ExecuteDuplicateRow(object parameter) { this.EditableProductsSource.Insert(parameter as T); if (!this.IsBatchUpdate) this.SaveChanges(); else this.HasChanges = true; }
Changes in *ViewModel.cs
protected override void ExecuteDuplicateRow(object parameter) { Person currentPerson = parameter as Person; Person duplicatePerson = new Person(); duplicatePerson.ID = System.Guid.Empty; //.NewGuid(); duplicatePerson.Name = currentPerson.Name + " - Copy"; duplicatePerson.Vorname = currentPerson.Vorname; base.ExecuteDuplicateRow(duplicatePerson); }
Regards
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname