Reputation: 3256
I have two tables students and activities. Each student have to have 10 activites, can be different ones. What will be the best way to create a CRUD for this scenario?
Currently i am doing this:
using System;
using System.Collections.Generic;
namespace StudentActivity.Models
{
public class Student
{
public int StudentID { get; set; }
public string LastName { get; set; }
public string FirstMidName { get; set; }
public string ActivityId{ get; set; }
public virtual ICollection<Activity> Activity { get; set; }
}
}
creating CRUD controller for above scenario. But this makes its very difficult to manage. As i have to create 10 activities seperatly for each student. Is there a better way to do this? Such that i see one student and 10 activity textboxes under it to fill at once. Rather then filling them one by one.
Upvotes: 1
Views: 322
Reputation: 669
You're definitely mixing two different things together here. The business entity should be designed to represent business logic in a way that makes sense regardless of any UI.
As a good practice, when you design your business layer, you should assume that it need to be used with different kinds of UI with minimal or no changes.
Now looking at your business case here, you have a parent class (Student), and a child class (Activity). Each student need to have many activities. So your design here is correct. How to render this in the UI should have absolutely no influence on this design.
The view is the entity responsible for displaying the information and accepting input from the user. Given this Student class with the collection of activities, I don't see why you can't display it so that all the activities can be entered at once. What have you tried so far?
Upvotes: 1