Advertisement
Guest User

ViewModel Controller

a guest
Aug 29th, 2011
1,008
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1.     public class HomeController : Controller
  2.     {
  3.         //
  4.         // GET: /Home/
  5.  
  6.         public ActionResult Index()
  7.         {
  8.             AnasayfaViewModel avm = new AnasayfaViewModel();
  9.             try
  10.             {
  11.                 Category CategoryBL = new Category();
  12.                 Campaign CampaignBL=new Campaign();
  13.                 Product ProductBL = new Product();
  14.                
  15.                 avm.Kategoriler = CategoryBL.GetCategories();
  16.                 avm.Kampanyalar = CampaignBL.GetCampaing();
  17.                 avm.EnSonUrunler = ProductBL.GetLatestProducts(10);//son 10 ürün
  18.  
  19.                 avm.Success = true; //şu ana kadar bir exception oluşmadı.
  20.  
  21.  
  22.             }
  23.             catch (Exception ex) //Burarada Exception class'indan türetilen kendi exception class'imizi kullanarak kolaylıkla log'lama da yapabiliriz
  24.             {
  25.                 avm.Success = false; //view tarafında durumu kontrol edip sayfada işlem yapmıyoruz
  26.                 avm.Message = ex.Message; // kullanıcıya hatayı bildiriyoruz, istersek kendi mesajımızı da yazabiliriz.
  27.             }
  28.             return View(avm);
  29.         }
  30.  
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement