현재 인턴쉽 중이며 MVC에서 컨트롤러를 학습 한 내용은 트래픽에만 사용되어야하며 트래픽에 대해서만 사용해야합니다. 나는 또한 "서비스 계층 (service layer)"이라고 불리는 것에 대해서도 들었는데, 나는 컨트롤러 용 데이터/비즈니스 로직을 수행해야만하는 곳과 같다고 들었다."서비스 레이어"이해 및 사용 - .NET MVC 5
나는 이것에 대한 예제와 튜토리얼을 찾고 있었지만, 한 달 전에 MVC를 배웠을 뿐이었다. 어떤 사람이 다음의 ActionResult Index
비즈니스 로직을 "서비스 계층"으로 전송하는 방법을 설명하고 보여줄 수 있는지 궁금합니다.
public class LakerLegendsController : Controller
{
string pathway1 = HostingEnvironment.MapPath(@"~/App_Data/Announcement1.txt");
string pathway2 = HostingEnvironment.MapPath(@"~/App_Data/Announcement2.txt");
string pathway3 = HostingEnvironment.MapPath(@"~/App_Data/Announcement3.txt");
private MoviesEntities db = new MoviesEntities();
public ActionResult Index()
{
// Setting some ViewBag texts from announcement files.
string text1 = System.IO.File.ReadAllText(pathway1);
ViewBag.TextHTML1 = text1;
string text2 = System.IO.File.ReadAllText(pathway2);
ViewBag.TextHTML2 = text2;
string text3 = System.IO.File.ReadAllText(pathway3);
ViewBag.TextHTML3 = text3;
// Following pulls some XML information
XDocument xmlFile = XDocument.Load(@"http://na.leagueoflegends.com/en/rss.xml");
var LoLtitles = from service in xmlFile.Descendants("item")
select (string)service.Element("title");
var LoLlinks = from service in xmlFile.Descendants("item")
select (string)service.Element("link");
var LoLdescriptions = from service in xmlFile.Descendants("item")
select (string)service.Element("description");
var LoLDates = from service in xmlFile.Descendants("item")
select (string)service.Element("pubDate");
var servicing = LoLdescriptions.ToArray();
for (int i = 0; i < 4; i++)
{
servicing[i] = Regex.Replace(Server.HtmlDecode(servicing[i]), @"<[^>]*>", String.Empty);
}
ViewBag.titles = LoLtitles.ToArray();
ViewBag.links = LoLlinks.ToArray();
ViewBag.descriptions = servicing;
ViewBag.dates = LoLDates.ToArray();
// Pulls the DB Table
var users = db.Users.Include(u => u.championList).Include(u => u.championList1).Include(u => u.championList2).Include(u => u.eloList).Include(u => u.rankList).Include(u => u.roleList).Include(u => u.roleList1);
return View(users.ToList());
}
}
이 코드가 수행하는 모든 작업은 XML 파일을 가져 와서 일부 정보를 구문 분석하는 몇 가지 추가 논리와 함께 DB 테이블을 반환하는 것입니다.
이 특정 예제를 서비스 계층 (또는 논리에 사용해야하는 것은 무엇이든)으로 변환하는 방법을 궁금합니다. MVC를 처음 접했을 때 가능한 한 간단하게 만들어보십시오.