Step 6: Solution with Front End

by sunil ravulapalli /30. July 2013 00:35 /software-design /Comments (0)

Add Ninject binding to DataNinjectModule in the Data project.

public class DataNinjectModule : NinjectModule
{ 
  public override void Load() 
  {  
     Kernel.Bind<IUnitOfWork>().To<UnitOfWork>(); 
  }
}

Add Ninject binding to ServiceNinjectModule in the Data project.

public class ServiceNinjectModule : NinjectModule
{ 
  public override void Load() 
  {  
    Kernel.Bind<IWishlistService>().To<WishlistService>(); 
  }
}

Add a controller class in the Web project.

public class WishlistController : Controller
{ 
  private readonly WishlistService _wishlistService; 
  public WishlistController(WishlistService wishlistService) 
  {  
    _wishlistService = wishlistService; 
  } 
  public ActionResult Add() 
  {  
    return View(); 
  } 
  [HttpPost] 
  public ActionResult Add(WishListItemViewModel wishListItemViewModel) 
  {  
    _wishlistService.AddWishlistItem(wishListItemViewModel.Description, wishListItemViewModel.Quantity);  
    return RedirectToAction("All"); 
  } 
  public ActionResult All() 
  {  
    return View(_wishlistService.GetAllWishlistItems()); 
  }
}


Add a view model class.
Add corresponding views.
Modify routes
Add a connection string in Web.config.

<add name="CompanyDbContext" providerName="System.Data.SqlClient" connectionString="Data Source=MYMACHINE\SQLEXPRESS;Initial Catalog=Wishlist.Data.CompanyDbContext;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False" />

You can find the solution on GitHub.
https://github.com/sunilrav/Wishlist.6.SolutionWithFrontEnd


 

blog comments powered by Disqus