<%@ Page Title="Manage Favorites with Profile" Language="C#" AutoEventWireup="true" CodeFile="ManageFavoritesWithProfile.aspx.cs" Inherits="ManageFavoritesWithProfile" 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">
    <DeleteParameters>
      <asp:Parameter Name="Id" Type="Int32" />
      <asp:ProfileParameter Name="UserName" PropertyName="UserName" Type="String" />
    </DeleteParameters>
    <InsertParameters>
      <asp:Parameter Name="Link" Type="String" />
      <asp:ProfileParameter Name="UserName" PropertyName="UserName" Type="String" />
    </InsertParameters>
    <SelectParameters>
      <asp:ProfileParameter Name="UserName" PropertyName="UserName" Type="String" />
    </SelectParameters>
    <UpdateParameters>
      <asp:Parameter Name="Link" Type="String" />
      <asp:ProfileParameter Name="UserName" PropertyName="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>
