public ActionResult UpdateProducteBay(string id, ProducteBayDto model)
        {
            try
            {
                // get the original product
                var eBay = _productService.GetProducteBay(id);

                // try to determine the category ID for the eBay
                int categoryId = 0;
                Int32.TryParse(model.CategoryName, out categoryId);

                // try to look the value for category name if the category is null
                if (model.CategoryId == null)
                {
                    model.CategoryId = categoryId != 0 ? (int?)categoryId : null;
                }

                if (eBay == null)
                {
                    _productService.SaveProducteBay(model);
                }
                else
                {
                    _productService.UpdateProducteBay(id, model);
                }

                TempData["Message"] = "Changes have been successfully saved!";
            }
            catch (Exception ex)
            {
                TempData["ErrorMessage"] = string.Format("Error in saving eBay product. Exception Msg: {0}",
                                                         EisHelper.GetExceptionMessage(ex));
            }
            return(RedirectToAction("edit", new { id = id }));
        }
Exemple #2
0
        public bool SaveProducteBay(ProducteBayDto model)
        {
            var product = Mapper.Map <ProducteBayDto, productebay>(model);

            product.Created = DateTime.UtcNow;

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

            return(true);
        }
Exemple #3
0
        public bool UpdateProducteBay(string eisSku, ProducteBayDto model)
        {
            var oldProduct = _context.productebays.Find(eisSku);

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

            _context.SaveChanges();

            return(true);
        }
        private static ProducteBayDto extractProducteBay(CsvReader csvReader)
        {
            var eBay = new ProducteBayDto();

            string eisSku = null;

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

            string itemId = null;

            csvReader.TryGetField <string>("eBay-ItemId", out itemId);
            eBay.ItemId = itemId;

            string title = null;

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

            string subTitle = null;

            csvReader.TryGetField <string>("eBay-SubTitle", out subTitle);
            eBay.SubTitle = subTitle;

            string description = null;

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

            int?listingQuantity = null;

            csvReader.TryGetField <int?>("eBay-ListingQuantity", out listingQuantity);
            eBay.ListingQuantity      = listingQuantity ?? 1;
            eBay.isListingQuantitySet = listingQuantity != null;

            int?safetyQty = null;

            csvReader.TryGetField <int?>("eBay-SafetyQty", out safetyQty);
            eBay.SafetyQty      = safetyQty ?? 1;
            eBay.isSafetyQtySet = safetyQty != null;

            int?categoryId = null;

            csvReader.TryGetField <int?>("eBay-CategoryId", out categoryId);
            eBay.CategoryId      = categoryId ?? 0;
            eBay.isCategoryIdSet = categoryId != null;

            decimal?startPrice = null;

            csvReader.TryGetField <decimal?>("eBay-StartPrice", out startPrice);
            eBay.StartPrice      = startPrice ?? 0;
            eBay.isStartPriceSet = startPrice != null;

            decimal?reservePrice;

            csvReader.TryGetField <decimal?>("eBay-ReservePrice", out reservePrice);
            eBay.ReservePrice      = reservePrice ?? 0;
            eBay.isReservePriceSet = reservePrice != null;

            decimal?binPrice = null;

            csvReader.TryGetField <decimal?>("eBay-BinPrice", out binPrice);
            eBay.BinPrice      = binPrice ?? 0;
            eBay.isBinPriceSet = binPrice != null;

            string listType = null;

            csvReader.TryGetField <string>("eBay-ListType", out listType);
            eBay.ListType = listType;

            string duration = null;

            csvReader.TryGetField <string>("eBay-Duration", out duration);
            eBay.Duration = duration;

            string location = null;

            csvReader.TryGetField <string>("eBay-Location", out location);
            eBay.Location = location;

            int?condition = null;

            csvReader.TryGetField <int?>("eBay-Condition", out condition);
            eBay.Condition_     = condition ?? 1000;
            eBay.isConditionSet = condition != null;

            int?dispatchTimeMax = null;

            csvReader.TryGetField <int?>("eBay-DispatchTimeMax", out dispatchTimeMax);
            eBay.DispatchTimeMax      = dispatchTimeMax ?? 1;
            eBay.isDispatchTimeMaxSet = dispatchTimeMax != null;

            bool?isBoldTitle = null;

            csvReader.TryGetField <bool?>("eBay-IsBoldTitle", out isBoldTitle);
            eBay.IsBoldTitle    = isBoldTitle ?? false;
            eBay.isBoldTitleSet = isBoldTitle != null;

            bool?isOutOfStockListing = null;

            csvReader.TryGetField <bool?>("eBay-IsOutOfStockListing", out isOutOfStockListing);
            eBay.IsOutOfStockListing    = isOutOfStockListing ?? false;
            eBay.isOutOfStockListingSet = isOutOfStockListing != null;

            bool?isRequireAutoPayment = null;

            csvReader.TryGetField <bool?>("eBay-IsRequireAutoPayment", out isRequireAutoPayment);
            eBay.IsRequireAutoPayment    = isRequireAutoPayment ?? false;
            eBay.isRequireAutoPaymentSet = isRequireAutoPayment != null;

            bool?isEnabled = null;

            csvReader.TryGetField <bool?>("eBay-IsEnabled", out isEnabled);
            eBay.IsEnabled    = isEnabled ?? false;
            eBay.isEnabledSet = isEnabled != null;

            return(eBay);
        }
        public int DoUpadateOrInserteBay(ProducteBayDto model, string submittedBy)
        {
            using (var context = new EisInventoryContext())
            {
                // check if the bigcommerce product already exists
                var product = context.productebays.FirstOrDefault(x => x.EisSKU == model.EisSKU);

                // create new item if it doesn't exists
                if (product == null)
                {
                    model.Title    = getTruncatedString(model.Title, 80);
                    model.SubTitle = getTruncatedString(model.SubTitle, 55);
                    var domain = Mapper.Map <productebay>(model);
                    domain.CreatedBy = submittedBy;
                    domain.Created   = DateTime.UtcNow;
                    context.productebays.Add(domain);
                }
                else
                {
                    if (model.ItemId != null)
                    {
                        product.ItemId = model.ItemId;
                    }
                    if (model.Title != null)
                    {
                        product.Title = getTruncatedString(model.Title, 80);
                    }
                    if (model.SubTitle != null)
                    {
                        product.SubTitle = getTruncatedString(model.SubTitle, 55);
                    }
                    if (model.Description != null)
                    {
                        product.Description = model.Description;
                    }
                    if (model.isListingQuantitySet)
                    {
                        product.ListingQuantity = model.ListingQuantity;
                    }
                    if (model.isSafetyQtySet)
                    {
                        product.SafetyQty = model.SafetyQty;
                    }
                    if (model.isCategoryIdSet)
                    {
                        product.CategoryId = model.CategoryId;
                    }
                    if (model.isStartPriceSet)
                    {
                        product.StartPrice = model.StartPrice;
                    }
                    if (model.isReservePriceSet)
                    {
                        product.ReservePrice = model.ReservePrice;
                    }
                    if (model.isBinPriceSet)
                    {
                        product.BinPrice = model.BinPrice;
                    }
                    if (model.ListType != null)
                    {
                        product.ListType = model.ListType;
                    }
                    if (model.Duration != null)
                    {
                        product.Duration = model.Duration;
                    }
                    if (model.Location != null)
                    {
                        product.Location = model.Location;
                    }
                    if (model.isConditionSet)
                    {
                        product.Condition_ = model.Condition_;
                    }
                    if (model.isDispatchTimeMaxSet)
                    {
                        product.DispatchTimeMax = model.DispatchTimeMax;
                    }
                    if (model.isOutOfStockListingSet)
                    {
                        product.IsOutOfStockListing = model.IsOutOfStockListing;
                    }
                    if (model.isBoldTitleSet)
                    {
                        product.IsBoldTitle = model.IsBoldTitle;
                    }
                    if (model.isRequireAutoPaymentSet)
                    {
                        product.IsRequireAutoPayment = model.IsRequireAutoPayment;
                    }
                    if (model.isEnabledSet)
                    {
                        product.IsEnabled = model.IsEnabled;
                    }

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

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

            return(1);
        }