public ActionResult Create()
 {
     try
     {
         var promotionalDiscount = new PromotionalDiscountViewModel
         {
             DateFrom = DateTime.Now,
             DateTo   = DateTime.Now,
             Active   = true,
             PromotionalDiscountDetails = new List <PromotionalDiscountDetailViewModel>
             {
                 new PromotionalDiscountDetailViewModel()
             }
         };
         return(View(promotionalDiscount));
     }
     catch (Exception ex)
     {
         ViewBag.Fail = ex.Message;
         return(View());
     }
 }
 public JavaScriptResult Edit(PromotionalDiscountViewModel promotionalDiscountVm)
 {
     try
     {
         if (promotionalDiscountVm.PromotionalDiscountDetails.All(x => x.EligibleQuantity > 0))
         {
             var promotionalDiscount        = Mapper.Map <PromotionalDiscount>(promotionalDiscountVm);
             var promotionalDiscountDetails = Mapper.Map <List <PromotionalDiscountDetail> >(promotionalDiscountVm.PromotionalDiscountDetails);
             promotionalDiscount.PromotionalDiscountDetails = new List <PromotionalDiscountDetail>();
             foreach (var item in promotionalDiscountDetails)
             {
                 promotionalDiscount.PromotionalDiscountDetails.Add(item);
             }
             _promotionalDiscountService.Update(promotionalDiscount);
             return(JavaScript($"ShowResult('{"Data Updated successfully."}','{"success"}','{"redirect"}','{"/APanel/PromotionalDiscount/?dateFrom=" + promotionalDiscountVm.DateFrom.ToString("dd-MMM-yyyy") + "&dateTo=" + promotionalDiscountVm.DateTo.ToString("dd-MMM-yyyy")}')"));
         }
         return(JavaScript($"ShowResult('{"Enter quantity!"}','{"failure"}')"));
     }
     catch (Exception ex)
     {
         return(JavaScript($"ShowResult('{ex.Message}','{"failure"}')"));
     }
 }