Пример #1
0
        public void SaveSaleProduct(SaleProductViewModel vm)
        {
            if (vm.brandCode != null && vm.subBrandCode != null && vm.productTypeCode != null && vm.packTypeCode != null && vm.packCode != null && vm.vatClass != null)
            {
                ProductBrand pd = _productBrandRepository.GetAll().FirstOrDefault(n => n.Code == vm.brandCode);
                ProductFlavour pf = _productFlavourRepository.GetAll().FirstOrDefault(n=>n.Code==vm.subBrandCode);
                ProductType pt = _productTypeRepository.GetAll().FirstOrDefault(n=>n.Code==vm.productTypeCode);
                ProductPackaging ppg = _productPackagingRepository.GetAll().FirstOrDefault(n=>n.Code==vm.packCode);
                ProductPackagingType ppgT = _productPackagingTypeRepository.GetAll().FirstOrDefault(n=>n.Code==vm.packTypeCode);
                VATClass vc = _vatClassRepository.GetAll().FirstOrDefault(n=>n.VatClass==vm.vatClass);

                SaleProduct sp = _productRepository.GetById(vm.Id) as SaleProduct;
                if (sp == null)
                    sp = _productFactory.CreateSaleProduct(vm.Id);
                sp.Brand = _productBrandRepository.GetById(pd.Id);
                sp.Description = vm.Description;
                sp.ExFactoryPrice = vm.ExFactoryPrice;
                sp.Packaging = _productPackagingRepository.GetById(ppg.Id);
                sp.PackagingType = _productPackagingTypeRepository.GetById(ppgT.Id);
                sp.ProductCode = vm.ProductCode;
                sp.Flavour = _productFlavourRepository.GetById(pf.Id);
                sp.ProductType = _productTypeRepository.GetById(pt.Id);
                sp.VATClass = _vatClassRepository.GetById(vc.Id);

                _productRepository.Save(sp);
                if (vm.Id == Guid.Empty)
                {
                    addDefaultPrice();
                }
            }
            else
            {

                SaleProduct sp = sp = _productRepository.GetById(vm.Id) as SaleProduct; ;
                if (sp== null)
                    sp = _productFactory.CreateSaleProduct(vm.Id);


                sp.ExFactoryPrice = vm.ExFactoryPrice;
                sp.Brand = _productBrandRepository.GetById(vm.Brands);
                sp.Description = vm.Description;
                sp.Packaging = _productPackagingRepository.GetById(vm.Packaging);
                sp.PackagingType = _productPackagingTypeRepository.GetById(vm.PackageType);
                sp.ProductCode = vm.ProductCode;
                sp.Flavour = _productFlavourRepository.GetById(vm.FlavourID);
                sp.ProductType = _productTypeRepository.GetById(vm.ProductTypeID);
                sp.VATClass = _vatClassRepository.GetById(vm.VatClassId);
                if (vm.ReturnableProductId != null)
                    sp.ReturnableProduct = _productRepository.GetById(vm.ReturnableProductId.Value) as ReturnableProduct;

                _productRepository.Save(sp);
                if (vm.Id == Guid.Empty)
                {
                    addDefaultPrice();
                }
            }
        }
