public void Save(ProductPricingTierViewModel productPricingTierViewModel)
 {
     ProductPricingTier pptVM = new ProductPricingTier(productPricingTierViewModel.Id)
     {
         Name = productPricingTierViewModel.Name,
         Code=productPricingTierViewModel.TierCode,
         Description=productPricingTierViewModel.Description
     };
     _productPricingTierRepository.Save(pptVM);
 }
        public ActionResult ImportPricingTiers(HttpPostedFileBase file)
        {

            try
            {

                var fileName = Path.GetFileName(file.FileName);


                var directory = Server.MapPath("~/Uploads");
                if (Directory.Exists(directory) == false)
                {
                    Directory.CreateDirectory(directory);
                }
                var path = Server.MapPath("~/Uploads") + "\\" + fileName;


                file.SaveAs(path);


                string fileExtension = Path.GetExtension(fileName);
                if (fileExtension == ".xlsx")
                {
                    ViewBag.msg = "Please wait. Upload in progress";

                    string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties='Excel 12.0;HDR=YES;'";

                    OleDbConnection conn = new OleDbConnection(connectionString);
                    try
                    {
                        conn.Open();
                        OleDbCommand command = new OleDbCommand("SELECT code,name,description FROM [Sheet1$]", conn);
                        OleDbDataReader reader = command.ExecuteReader();
                        ProductPricingTierViewModel ptvm = new ProductPricingTierViewModel();
                        while (reader.Read())
                        {

                            string code = reader["code"].ToString();
                            string name = reader["name"].ToString();
                            string description = reader["description"].ToString();

                            bool hasDuplicateName = _productPricingTierViewModelBuilder.GetAll()
                            .Any(p => p.Name == name);

                            if (hasDuplicateName)
                            { }
                            else
                            {
                                ptvm.Name = name;
                                ptvm.TierCode = code;
                                ptvm.Description = description;
                                _productPricingTierViewModelBuilder.Save(ptvm);

                            }
                        }
                    }
                    catch (OleDbException ex)
                    {
                        ViewBag.msg = ex.ToString();
                        return View();
                    }

                    finally
                    {
                        conn.Close();

                    }

                    fi = new FileInfo(path);

                    fi.Delete();
                    _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Import", "Product Pricing Tier", DateTime.Now);
                    ViewBag.msg = "Upload Successful";
                    return RedirectToAction("ListProductPricingTiers");
                }

                else
                {
                    fi = new FileInfo(path);

                    fi.Delete();
                    ViewBag.msg = "Please upload excel file with extension .xlsx";
                    return View();
                }
            }
            catch (Exception ex)
            {

                ViewBag.msg = ex.ToString();
                return View();
            }


        }
 public ActionResult CreateProductPricingTier(ProductPricingTierViewModel productPricingTierViewModel)
 {
     try
     {
         productPricingTierViewModel.Id = Guid.NewGuid();
         _productPricingTierViewModelBuilder.Save(productPricingTierViewModel);
         _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Create", "Product Pricing Tier", DateTime.Now);
         TempData["msg"] = "Product Pricing Tier Successfully Created";
         return RedirectToAction("ListProductPricingTiers");
     }
     catch (DomainValidationException dve)
     {
         ValidationSummary.DomainValidationErrors(dve,ModelState);
         _log.ErrorFormat("Error in creating product pricing  tier" + dve.Message);
         _log.InfoFormat("Error in creating product pricing tier " + dve.Message);
         return View();
     }
     catch(Exception ex)
     {
         ViewBag.msg = ex.Message;
         _log.ErrorFormat("Error in creating product pricing  tier" + ex.Message);
         _log.InfoFormat("Error in creating product pricing tier " + ex.Message);
         return View();
     }
 }
 public ActionResult EditProductPricingTier(ProductPricingTierViewModel vm)
 {
     try
     {
         _productPricingTierViewModelBuilder.Save(vm);
         _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "edit", "Product Pricing Tier", DateTime.Now);
         return RedirectToAction("ListProductPricingTiers");
     }
     catch (DomainValidationException ve)
     {
         ValidationSummary.DomainValidationErrors(ve, ModelState);
         _log.ErrorFormat("Error in editing product pricing  tier" + ve.Message);
         _log.InfoFormat("Error in editing product pricing tier " + ve.Message);
         return View();
     }
     catch (Exception ex)
     {
         //Session["msg"] = ex.Message;
         ModelState.AddModelError("", ex.Message);
         _log.ErrorFormat("Error in editing product pricing  tier" + ex.Message);
         _log.InfoFormat("Error in editing product pricing tier " + ex.Message);
         return View();
     }
 }