开发者

Should I have a new controller or same controller to implement this?

For example, I have an advertiser controller, now, I开发者_Go百科 need the advertiser have the advertisement. So, my question is, where do I put this? Should I have a new advertisement controller or do it in the advertiser controller? Please suggest. Thanks.


Well, I think it really depends on how your users will interact with the site and what an advertisement means in the overall domain.

Just based on what you've said, I would probably create an AdvertisementController that has a Create method. I'm assuming you'll know the user/advertiser id based on authentication, so you can have an empty Create method signature for the GET (to display the form) and a Create method signature that takes an Advertisement object for the POST. I don't know the language that you're working with and/or the MVC framework you're using, but hopefully this helps.

public AdvertisementController : Controller {

  //http://server/ad/create (with optional querystring params??)
  [HttpGet]
  public ActionResult Create(){
    //get your model or modelview
    return View(model);  //return View for your Create Advertisement view
  }

  //http://server/ad/create (with post request body)
  [HttpPost]
  public ActionResult Create(Advertisment ad){
    //send your ad to the repository

    //redirect to some read page, or list, or something else
    return Redirect("Home", "Index");
  }
}

So I hope this helps, or at least gives you some thoughts around how to design this. I'd go for the separate controller. Organizationally, at a minimum, it will keep your logic around Advertisements pretty well contained (instead of a potentially bloated Advertiser controller).

Good luck!


To me this is a conceptual question.

If advertisements were conceptually and logically "owned" by an advertiser - that would be your answer (use the Advertiser Controller); on the other-hand, if advertisements are a stand-alone concept in their own right (and don't depend exclusively on advertisers) then that would drive your answer (give them their own one).

The way to test this is to look at the different scenarios your likely to have to implement (as per the 4+1 architectural view model) and let those help drive out the answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