public ActionResult Create(int productId, Promotion promotion)
 {
     try
     {
         _repository.Add(productId, promotion);
         var promotionViewModel = new PromotionViewModel
         {
             Id = promotion.Id,
             ProductId = promotion.ProductId,
             SalesStartDate = promotion.SalesStartDate,
             SalesEndDate = promotion.SalesEndDate,
             PercentDiscount = promotion.PercentDiscount,
             ModifiedDate = promotion.ModifiedDate
         };
         return RedirectToAction("Index", promotionViewModel);
     }
     catch
     {
         return View();
     }
 }
        public ActionResult Details(int id)
        {
            Promotion promotion = _repository.Get(id);
            var promotionViewModel = new PromotionViewModel
            {
                Id = promotion.Id,
                ProductId = promotion.ProductId,
                SalesStartDate = promotion.SalesStartDate,
                SalesEndDate = promotion.SalesEndDate,
                PercentDiscount = promotion.PercentDiscount,
                ModifiedDate = promotion.ModifiedDate
            };

            return promotionViewModel.Id > 0 ? View(promotionViewModel) : View("No data found");
        }
 public ActionResult Index()
 {
     IEnumerable<Promotion> promotions = _repository.List();
     var promotionViewModels = new List<PromotionViewModel>();
     foreach (Promotion promotion in promotions)
     {
         var promotionViewModel = new PromotionViewModel()
         {
             Id = promotion.Id,
             ProductId = promotion.ProductId,
             SalesStartDate = promotion.SalesStartDate,
             SalesEndDate = promotion.SalesEndDate,
             PercentDiscount = promotion.PercentDiscount,
             ModifiedDate = promotion.ModifiedDate
         };
         promotionViewModels.Add(promotionViewModel);
     }
     return promotions.Count() > 0 ? View(promotionViewModels) : View("No data found");
 }
 public ActionResult Edit(int id)
 {
     var promotion = _repository.Get(id);
     var promotionViewModel = new PromotionViewModel
     {
         Id = promotion.Id,
         ProductId = promotion.ProductId,
         SalesStartDate = promotion.SalesStartDate,
         SalesEndDate = promotion.SalesEndDate,
         PercentDiscount = promotion.PercentDiscount,
         ModifiedDate = promotion.ModifiedDate
     };
     return View(promotionViewModel);
 }