Пример #2
0
        public ActionResult ImportProduct(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();
                        string product = "";
                        OleDbCommand commProduct = new OleDbCommand("SELECT product FROM [Sheet1$]", conn);
                        OleDbDataReader readProduct = commProduct.ExecuteReader();
                        while (readProduct.Read())
                        {
                            product = readProduct["product"].ToString();
                        }
                        if (product == "Sale Product")
                        {
                            OleDbCommand command = new OleDbCommand("SELECT brandCode,subBrandCode,packagingtypeCode,packagingCode,productTypeCode,vatClass,code,description FROM [Sheet1$]", conn);
                            OleDbDataReader reader = command.ExecuteReader();
                            SaleProductViewModel pdvm = new SaleProductViewModel();
                            while (reader.Read())
                            {

                                string brandCode = reader["brandCode"].ToString();
                                string subBrandCode = reader["subBrandCode"].ToString();
                                string packagingTypeCode = reader["packagingTypeCode"].ToString();
                                string packagingCode = reader["packagingCode"].ToString();
                                string productTypeCode = reader["productTypeCode"].ToString();
                                string vatClass = reader["vatClass"].ToString();
                                string productCode = reader["code"].ToString();
                                string description = reader["description"].ToString();

                                pdvm.brandCode = brandCode;
                                pdvm.subBrandCode = subBrandCode;
                                pdvm.packTypeCode = packagingTypeCode;
                                pdvm.packCode = packagingCode;
                                pdvm.productTypeCode = productTypeCode;
                                pdvm.vatClass = vatClass;
                                pdvm.ProductCode = productCode;
                                pdvm.Description = description;
                                _productViewModelBuilder.SaveSaleProduct(pdvm);

                            }
                        }
                        else if (product == "Returnable Product")
                        {
                            OleDbCommand command = new OleDbCommand("SELECT Brand,SubBrand,PackagingType,Packaging,ProductType,VatClass,ProductCode,Description,returnableType FROM [Sheet1$]", conn);
                            OleDbDataReader reader = command.ExecuteReader();
                            EditReturnableProductViewModelIn pdvm = new EditReturnableProductViewModelIn();
                            while (reader.Read())
                            {

                                string brandCode = reader["brand"].ToString();
                                string subBrandCode = reader["subBrand"].ToString();
                                string packagingTypeCode = reader["packagingType"].ToString();
                                string packagingCode = reader["packaging"].ToString();
                                string productTypeCode = reader["productType"].ToString();
                                string vatClass = reader["vatClass"].ToString();
                                string productCode = reader["productcode"].ToString();
                                string description = reader["description"].ToString();
                                string returnableType = reader["returnableType"].ToString();

                                pdvm.brandCode = brandCode;
                                pdvm.subBrandCode = subBrandCode;
                                pdvm.packTypeCode = packagingTypeCode;
                                pdvm.packCode = packagingCode;
                                pdvm.productTypeCode = productTypeCode;
                                pdvm.vatClass = vatClass;
                                pdvm.ProductCode = productCode;
                                pdvm.Description = description;
                                pdvm.RetunableTypeName = returnableType;
                                _productViewModelBuilder.Save(pdvm);

                            }
                        }
                        else if (product == "Consolidated Product")
                        {
                            OleDbCommand command = new OleDbCommand("SELECT brandCode,packagingtypeCode,packagingCode,code,description FROM [Sheet1$]", conn);
                            OleDbDataReader reader = command.ExecuteReader();
                            EditConsolidatedProductOut vm = new EditConsolidatedProductOut();

                            string brandCode = reader["brandCode"].ToString();
                            string packagingTypeCode = reader["packagingTypeCode"].ToString();
                            string packagingCode = reader["packagingCode"].ToString();
                            string code = reader["Code"].ToString();
                            string description = reader["description"].ToString();

                            vm.brandCode = brandCode;
                            vm.packagingTypeCode = packagingTypeCode;
                            vm.packagingCode = packagingCode;
                            vm.ProductCode = code;
                            vm.Description = description;
                            _productViewModelBuilder.Save(vm);
                        }
                    }
                    catch (OleDbException ex)
                    {
                        ViewBag.msg = ex.ToString();
                        try
                        {
                            HQMailerViewModelBuilder hqm = new HQMailerViewModelBuilder(ConfigurationSettings.AppSettings["ServerIP"], ConfigurationSettings.AppSettings["UserName"], ConfigurationSettings.AppSettings["Password"]);


                            hqm.Send(ConfigurationSettings.AppSettings["ServerEmail"], ConfigurationSettings.AppSettings["MailGroup"], "Test", "editing sale product error:" + ex.Message);
                        }
                        catch (Exception exx)
                        { }
                        return View();
                    }

                    finally
                    {
                        conn.Close();

                    }

                    fi = new FileInfo(path);

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

                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();
                try
                {
                    HQMailerViewModelBuilder hqm = new HQMailerViewModelBuilder(ConfigurationSettings.AppSettings["ServerIP"], ConfigurationSettings.AppSettings["UserName"], ConfigurationSettings.AppSettings["Password"]);


                    hqm.Send(ConfigurationSettings.AppSettings["ServerEmail"], ConfigurationSettings.AppSettings["MailGroup"], "Test", "editing sale product error:" + ex.Message);
                }
                catch (Exception exx)
                { }
                return View();
            }


        }
