﻿<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Intersoft Community - ClientUI - Duplicate function for MVVM data application </title><link>http://www.intersoftsolutions.com/Community/ClientUI/Duplicate-function-for-MVVM-data-application/</link><description /><generator>http://www.intersoftsolutions.com</generator><language>en</language><copyright>Copyright 2002 - 2015 Intersoft Solutions Corp. All rights reserved.</copyright><ttl>60</ttl><item><title>Duplicate function for MVVM data application </title><link>http://www.intersoftsolutions.com/Community/ClientUI/Duplicate-function-for-MVVM-data-application/</link><pubDate>Mon, 17 Oct 2011 10:22:43 GMT</pubDate><dc:creator>mg@hsig.ch</dc:creator><category>MVVM</category><category>command</category><category>generic</category><description>&lt;p&gt;Hi Yudi&lt;/p&gt;
&lt;p&gt;Thanks for very helpful sample! For all with the same problem. I've implemented it like this:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Changes in EditableGridViewModelGenericBase.cs&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;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;
}&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Changes in *ViewModel.cs&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;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 &amp;#43; " - Copy";
    duplicatePerson.Vorname = currentPerson.Vorname;
    base.ExecuteDuplicateRow(duplicatePerson);
}&lt;/pre&gt;

&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;Michael&lt;/p&gt;</description></item><item><title>Duplicate function for MVVM data application </title><link>http://www.intersoftsolutions.com/Community/ClientUI/Duplicate-function-for-MVVM-data-application/</link><pubDate>Sun, 16 Oct 2011 20:40:33 GMT</pubDate><dc:creator>yudi</dc:creator><category>MVVM</category><category>command</category><category>generic</category><description>&lt;p&gt;&lt;span style="font-family: 'segoe ui', 'sans-serif'; color: #1f497d; font-size: 9pt"&gt;I’m currently still investigating this issue and need more time to provide you with solution, suggestion, or sample.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui', 'sans-serif'; color: #1f497d; font-size: 9pt"&gt;I’ll get back to you as soon as possible.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui', 'sans-serif'; color: #1f497d; font-size: 9pt"&gt;Edited: adding reply information&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui', 'sans-serif'; color: #1f497d; font-size: 9pt"&gt;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.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui', 'sans-serif'; color: #1f497d; font-size: 9pt"&gt;The snippet code below shows how add the new command in ProductsViewModel class.&lt;/span&gt;&lt;/p&gt;&lt;pre&gt;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);
}&lt;/pre&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui', 'sans-serif'; color: #1f497d; font-size: 9pt"&gt;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)&lt;/span&gt;&lt;/p&gt;&lt;pre&gt;internal override void ExecuteUpdateRow(object parameter)
{   
    Product oldValue = parameter as Product;
    Product prod = new Product();
    prod.ProductID = 0;
    ...
}&lt;/pre&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui', 'sans-serif'; color: #1f497d; font-size: 9pt"&gt;The same approach also shows how to get the “Product” object.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui', 'sans-serif'; color: #1f497d; font-size: 9pt"&gt;Hope this helps.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>Duplicate function for MVVM data application </title><link>http://www.intersoftsolutions.com/Community/ClientUI/Duplicate-function-for-MVVM-data-application/</link><pubDate>Thu, 13 Oct 2011 16:24:16 GMT</pubDate><dc:creator>mg@hsig.ch</dc:creator><category>MVVM</category><category>command</category><category>generic</category><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I use the ClientUI MVVM data application (WCF RIA SP1) Template.&lt;br /&gt;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.&lt;/p&gt;
&lt;p&gt;I have now created a new command (DuplicateRowCommand) in the class EditableGridViewModelBase. I've bound the command to a UXButton.&lt;/p&gt;&lt;span style="font-family: consolas"&gt;&lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt; EditableGridViewModelBase() : &lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;base&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;() &lt;p&gt;{&lt;/p&gt;&lt;/span&gt;&lt;span style="font-family: consolas; color: #008000"&gt;&lt;span style="font-family: consolas; color: #008000"&gt;// Batch update is not supported in WCF RIA Services. &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;&lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;this&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;.IsBatchUpdate = &lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;false&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;; &lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;this&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;.AutoEditOperation = &lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;false&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;; &lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;...&lt;/span&gt;&lt;/span&gt; &lt;span style="font-family: consolas"&gt;&lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;this&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;.ValidateRowCommand = &lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt; &lt;/span&gt;&lt;span style="font-family: consolas; color: #2b91af"&gt;&lt;span style="font-family: consolas; color: #2b91af"&gt;DelegateCommand&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;(ExecuteValidateRow); &lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;this&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;.DuplicateRowCommand = &lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt; &lt;/span&gt;&lt;span style="font-family: consolas; color: #2b91af"&gt;&lt;span style="font-family: consolas; color: #2b91af"&gt;DelegateCommand&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;(ExecuteDuplicateRow); &lt;p&gt;}&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;&lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;private&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt; &lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt; ExecuteDuplicateRow(&lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;object&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt; parameter) &lt;p&gt;{&lt;/p&gt;&lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;this&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;.EditableProductsSource.Insert(&lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;this&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;.SelectedItem); &lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;if&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt; (!&lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;this&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;.IsBatchUpdate) &lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;this&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;.SaveChanges(); &lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;else &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;&lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;this&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;.HasChanges = &lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;true&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;; &lt;p&gt;}&lt;/p&gt;&lt;/span&gt;
&lt;p&gt;How / where do I change the primary key? I have problems, because it is a generic class. Should I override ExecuteDuplicateRow in each ViewModel?&lt;br /&gt;How do to I best this?&lt;/p&gt;
&lt;div lang="undefined" _msthash="826319"&gt; &lt;/div&gt;
&lt;div lang="undefined" _msthash="826319"&gt;&lt;strong&gt;A simpler sample is to initialize default values:&lt;/strong&gt;&lt;/div&gt;
&lt;div lang="undefined" _msthash="826319"&gt;How can I add default values? How do I get the "product" object?&lt;/div&gt;
&lt;div lang="undefined" _msthash="826319"&gt;((parameter.GetType())(parameter).ProductName = "New Product" does not work...&lt;/div&gt;
&lt;div lang="undefined" _msthash="826319"&gt; &lt;/div&gt;&lt;span style="font-family: consolas"&gt;&lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;private&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt; &lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt; ExecutePrepareNewRow(&lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;object&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt; parameter) &lt;p&gt;{&lt;/p&gt;&lt;p&gt;&lt;span style="font-family: consolas; color: #008000"&gt;&lt;span style="font-family: consolas; color: #008000"&gt;// It's possible to initialize the new row with default values &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/span&gt;
&lt;p&gt;&lt;span style="font-family: consolas; color: #008000"&gt;&lt;span style="font-family: consolas; color: #008000"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;&lt;/span&gt;&lt;span style="font-family: consolas; color: #008000"&gt;&lt;span style="font-family: consolas; color: #008000"&gt;// Example: &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: consolas; color: #008000"&gt;&lt;span style="font-family: consolas; color: #008000"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;&lt;/span&gt;&lt;span style="font-family: consolas; color: #008000"&gt;&lt;span style="font-family: consolas; color: #008000"&gt;// product.ProductName = "New Product"; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: consolas; color: #008000"&gt;&lt;span style="font-family: consolas; color: #008000"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;&lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;this&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;.NewItem = &lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;this&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;.EditableProductsSource.Create() &lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;as&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt; T;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: consolas"&gt;&lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;this&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;.EditableProductsSource.Insert(&lt;/span&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;&lt;span style="font-family: consolas; color: #0000ff"&gt;this&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: consolas"&gt;.NewItem); 
&lt;p&gt;}&lt;/p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Thanks for help!&lt;/p&gt;
&lt;p&gt;Michael&lt;/p&gt;</description></item></channel></rss>