public AddPricingLineItemsViewModel GetById(Guid id)
        {
            ProductPricing ppr=_productPricingRepository.GetById(id);
            AddPricingLineItemsViewModel alvm = new AddPricingLineItemsViewModel
            {
                id = ppr.Id,
                CurrentEffectiveDate = ppr.CurrentEffectiveDate,
                CurrentExFactory = ppr.CurrentExFactory,
                CurrentSellingPrice = ppr.CurrentSellingPrice,
                
            };
            return alvm;

        }
        public ActionResult CreatePricingItems(AddPricingLineItemsViewModel aplvm)
        {
            try
            {
                var settings = _settingsRepository.GetByKey(SettingsKeys.NumberOfDecimalPlaces);
                var decimalPlaces = settings != null ? settings.Value : "4";
                ViewBag.DecimalPlaces = decimalPlaces;

                if (aplvm.CurrentExFactory > aplvm.CurrentSellingPrice)
                {
                    ModelState.AddModelError("", "Exfactory should be less than selling price");
                    return View(aplvm);
                }
                //if (Decimal.Round(aplvm.CurrentSellingPrice, 4) != aplvm.CurrentSellingPrice)
                //{
                   
                //    return View(aplvm);
                    
                //}
                if (Decimal.Round(aplvm.CurrentSellingPrice, Convert.ToInt32(decimalPlaces)) != aplvm.CurrentSellingPrice)
                {

                    return View(aplvm);

                }
                else
                {
                    
                
                Guid id = aplvm.id;
                DateTime dt = aplvm.CurrentEffectiveDate;
                decimal currSellingPrice = aplvm.CurrentSellingPrice;
                decimal exFactory = aplvm.CurrentExFactory;
                _addPricingLineItemViewModelBuilder.AddPricingLineItem(id, dt, currSellingPrice, exFactory);
                _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Create", "Product Pricing Items", DateTime.Now);
                TempData["msg"] = "Pricing Item Successfully Created";
                return RedirectToAction("EditProductPricing", new { @id = aplvm.id });
           }
            }
            catch (DomainValidationException dve)
            {
                ValidationSummary.DomainValidationErrors(dve, ModelState);
                ViewBag.msg = dve.Message;
                var modelId = new AddPricingLineItemsViewModel();
                modelId.id = aplvm.id;
                _log.ErrorFormat("Error in creating product pricing" + dve.Message);
                _log.InfoFormat("Error in creating product pricing" + dve.Message);
                return View(aplvm);
            }
            catch (Exception exx)
            {
               ViewBag.msg= exx.Message;
               _log.ErrorFormat("Error in creating product pricing" + exx.Message);
               _log.InfoFormat("Error in creating product pricing" + exx.Message);
               return View(aplvm);
            }
        }
        public ActionResult CreatePricingItems(Guid id)
        {
            //return View("CreatePricingItems", new AddPricingLineItemsViewModel());
             var settings = _settingsRepository.GetByKey(SettingsKeys.NumberOfDecimalPlaces);
             var decimalPlaces = settings != null ? settings.Value : "4";
             ViewBag.DecimalPlaces = decimalPlaces;
             var decimalCharacter = string.Format("N{0}", decimalPlaces);


            try
            {
                ProductPricingViewModel model = _ppViewModelBuilder.Get(id);
                var p = _productRepository.GetById(model.ProductId);
                AddPricingLineItemsViewModel alvm = new AddPricingLineItemsViewModel
                {
                    id = id,
                    CurrentExFactory =p!=null?p.ExFactoryPrice:0,
                };
                
                return View(alvm);
            }
            catch (Exception ex)
            {
                ViewBag.msg = ex.Message;
                return View();
            }
        }