<%@ Page Title="Manage Favorites with the User Property" Language="C#" AutoEventWireup="true" CodeFile="ManageFavoritesWithUserProperty.aspx.cs" Inherits="ManageFavoritesWithUserProperty" MasterPageFile="~/Site.Master" %>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
  <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE FROM [Favorites] WHERE [Id] = @Id AND [UserName] = @UserName" InsertCommand="INSERT INTO [Favorites] ([Link], [UserName]) VALUES (@Link, @UserName)" SelectCommand="SELECT Id, Link, UserName FROM [Favorites] WHERE ([UserName] = @UserName)" UpdateCommand="UPDATE [Favorites] SET [Link] = @Link, [UserName] = @UserName WHERE [Id] = @Id AND Username = @UserName" OnDeleting="SqlDataSource1_Deleting" OnInserting="SqlDataSource1_Inserting" OnSelecting="SqlDataSource1_Selecting" OnUpdating="SqlDataSource1_Updating">
    <DeleteParameters>
      <asp:Parameter Name="Id" Type="Int32" />
      <asp:Parameter Name="UserName" Type="String" />
    </DeleteParameters>
    <InsertParameters>
      <asp:Parameter Name="Link" Type="String" />
      <asp:Parameter Name="UserName" Type="String" />
    </InsertParameters>
    <SelectParameters>
      <asp:Parameter Name="UserName" Type="String" />
    </SelectParameters>
    <UpdateParameters>
      <asp:Parameter Name="Link" Type="String" />
      <asp:Parameter Name="UserName" Type="String" />
      <asp:Parameter Name="Id" Type="Int32" />
    </UpdateParameters>
  </asp:SqlDataSource>

  <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" DataKeyNames="Id, UserName">
    <Columns>
      <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
      <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
      <asp:BoundField DataField="Link" HeaderText="Link" SortExpression="Link" />
      <asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" ReadOnly="True" />
    </Columns>
  </asp:GridView>

  <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="Id" DataSourceID="SqlDataSource1" DefaultMode="Insert" Height="50px" Width="125px">
    <Fields>
      <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" InsertVisible="False" />
      <asp:BoundField DataField="Link" HeaderText="Link" SortExpression="Link" />
      <asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" InsertVisible="False" />
      <asp:CommandField ShowInsertButton="True" />
    </Fields>
  </asp:DetailsView>
</asp:Content>
