public ActionResult UpdateProductBigCommerce(string id, ProductBigCommerceDto model)
        {
            // get the original product
            var bigCommerce = _productService.GetProductBigCommerce(id);

            model.ModifiedBy = User.Identity.Name;
            if (bigCommerce == null)
            {
                _productService.SaveProductBigCommerce(model);
            }
            else
            {
                _productService.UpdateProductBigCommerce(id, model);
            }

            TempData["Message"] = "Changes have been successfully saved!";
            return(RedirectToAction("edit", new { id = id }));
        }
Example #2
0
        public bool SaveProductBigCommerce(ProductBigCommerceDto model)
        {
            var product = Mapper.Map <productbigcommerce>(model);

            try {
                product.Created   = DateTime.UtcNow;
                product.CreatedBy = model.ModifiedBy;

                _context.productbigcommerces.Add(product);
                _context.SaveChanges();

                return(true);
            } catch (DbEntityValidationException ex) {
                var errorMsg = EisHelper.ParseDbEntityValidationException(ex);
                _logger.LogError(LogEntryType.ProductService, errorMsg, ex.StackTrace);
                throw ex;
            } catch (Exception ex) {
                _logger.LogError(LogEntryType.ProductService, EisHelper.GetExceptionMessage(ex), ex.StackTrace);
                throw ex;
            }
        }