Пример #3
0
        public ActionResult CreateSaleProduct(SaleProductViewModel vm)
        {

            try
            {
                ViewBag.msg = TempData["msg"] = null;
               
                vm.Id = Guid.NewGuid();

                _productViewModelBuilder.SaveSaleProduct(vm);
                TempData["msg"] = "Sale Product Successfully created";
                return RedirectToAction("Index");
            }
            catch (DomainValidationException dve)
            {
                ValidationSummary.DomainValidationErrors(dve, ModelState);
                //ViewBag.msg = dve.Message;
                ViewBag.BrandsList = _productBrandRepository.GetAll().Select(n => new { n.Id, n.Name }).ToDictionary(s => s.Id, s => s.Name);
                ViewBag.FlavoursList = _productFlavourRepository.GetAll().Select(n => new { n.Id, n.Description }).ToDictionary(s => s.Id, s => s.Description);
                ViewBag.PackagingsList = _productPackagingRepository.GetAll().Select(n => new { n.Id, n.Description }).ToDictionary(s => s.Id, s => s.Description);
                ViewBag.PackTypeList = _productPackagingTypeRepository.GetAll().Select(n => new { n.Id, n.Description }).ToDictionary(s => s.Id, s => s.Description);
                ViewBag.VatClassList = _vatClassRepository.GetAll().Select(n => new { n.Id, n.VatClass }).ToDictionary(s => s.Id, s => s.VatClass);
                ViewBag.ProductTypeList = _productTypeRepository.GetAll().Select(n => new { n.Id, n.Name }).ToDictionary(s => s.Id, s => s.Name);
                ViewBag.ReturnableProductList = _productRepository.GetAll().OfType<ReturnableProduct>().Select(n => new { n.Id, n.Description }).ToDictionary(s => s.Id, s => s.Description);
                
                return View("CreateSaleProduct");
            }
            catch (Exception exx)
            {
                ViewBag.msg = exx.Message;

                ViewBag.BrandsList = _productBrandRepository.GetAll().Select(n => new { n.Id, n.Name }).ToDictionary(s => s.Id, s => s.Name);
                ViewBag.FlavoursList = _productFlavourRepository.GetAll().Select(n => new { n.Id, n.Description }).ToDictionary(s => s.Id, s => s.Description);
                ViewBag.PackagingsList = _productPackagingRepository.GetAll().Select(n => new { n.Id, n.Description }).ToDictionary(s => s.Id, s => s.Description);
                ViewBag.PackTypeList = _productPackagingTypeRepository.GetAll().Select(n => new { n.Id, n.Description }).ToDictionary(s => s.Id, s => s.Description);
                ViewBag.VatClassList = _vatClassRepository.GetAll().Select(n => new { n.Id, n.VatClass }).ToDictionary(s => s.Id, s => s.VatClass);
                ViewBag.ProductTypeList = _productTypeRepository.GetAll().Select(n => new { n.Id, n.Name }).ToDictionary(s => s.Id, s => s.Name);
                ViewBag.ReturnableProductList = _productRepository.GetAll().OfType<ReturnableProduct>().Select(n => new { n.Id, n.Description }).ToDictionary(s => s.Id, s => s.Description);
              
                return View();
            }
        }
Пример #4
0
        public ActionResult CreateSaleProduct(SaleProductViewModel vm)
        { 
            
         try
         {
             ViewBag.msg = TempData["msg"] = null;
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();
                vm.Id = Guid.NewGuid();
                _productViewModelBuilder.SaveSaleProduct(vm);
                _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Create", "Sale Product", DateTime.Now);
                stopWatch.Stop();
                TimeSpan ts = stopWatch.Elapsed;


                // Format and display the TimeSpan value.
                string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                    ts.Hours,
                    ts.Minutes,
                    ts.Seconds,
                    ts.TotalMilliseconds);


                stopWatch.Reset();


                _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Timestamp", "Product Controller:Creat Sale Product:" + elapsedTime, DateTime.Now);
                TempData["msg"] = "Sale Product Successfully created";
                return RedirectToAction("Index");
            }
            catch (DomainValidationException dve)
            {
                ValidationSummary.DomainValidationErrors(dve, ModelState);
                //ViewBag.msg = dve.Message;
                ViewBag.BrandsList = _productViewModelBuilder.GetBrands();
                ViewBag.FlavoursList = _productViewModelBuilder.GetFlavours();
                ViewBag.PackagingsList = _productViewModelBuilder.GetPackaging();
                ViewBag.PackTypeList = _productViewModelBuilder.GetPackagingType();
                ViewBag.ProductTypeList = _productViewModelBuilder.GetProductType();
                ViewBag.VatClassList = _productViewModelBuilder.VatClass();
                ViewBag.ReturnableProductList = _productViewModelBuilder.GetReturnableProducts();
                _log.ErrorFormat("Error in creating product " + dve.Message);
                _log.InfoFormat("Error in creating product " + dve.Message);
                return View("CreateSaleProduct");
            }
            catch (Exception exx)
            {
                ViewBag.msg = exx.Message;

                ViewBag.BrandsList = _productViewModelBuilder.GetBrands();
                ViewBag.FlavoursList = _productViewModelBuilder.GetFlavours();
                ViewBag.PackagingsList = _productViewModelBuilder.GetPackaging();
                ViewBag.PackTypeList = _productViewModelBuilder.GetPackagingType();
                ViewBag.ProductTypeList = _productViewModelBuilder.GetProductType();
                ViewBag.VatClassList = _productViewModelBuilder.VatClass();
                ViewBag.ReturnableProductList = _productViewModelBuilder.GetReturnableProducts();
                _log.ErrorFormat("Error in creating product " + exx.Message);
                _log.InfoFormat("Error in creating product " + exx.Message);
               
                return View(vm);
            }
        }