locked
Supplier Model Help - gridview, need supplier details and supplier products RRS feed

  • Question

  • User-570626059 posted

    Hi guys, I have my main supplier model and the default identity user model. However my requirements are below and I dont know the best way to get there.

    Do I need to create new models and link them together? Do I need to create a user model or am I still ok using the default model so login is already set up?

    So it should be like this:

    Main dashboard grid showing all suppliers > add/edit/delete supplier

    Main dashboard grid showing all suppliers > click view products > show all products for this supplier in grid > add/edit/delete product for this supplier

    Main dashboard grid showing all suppliers > click view details> form/grid showing details address etc > edit details

    Main dashboard grid showing all suppliers > click view users> grid showing all users for this supplier > add/edit/delete user (currently I have altered the aspnetuser table to contain supplierid so I can link users to a supplier and also login).

    thanks

    Current supplier model:

     public partial class supplier 
            {
    
    
                public int supplierid { get; set; }
    
                [Required]
                [StringLength(50)]
                public string suppliername { get; set; }
    
                [StringLength(50)]
                public string address1 { get; set; }
    
                [StringLength(50)]
                public string county { get; set; }
    
                [StringLength(50)]
                public string country { get; set; }
    
                [StringLength(50)]
                public string telephone { get; set; }
    
                [StringLength(50)]
                public string address2 { get; set; }
    
                [StringLength(11)]
                public string postcode { get; set; }
    
                [StringLength(20)]
                public string webstatus { get; set; }
    
               
                public status status { get; set; }
    
                [StringLength(50)]
                public string LastreviewedBy { get; set; }
    
                [Column(TypeName = "datetime2")]
                public DateTime Whencompliant { get; set; }
                [Column(TypeName = "datetime2")]
                public DateTime Reviewdate { get; set; }
    
    
    
            }
    
        public enum status
        {
            
        
            InProgress,
           Started,
            NotStarted,
    
    
        }

    Main grid / dashboard - currently only the important fields showing, I want to then be able to edit supplierdetails and supplierproducts:

           <asp:GridView ID="GridView1" runat="server" CssClass="col-md-8 table table-bordered table-hover table-responsive" SelectMethod="GridView1_GetData" DeleteMethod="GridView1_DeleteItem" UpdateMethod="GridView1_UpdateItem"
                        DataKeyNames="supplierid" GridLines="Horizontal" ItemType="PrincePortalWeb.Models.supplier" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" SelectedRowStyle-BackColor="#ddf7ff">
                        <Columns>
                            <asp:CommandField ButtonType="Image" ShowSelectButton="true" SelectImageUrl="~/Content/Images/select.png" ItemStyle-HorizontalAlign="Center" />
                            <asp:DynamicField DataField="suppliername" HeaderText="Supplier Name" />
                            <asp:DynamicField DataField="status" HeaderText="Status" />
                            <asp:DynamicField DataField="whencompliant" HeaderText="When Compliant" DataFormatString="{0:MM/dd/yyyy}" ApplyFormatInEditMode="false" />
                            <asp:DynamicField DataField="reviewdate" HeaderText="Review Date" DataFormatString="{0:MM/dd/yyyy}" />
                            <asp:DynamicField DataField="lastreviewedby" HeaderText="Reviewed By" />
                            <asp:DynamicField DataField="webstatus" ReadOnly="true" HeaderText="Portal Status" />
    
                            <asp:TemplateField ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:ImageButton ImageUrl="~/Content/Images/producticon.png" CommandName="ViewProducts" ImageAlign="Middle" ToolTip="View Supplier Products" runat="server" />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField FooterStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:ImageButton ImageUrl="~/Content/Images/detailicon.png" ImageAlign="Middle" CommandName="ViewDetails" ToolTip="View Supplier Details" runat="server" />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:CommandField ButtonType="Image" ItemStyle-HorizontalAlign="Center" ShowDeleteButton="true" DeleteImageUrl="~/Content/Images/deleteicon.png" CancelImageUrl="~/Content/Images/cancelicon.png" EditImageUrl="~/Content/Images/editicon.png" ShowEditButton="True" UpdateImageUrl="~/Content/Images/tickicon.png" />
    
                        </Columns>
                    </asp:GridView>

    Tuesday, July 10, 2018 2:22 PM

All replies

  • User1724605321 posted

    Hi skyblue ,

    Do I need to create new models and link them together? Do I need to create a user model or am I still ok using the default model so login is already set up?

    You can still use the default user table created by asp.net identity , you can add custom property to user which named "supplierid" in your scenario , then you will get the relationship between your supplier and the users . Extend the properties of User.Identity with  additional properties is not difficult  , check out below blog:

     ASP.NET Identity 2.0: Customizing Users and Roles

    It has  step-by-step info on the whole process(the Extending Identity User – The Easy Part section ). See this code sample also if you want to get new properties from User.Identity after adding the new properties. 

    Best Regards,

    Nan Yu

    Wednesday, July 11, 2018 6:08 AM
  • User-570626059 posted
    Yep I've already done this. However how do I now click on my suppliers grid and show all the users for that supplier.

    Do I need to add a link in the supplier model at all?
    Wednesday, July 11, 2018 6:44 AM
  • User1724605321 posted

    Hi skyblue ,

    That depends on your design . When you want to  all the users for that supplier , you can use supplier id to query the database since you already have supplier id property in your user table :

    https://stackoverflow.com/a/1175662/5751404 

    Or you can add a list<user> property in your supplier model and fill the list in controller .

    Best Regards,

    Nan Yu

    Wednesday, July 11, 2018 7:15 AM
  • User-570626059 posted
    Ok thanks. So how do I pass the supplier Id and populate the users grid using model binding?
    Wednesday, July 11, 2018 7:21 AM
  • User1724605321 posted

    Hi skyblue28,

     When click the edit link (you can put supplier Id as querystring) pass the id to code behind :

    https://weblogs.asp.net/gurusarkar/pass-querystring-parameter-with-navigaterurl-in-hyperlink-inside-a-gridview 

    Since you already have the supplier id in user table. directly search the database and find out the users whose supplier Id is the edit one .

    At last , loop the query result , bind another gridview or some other view plugin with the list<YourUserEntity> as datasource .

    Best Regards,

    Nan Yu

    Thursday, July 12, 2018 8:22 AM