मैं अब कुछ महीनों के लिए मेरी पहली बड़ी (मेरे लिए) MVC परियोजना का विकास किया गया है और चीजों को नेविगेट करने के लिए बेहद मुश्किल हो रही है किया जा रहा से नियंत्रक रखने के रूप में।नेट MVC सर्वश्रेष्ठ अभ्यास बहुत अपठनीय
मैं रिफैक्टरिंग पर बंद slacking किया गया है और के आधुनिक उदाहरण की मांग कर रहा हूँ 'सर्वोत्तम प्रथाएं' जहाँ तक अपने नियंत्रक पतली रखने और अपने मॉडल के लिए कि डेटा के सभी जाने के रूप में।
मैं this article कि विस्तार से बातें की चर्चा है, लेकिन एक उदाहरण परियोजना प्रदान नहीं करता है पढ़ें।
अधिकांश 'सर्वोत्तम प्रथाएं' धागे यहां पोस्ट MVC संगीत स्टोर या बेवकूफ डिनर परियोजना से जोड़ने के लिए जाते हैं, लेकिन एक ही समय में टिप्पणियां कहने के लिए वे और अधिक 'शुरुआत की गाइड' के बजाय 'सर्वोत्तम प्रथाओं के उदाहरण हैं करते हैं। '
किसी को भी किसी भी अप-टू-डेट खुला स्रोत MVC परियोजनाओं है कि समुचित विकास संरचना प्रदर्शित की पता है?
ध्यान दें: एक ठेठ समस्या यह है कि मैं हल करने में जानना चाहते हैं: मेरी नियंत्रकों बहुत लंबा और कोड से भरा है कि वेबसाइट ड्राइव कर रहे हैं - मैं इस कोड तरीकों कि केवल नियंत्रक द्वारा संदर्भित कर रहे हैं में बंद बढ़ने की जरूरत है । मैं इन सभी तरीकों को कहां फेंक दूं?
यहाँ एक एक नियंत्रक से मेरे कोड का एक नमूना के रूप में प्राप्त उत्तरों में से एक पर एक टिप्पणी ने सुझाव दिया है। मैं इस जानकारी में से कुछ को अपने व्यूमोडेल पर कैसे ले जाऊं? (मैं नीचे ViewModel को शामिल किया है):
नियंत्रक:
public ActionResult AttendanceView(int id)
{
//
// Generates list of Attendances specifically for current Course
var attendanceItems = db.Attendance.Where(s => s.CourseID == id);
List<Attendance> attendanceItemsList = attendanceItems.ToList();
// End of generating list of Attendances
//
// Generates list of Students in alphabetical order sorted by LastName
var student = attendanceItemsList.Select(a => a.Student).Distinct().OrderBy(s => s.LastName);
List<Student> StudentList = student.ToList();
// End of generating list of Students
//
// Generates list of AttendingDays specifically for current Course
Course course = db.Courses.FirstOrDefault(p => p.CourseID == id);
List<int> attDayList = new List<int>();
for (int i = 0; i < course.AttendingDays; i++)
{
attDayList.Add(i + 1);
};
// End of generating list of AttendingDays
AttendanceReportViewModel model = new AttendanceReportViewModel
{
AttendanceDays = attDayList,
Students = StudentList,
Attendances = attendanceItemsList,
courseId = id
};
return View(model);
}
ViewModel:
namespace MyApp.ViewModels
{
public class AttendanceReportViewModel
{
public List<int> AttendanceDays { get; set; }
public List<Student> Students { get; set; }
public List<Attendance> Attendances { get; set; }
public int courseId { get; set; }
public string IsPresent(Student student, int attendanceDay)
{
return Attendances.Single(a => a.StudentID == student.StudentID && a.AttendanceDay == attendanceDay).Present ? MyAppResource.Present_Text : MyAppResource.Absent_Text;
}
}
}
मैं कोड की जांच कर रहा हूं और मुझे कई गलतियां मिलीं। उदाहरण के लिए क्लास हैंडलर। गेटफिल्प्स फॉरवहिकल, पहले इसकी ओवरकिल (कक्षा को क्रिया के रूप में परिभाषित करना) और दूसरा एकमात्र फ़ंक्शन जो क्लास में कुछ उपयोगी करता है, एक आईनेमरेबल देता है, जहां स्पष्ट रूप से फ़ंक्शन का कोड केवल एक सूची देता है, इसलिए इसकी एक अस्पष्टता को मजबूर करना जहां वहां नहीं है। – magallanes