Example #3
0
        public bool UpdateProductBigCommerce(string eisSku, ProductBigCommerceDto model)
        {
            try {
                var oldProduct = _context.productbigcommerces.Find(eisSku);

                // ensure the EIS SKU is upper cased
                model.EisSKU.ToUpper();
                _context.Entry(oldProduct).CurrentValues.SetValues(model);
                oldProduct.Modified   = DateTime.UtcNow;
                oldProduct.ModifiedBy = model.ModifiedBy;

                _context.SaveChanges();

                return(true);
            } catch (DbEntityValidationException ex) {
                var errorMsg = EisHelper.ParseDbEntityValidationException(ex);
                _logger.LogError(LogEntryType.ProductService, errorMsg, ex.StackTrace);
                throw ex;
            } catch (Exception ex) {
                _logger.LogError(LogEntryType.ProductService, EisHelper.GetExceptionMessage(ex), ex.StackTrace);
                throw ex;
            }
        }
        private static ProductBigCommerceDto extractProductBigCommerce(CsvReader csvReader)
        {
            var bigCommerce = new ProductBigCommerceDto();

            string eisSku = null;

            csvReader.TryGetField <string>("General-EisSKU", out eisSku);
            bigCommerce.EisSKU = eisSku;

            int?productId = null;

            csvReader.TryGetField <int?>("BigCommerce-ProductId", out productId);
            bigCommerce.ProductId = productId;

            int?categoryId = null;

            csvReader.TryGetField <int?>("BigCommerce-CategoryId", out categoryId);
            bigCommerce.CategoryId = categoryId;

            decimal?price = null;

            csvReader.TryGetField <decimal?>("BigCommerce-Price", out price);
            bigCommerce.Price = price;

            string condition = null;

            csvReader.TryGetField <string>("BigCommerce-Condition", out condition);
            bigCommerce.Condition = condition;

            string categories = null;

            csvReader.TryGetField <string>("BigCommerce-Categories", out categories);
            bigCommerce.Categories = categories;

            decimal?retailPrice = null;

            csvReader.TryGetField <decimal?>("BigCommerce-RetailPrice", out retailPrice);
            bigCommerce.RetailPrice = retailPrice;

            string primaryImage = null;

            csvReader.TryGetField <string>("BigCommerce-PrimaryImage", out primaryImage);
            bigCommerce.PrimaryImage = primaryImage;

            decimal?fixedCostShippingPrice = null;

            csvReader.TryGetField <decimal?>("BigCommerce-FixedCostShippingPrice", out fixedCostShippingPrice);
            bigCommerce.FixedCostShippingPrice = fixedCostShippingPrice;

            int?brand = null;

            csvReader.TryGetField <int?>("BigCommerce-Brand", out brand);
            bigCommerce.Brand = brand;

            int?productsType = null;

            csvReader.TryGetField <int?>("BigCommerce-ProductsType", out productsType);
            bigCommerce.ProductsType = productsType;

            int?inventoryLevel = null;

            csvReader.TryGetField <int?>("BigCommerce-InventoryLevel", out inventoryLevel);
            bigCommerce.InventoryLevel = inventoryLevel;

            int?inventoryWarningLevel = null;

            csvReader.TryGetField <int?>("BigCommerce-InventoryWarningLevel", out inventoryWarningLevel);
            bigCommerce.InventoryWarningLevel = inventoryWarningLevel;

            int?inventoryTracking = null;

            csvReader.TryGetField <int?>("BigCommerce-InventoryTracking", out inventoryTracking);
            bigCommerce.InventoryTracking = inventoryTracking;

            int?orderQuantityMinimum = null;

            csvReader.TryGetField <int?>("BigCommerce-OrderQuantityMinimum", out orderQuantityMinimum);
            bigCommerce.OrderQuantityMinimum = orderQuantityMinimum;

            int?orderQuantityMaximum = null;

            csvReader.TryGetField <int?>("BigCommerce-OrderQuantityMaximum", out orderQuantityMaximum);
            bigCommerce.OrderQuantityMaximum = orderQuantityMaximum;

            bool?isEnabled = null;

            csvReader.TryGetField <bool?>("BigCommerce-IsEnabled", out isEnabled);
            bigCommerce.IsEnabled = isEnabled ?? false;

            string description = null;

            csvReader.TryGetField <string>("BigCommerce-Description", out description);
            bigCommerce.Description = description;

            string title = null;

            csvReader.TryGetField <string>("BigCommerce-Title", out title);
            bigCommerce.Title = title;

            return(bigCommerce);
        }
        public int DoUpdateOrInsertBigCommerce(ProductBigCommerceDto model, string submittedBy)
        {
            using (var context = new EisInventoryContext())
            {
                // check if the bigcommerce product already exists
                var product = context.productbigcommerces.FirstOrDefault(x => x.EisSKU == model.EisSKU);
                if (product == null)
                {
                    var domain = Mapper.Map <productbigcommerce>(model);
                    domain.CreatedBy = submittedBy;
                    domain.Created   = DateTime.UtcNow;
                    context.productbigcommerces.Add(domain);
                }
                else
                {
                    if (model.ProductId != null)
                    {
                        product.ProductId = model.ProductId;
                    }
                    if (model.CategoryId != null)
                    {
                        product.CategoryId = model.CategoryId;
                    }
                    if (model.Price != null)
                    {
                        product.Price = model.Price;
                    }
                    if (!string.IsNullOrEmpty(model.Condition))
                    {
                        product.Condition = model.Condition;
                    }
                    if (!string.IsNullOrEmpty(model.Categories))
                    {
                        product.Categories = model.Categories;
                    }
                    if (model.RetailPrice != null)
                    {
                        product.RetailPrice = model.RetailPrice;
                    }
                    if (!string.IsNullOrEmpty(model.PrimaryImage))
                    {
                        product.PrimaryImage = model.PrimaryImage;
                    }
                    if (model.FixedCostShippingPrice != null)
                    {
                        product.FixedCostShippingPrice = model.FixedCostShippingPrice;
                    }
                    if (model.Brand != null)
                    {
                        product.Brand = model.Brand;
                    }
                    if (model.ProductsType != null)
                    {
                        product.ProductsType = model.ProductsType;
                    }
                    if (model.InventoryLevel != null)
                    {
                        product.InventoryLevel = model.InventoryLevel;
                    }
                    if (model.InventoryWarningLevel != null)
                    {
                        product.InventoryWarningLevel = model.InventoryWarningLevel;
                    }
                    if (model.InventoryTracking != null)
                    {
                        product.InventoryTracking = model.InventoryTracking;
                    }
                    if (model.OrderQuantityMinimum != null)
                    {
                        product.OrderQuantityMinimum = model.OrderQuantityMinimum;
                    }
                    if (model.OrderQuantityMaximum != null)
                    {
                        product.OrderQuantityMaximum = model.OrderQuantityMaximum;
                    }
                    if (model.IsEnabled)
                    {
                        product.IsEnabled = model.IsEnabled;
                    }
                    if (model.Description != null)
                    {
                        product.Description = model.Description;
                    }
                    if (model.Title != null)
                    {
                        product.Title = model.Title;
                    }

                    product.ModifiedBy = submittedBy;
                    product.Modified   = DateTime.UtcNow;
                }

                // save the changes
                context.SaveChanges();
            }

            return(1);
        }