Пример #1
0
        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);
        }
Пример #2
0
 public ShippingRateService()
 {
     _context = new EisInventoryContext();
 }
Пример #3
0
 public BillingService()
 {
     _context = new EisInventoryContext();
 }
Пример #4
0
 public SystemEmailsService(ILogService logger)
 {
     _logger  = logger;
     _context = new EisInventoryContext();
 }
Пример #5
0
 public CredentialService()
 {
     _context = new EisInventoryContext();
 }
Пример #6
0
 public ReportLogService(string connectionString)
 {
     _context          = new EisInventoryContext();
     _connectionString = connectionString;
 }
Пример #7
0
 // [TestInitialize]
 public void InitializeVariables()
 {
     _context = new EisInventoryContext();
 }
Пример #8
0
 public VendorProductService(IImageHelper imageHelper, ILogService logger)
 {
     _logger      = logger;
     _imageHelper = imageHelper;
     _context     = new EisInventoryContext();
 }
Пример #9
0
        public int DoUpadateOrInsertVendorProduct(VendorProduct model, bool isToUpdate, string submittedBy)
        {
            try
            {
                // NEED TO CREATE NEW DB CONTEXT SINCE THIS METHOD IS SHARED TO CONSOLE SERVICES
                using (var context = new EisInventoryContext())
                {
                    if (isToUpdate)
                    {
                        // get the existing vendor product
                        var product = context.vendorproducts.FirstOrDefault(x => x.EisSupplierSKU == model.EisSupplierSKU);
                        if (product == null)
                        {
                            return(0);
                        }

                        // set the new quantity for this vendor product
                        if (model.IsQuantitySet)
                        {
                            // get the number of order items which are Unshipped/Pending for this item
                            var pendingQtyOrders = context.orderproducts.Where(x => x.EisSupplierSKU == model.EisSupplierSKU)
                                                   .Join(context.orderitems,
                                                         op => op.OrderItemId,
                                                         oi => oi.OrderItemId,
                                                         (op, oi) => new { OrderProduct = op, OrderItem = oi })
                                                   .Join(context.orders.Where(x => x.OrderStatus == OrderStatus.Unshipped || x.OrderStatus == OrderStatus.Pending),
                                                         ooi => ooi.OrderItem.OrderId,
                                                         o => o.OrderId,
                                                         (ooi, o) => new { ooi.OrderProduct })
                                                   .Select(x => x.OrderProduct)
                                                   .DefaultIfEmpty <orderproduct>()
                                                   .Sum(x => (x == null ? 0 : x.Quantity));

                            // deduct the availability for this item with its pending orders
                            product.Quantity = model.Quantity - pendingQtyOrders;
                        }

                        if (model.Name != null)
                        {
                            product.Name = model.Name;
                        }
                        if (model.Description != null)
                        {
                            product.Description = model.Description;
                        }
                        if (model.IsSupplierPriceSet)
                        {
                            product.SupplierPrice = model.SupplierPrice;
                        }
                        if (model.IsMinPackSet)
                        {
                            product.MinPack = model.MinPack;
                        }
                        if (model.UPC != null)
                        {
                            product.UPC = model.UPC;
                        }
                        if (model.Category != null)
                        {
                            product.Category = model.Category;
                        }
                        if (model.Weight != null)
                        {
                            product.Weight = model.Weight;
                        }
                        if (model.WeightUnit != null)
                        {
                            product.WeightUnit = model.WeightUnit;
                        }
                        if (model.Shipping != null)
                        {
                            product.Shipping = model.Shipping;
                        }
                        if (model.VendorMOQ != null)
                        {
                            product.VendorMOQ = model.VendorMOQ;
                        }
                        if (model.VendorMOQType != null)
                        {
                            product.VendorMOQType = model.VendorMOQType;
                        }
                        if (model.IsAutoLinkToEisSKUSet)
                        {
                            product.IsAutoLinkToEisSKU = model.IsAutoLinkToEisSKU;
                        }

                        product.Modified   = DateTime.UtcNow;
                        product.ModifiedBy = submittedBy;
                        context.SaveChanges();

                        // let's set some properties; assuming that only EisSupplierSKU is supplied
                        // these data will be used when creating new EisSKU
                        model.Name             = product.Name;
                        model.Description      = product.Description;
                        model.ShortDescription = product.ShortDescription;
                        model.Category         = product.Category;
                        model.UPC         = product.UPC;
                        model.SubmittedBy = submittedBy;
                    }
                    else
                    {
                        var product = new vendorproduct();
                        CopyObject.CopyFields(model, product);
                        product.Created   = DateTime.UtcNow;
                        product.CreatedBy = submittedBy;

                        // add it to the context and save
                        context.vendorproducts.Add(product);
                        context.SaveChanges();
                    }
                    UpdateVendorProductImages(model.Images, model.EisSupplierSKU);
                }
                return(1);
            }
            catch (DbEntityValidationException ex)
            {
                var errorMsg = EisHelper.ParseDbEntityValidationException(ex);
                _logger.LogError(LogEntryType.VendorProductFileUploadWorker, errorMsg, ex.StackTrace);
                return(0);
            }
            catch (Exception ex)
            {
                _logger.LogError(LogEntryType.VendorProductFileUploadWorker,
                                 string.Format("Error in updating vendor product details -> SupplierSKU: {0} VendorId: {1}. <br/>Error message: {2}",
                                               model.SupplierSKU, model.VendorId, EisHelper.GetExceptionMessage(ex)),
                                 ex.StackTrace);
                return(0);
            }
        }
Пример #10
0
 public MessageTemplateService(ILogService logger)
 {
     _context = new EisInventoryContext();
     _logger  = logger;
 }
Пример #11
0
        public bool DeleteProduct(string eisSKU)
        {
            var isSuccessful = false;

            using (var context = new EisInventoryContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    var imagesFileName = new List <string>();
                    try
                    {
                        // get the product first
                        var product = context.products.FirstOrDefault(x => x.EisSKU == eisSKU);
                        if (product == null)
                        {
                            return(true);
                        }

                        // delete first the product amaon
                        var productAmazon = context.productamazons.FirstOrDefault(x => x.EisSKU == eisSKU);
                        if (productAmazon != null)
                        {
                            context.productamazons.Remove(productAmazon);
                        }

                        // delete the eBay product details
                        var producteBay = context.productebays.FirstOrDefault(x => x.EisSKU == eisSKU);
                        if (producteBay != null)
                        {
                            context.productebays.Remove(producteBay);
                        }

                        // delete the bigcommerce product details
                        var productBigCommerce = context.productbigcommerces.FirstOrDefault(x => x.EisSKU == eisSKU);
                        if (productBigCommerce != null)
                        {
                            context.productbigcommerces.Remove(productBigCommerce);
                        }

                        // delete the product from product group details
                        var productGroupDetails = product.productgroupdetails.ToList();
                        foreach (var group in productGroupDetails)
                        {
                            product.productgroupdetails.Remove(group);
                        }

                        // delete first the child kit details
                        var childKitDetails = context.kitdetails.Where(x => x.ChildKitSKU == eisSKU);
                        context.kitdetails.RemoveRange(childKitDetails);

                        // delete the parent kit details
                        var parentKitDetails = context.kitdetails.Where(x => x.ParentKitSKU == eisSKU);
                        context.kitdetails.RemoveRange(parentKitDetails);

                        // then, the kits
                        var kits = context.kits.Where(x => x.ParentKitSKU == eisSKU);
                        context.kits.RemoveRange(kits);

                        // delete the child shadow
                        var childShadows = context.shadows.Where(x => x.ShadowSKU == eisSKU);
                        context.shadows.RemoveRange(childShadows);

                        // delete product from parent shadows
                        var parentShadows = context.shadows.Where(x => x.ParentSKU == eisSKU);
                        context.shadows.RemoveRange(parentShadows);

                        // delete its vendor product links
                        var vendorProductLinks = context.vendorproductlinks.Where(x => x.EisSKU == eisSKU);
                        context.vendorproductlinks.RemoveRange(vendorProductLinks);

                        // get the images first for this product
                        var images = context.productimages.Where(x => x.EisSKU == eisSKU);
                        imagesFileName = images.Select(x => x.FileName).ToList();
                        context.productimages.RemoveRange(images);

                        // lastly, the product
                        context.products.Remove(product);

                        // save the changes
                        context.SaveChanges();

                        // commit the changes
                        transaction.Commit();
                        isSuccessful = true;
                    }
                    catch (Exception ex)
                    {
                        isSuccessful = false;
                        transaction.Rollback();
                    }
                    finally
                    {
                        // delete the product images if it is successfull
                        if (isSuccessful)
                        {
                            imagesFileName.ForEach(fileName => _imageHelper.RemoveProductImage(eisSKU, fileName));
                        }
                    }
                }
            }

            return(isSuccessful);
        }
Пример #12
0
        public void UpdateEisProduct(ProductAmazon model, string submittedBy)
        {
            try
            {
                using (var context = new EisInventoryContext())
                {
                    // get the existing product to update from db
                    var product = context.products.FirstOrDefault(x => x.EisSKU == model.EisSKU);
                    if (product == null)
                    {
                        return;
                    }

                    // determine the product type id of the marketplace product
                    var productTypeId = getConfiguredProductTypeId(model.ProductTypeName, model.ProductGroup);

                    product.Brand         = model.Brand;
                    product.Color         = model.Color;
                    product.EAN           = model.EAN;
                    product.Model         = model.Model;
                    product.ProductTypeId = productTypeId;

                    // set the product' package dimension
                    if (model.PackageDimension != null)
                    {
                        product.PkgLength     = model.PackageDimension.Length.Value;
                        product.PkgWidth      = model.PackageDimension.Width.Value;
                        product.PkgHeight     = model.PackageDimension.Height.Value;
                        product.PkgLenghtUnit = model.PackageDimension.Length.Unit;
                        product.PkgWeight     = model.PackageDimension.Weight.Value;
                        product.PkgWeightUnit = model.PackageDimension.Weight.Unit;
                    }

                    // set the EIS product Item's dimension
                    if (model.ItemDimension != null)
                    {
                        product.ItemLength     = model.ItemDimension.Length.Value;
                        product.ItemWidth      = model.ItemDimension.Width.Value;
                        product.ItemHeight     = model.ItemDimension.Height.Value;
                        product.ItemLenghtUnit = model.ItemDimension.Length.Unit;
                        product.ItemWeight     = model.ItemDimension.Weight.Value;
                        product.ItemWeightUnit = model.ItemDimension.Weight.Unit;
                    }

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

                    // save the changes
                    context.SaveChanges();
                }
            }
            catch (DbEntityValidationException ex)
            {
                var errorMsg = EisHelper.ParseDbEntityValidationException(ex);
                _logger.LogError(LogEntryType.AmazonGetInfoWorker, errorMsg, ex.StackTrace);
            }
            catch (Exception ex)
            {
                _logger.LogError(LogEntryType.AmazonGetInfoWorker,
                                 string.Format("Error in updating Amazon product details -> EisSKU: {0} <br/>Error message: {1}",
                                               model.EisSKU, EisHelper.GetExceptionMessage(ex)));
            }
        }
Пример #13
0
        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);
        }
Пример #14
0
        public int DoUpadateOrInsertProduct(Product model, bool isUpdate, string submittedBy)
        {
            using (var context = new EisInventoryContext())
            {
                if (isUpdate)
                {
                    // get the exising product from db
                    var product = context.products.FirstOrDefault(x => x.EisSKU == model.EisSKU);
                    if (product == null)
                    {
                        return(0);
                    }

                    // let's update its data except for Products.Name
                    if (model.Description != null)
                    {
                        product.Description = model.Description;
                    }
                    if (model.ShortDescription != null)
                    {
                        product.ShortDescription = model.ShortDescription;
                    }
                    if (model.Category != null)
                    {
                        product.Category = model.Category;
                    }
                    if (model.isSellerPriceSet)
                    {
                        product.SellerPrice = model.SellerPrice;
                    }
                    if (model.PkgLength != null)
                    {
                        product.PkgLength = model.PkgLength;
                    }
                    if (model.PkgWidth != null)
                    {
                        product.PkgWidth = model.PkgWidth;
                    }
                    if (model.PkgHeight != null)
                    {
                        product.PkgHeight = model.PkgHeight;
                    }
                    if (model.PkgLenghtUnit != null)
                    {
                        product.PkgLenghtUnit = model.PkgLenghtUnit;
                    }
                    if (model.PkgWeight != null)
                    {
                        product.PkgWeight = model.PkgWeight;
                    }
                    if (model.PkgWeightUnit != null)
                    {
                        product.PkgWeightUnit = model.PkgWeightUnit;
                    }
                    if (model.ItemLength != null)
                    {
                        product.ItemLength = model.ItemLength;
                    }
                    if (model.ItemWidth != null)
                    {
                        product.ItemWidth = model.ItemWidth;
                    }
                    if (model.ItemHeight != null)
                    {
                        product.ItemHeight = model.ItemHeight;
                    }
                    if (model.ItemLenghtUnit != null)
                    {
                        product.ItemLenghtUnit = model.ItemLenghtUnit;
                    }
                    if (model.ItemWeight != null)
                    {
                        product.ItemWeight = model.ItemWeight;
                    }
                    if (model.ItemWeightUnit != null)
                    {
                        product.ItemWeightUnit = model.ItemWeightUnit;
                    }
                    if (model.GuessedWeight != null)
                    {
                        product.GuessedWeight = model.GuessedWeight;
                    }
                    if (model.AccurateWeight != null)
                    {
                        product.AccurateWeight = model.AccurateWeight;
                    }
                    if (model.GuessedWeightUnit != null)
                    {
                        product.GuessedWeightUnit = model.GuessedWeightUnit;
                    }
                    if (model.AccurateWeightUnit != null)
                    {
                        product.AccurateWeightUnit = model.AccurateWeightUnit;
                    }
                    if (model.GuessedShipping != null)
                    {
                        product.GuessedShipping = model.GuessedShipping;
                    }
                    if (model.AccurateShipping != null)
                    {
                        product.AccurateShipping = model.AccurateShipping;
                    }
                    if (model.isCompanySet)
                    {
                        product.CompanyId = model.CompanyId;
                    }
                    if (model.isKitSet)
                    {
                        product.IsKit = model.IsKit;
                    }
                    if (model.isBlacklistedSet)
                    {
                        product.IsBlacklisted = model.IsBlacklisted;
                    }
                    if (model.isSkuTypeSet)
                    {
                        product.SkuType = model.SkuType;
                    }

                    // Only upate UPC if this is a Normal product
                    if (model.UPC != null && product.SkuType == SkuType.Normal)
                    {
                        product.UPC = model.UPC;

                        // let's check if the product has shadow products
                        var shadows = context.shadows.Where(x => x.ParentSKU == model.EisSKU).ToList();
                        foreach (var shadow in shadows)
                        {
                            // get the shadow product details
                            var shadowProduct = context.products.FirstOrDefault(x => x.EisSKU == shadow.ShadowSKU);
                            shadowProduct.UPC        = model.UPC;
                            shadowProduct.ModifiedBy = submittedBy;
                            shadowProduct.Modified   = DateTime.UtcNow;
                        }
                    }

                    product.ModifiedBy = submittedBy;
                    product.Modified   = DateTime.UtcNow;
                }
                else
                {
                    // add first the product item
                    context.products.Add(new product {
                        EisSKU           = model.EisSKU,
                        CompanyId        = model.CompanyId,
                        Name             = model.Name,
                        Description      = model.Description,
                        ShortDescription = model.ShortDescription,
                        Category         = model.Category,
                        ProductTypeId    = model.ProductTypeId,
                        UPC                = model.UPC,
                        SellerPrice        = model.SellerPrice,
                        PkgLength          = model.PkgLength,
                        PkgWidth           = model.PkgWidth,
                        PkgHeight          = model.PkgHeight,
                        PkgLenghtUnit      = model.PkgLenghtUnit,
                        PkgWeight          = model.PkgWeight,
                        PkgWeightUnit      = model.PkgWeightUnit,
                        ItemLength         = model.ItemLength,
                        ItemWidth          = model.ItemWidth,
                        ItemHeight         = model.ItemHeight,
                        ItemLenghtUnit     = model.ItemLenghtUnit,
                        ItemWeight         = model.ItemWeight,
                        ItemWeightUnit     = model.ItemWeightUnit,
                        EAN                = model.EAN,
                        Brand              = model.Brand,
                        Color              = model.Color,
                        Model              = model.Model_,
                        GuessedWeight      = model.GuessedWeight,
                        GuessedWeightUnit  = model.GuessedWeightUnit,
                        AccurateWeight     = model.AccurateWeight,
                        AccurateWeightUnit = model.AccurateWeightUnit,
                        GuessedShipping    = model.GuessedShipping,
                        AccurateShipping   = model.AccurateShipping,
                        IsKit              = model.IsKit,
                        IsBlacklisted      = model.IsBlacklisted,
                        SkuType            = model.SkuType,
                        CreatedBy          = submittedBy,
                        Created            = DateTime.UtcNow
                    });
                }

                // save the change first to the product
                context.SaveChanges();

                // download and update product images
                UpdateProductImages(model.Images, model.EisSKU);

                return(1);
            }
        }
Пример #15
0
        public void DoInsertOrupdateOrder(MarketplaceOrder marketplaceOrder)
        {
            try
            {
                using (var context = new EisInventoryContext())
                {
                    // check if this order alreaady exist
                    var order = context.orders.FirstOrDefault(x => x.OrderId == marketplaceOrder.OrderId);
                    if (order == null)
                    {
                        var eisOrderId = getMaxEisOrderId() + 1;
                        context.orders.Add(new order
                        {
                            EisOrderId              = eisOrderId,
                            OrderId                 = marketplaceOrder.OrderId,
                            Marketplace             = marketplaceOrder.Marketplace,
                            OrderTotal              = marketplaceOrder.OrderTotal,
                            NumOfItemsShipped       = (int)marketplaceOrder.NumOfItemsShipped,
                            NumOfItemsUnshipped     = (int)marketplaceOrder.NumOfItemsUnshipped,
                            OrderStatus             = marketplaceOrder.OrderStatus,
                            PurchaseDate            = marketplaceOrder.PurchaseDate,
                            LastUpdateDate          = marketplaceOrder.LastUpdateDate,
                            PaymentMethod           = marketplaceOrder.PaymentMethod,
                            BuyerName               = marketplaceOrder.BuyerName,
                            BuyerEmail              = marketplaceOrder.BuyerEmail,
                            ShippingAddressPhone    = marketplaceOrder.ShippingAddressPhone,
                            ShippingAddressName     = marketplaceOrder.ShippingAddressName,
                            ShippingAddressLine1    = marketplaceOrder.ShippingAddressLine1,
                            ShippingAddressLine2    = marketplaceOrder.ShippingAddressLine2,
                            ShippingAddressLine3    = marketplaceOrder.ShippingAddressLine3,
                            ShippingCity            = marketplaceOrder.ShippingCity,
                            ShippingStateOrRegion   = marketplaceOrder.ShippingStateOrRegion,
                            ShippingPostalCode      = marketplaceOrder.ShippingPostalCode,
                            ShipServiceLevel        = marketplaceOrder.ShipServiceLevel,
                            ShipmentServiceCategory = marketplaceOrder.ShipmentServiceCategory,
                            EarliestShipDate        = marketplaceOrder.EarliestShipDate,
                            LatestShipDate          = marketplaceOrder.LatestShipDate,
                            EarliestDeliveryDate    = marketplaceOrder.EarliestDeliveryDate,
                            LatestDeliveryDate      = marketplaceOrder.LatestDeliveryDate,
                            OrderType               = marketplaceOrder.OrderType,
                            SellerOrderId           = marketplaceOrder.SellerOrderId,
                            MarketplaceId           = marketplaceOrder.MarketplaceId,
                            PurchaseOrderNumber     = marketplaceOrder.PurchaseOrderNumber,
                            SalesChannel            = marketplaceOrder.SalesChannel,
                            AdjustmentAmount        = marketplaceOrder.AdjustmentAmount,
                            AmountPaid              = marketplaceOrder.AmountPaid,
                            PaymentOrRefundAmount   = marketplaceOrder.PaymentOrRefundAmount,
                            PaymentStatus           = 1,
                            OrderNote               = null,
                            Created                 = DateTime.UtcNow
                        });
                    }
                    else
                    {
                        order.Marketplace             = marketplaceOrder.Marketplace;
                        order.OrderTotal              = marketplaceOrder.OrderTotal;
                        order.NumOfItemsShipped       = (int)marketplaceOrder.NumOfItemsShipped;
                        order.NumOfItemsUnshipped     = (int)marketplaceOrder.NumOfItemsUnshipped;
                        order.OrderStatus             = marketplaceOrder.OrderStatus;
                        order.PurchaseDate            = marketplaceOrder.PurchaseDate;
                        order.LastUpdateDate          = marketplaceOrder.LastUpdateDate;
                        order.PaymentMethod           = marketplaceOrder.PaymentMethod;
                        order.BuyerName               = marketplaceOrder.BuyerName;
                        order.BuyerEmail              = marketplaceOrder.BuyerEmail;
                        order.ShippingAddressPhone    = marketplaceOrder.ShippingAddressPhone;
                        order.ShippingAddressName     = marketplaceOrder.ShippingAddressName;
                        order.ShippingAddressLine1    = marketplaceOrder.ShippingAddressLine1;
                        order.ShippingAddressLine2    = marketplaceOrder.ShippingAddressLine2;
                        order.ShippingAddressLine3    = marketplaceOrder.ShippingAddressLine3;
                        order.ShippingCity            = marketplaceOrder.ShippingCity;
                        order.ShippingStateOrRegion   = marketplaceOrder.ShippingStateOrRegion;
                        order.ShippingPostalCode      = marketplaceOrder.ShippingPostalCode;
                        order.ShipServiceLevel        = marketplaceOrder.ShipServiceLevel;
                        order.ShipmentServiceCategory = marketplaceOrder.ShipmentServiceCategory;
                        order.EarliestShipDate        = marketplaceOrder.EarliestShipDate;
                        order.LatestShipDate          = marketplaceOrder.LatestShipDate;
                        order.EarliestDeliveryDate    = marketplaceOrder.EarliestDeliveryDate;
                        order.LatestDeliveryDate      = marketplaceOrder.LatestDeliveryDate;
                        order.OrderType               = marketplaceOrder.OrderType;
                        order.SellerOrderId           = marketplaceOrder.SellerOrderId;
                        order.MarketplaceId           = marketplaceOrder.MarketplaceId;
                        order.PurchaseOrderNumber     = marketplaceOrder.PurchaseOrderNumber;
                        order.SalesChannel            = marketplaceOrder.SalesChannel;
                        order.AdjustmentAmount        = marketplaceOrder.AdjustmentAmount;
                        order.AmountPaid              = marketplaceOrder.AmountPaid;
                        order.PaymentOrRefundAmount   = marketplaceOrder.PaymentOrRefundAmount;
                        order.PaymentStatus           = 1;
                        order.OrderNote               = null;
                        order.Created = DateTime.UtcNow;
                    }

                    // save the chagnes
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error occured on order id: {0} \nError Message: {1} \n{2} ", marketplaceOrder.OrderId, ex.Message, ex.StackTrace);
                _logger.LogError(LogEntryType.OrderService,
                                 string.Format("Error occured in creating or updating order id {0} to DB <br/>Error message: {1}",
                                               marketplaceOrder.OrderId,
                                               EisHelper.GetExceptionMessage(ex)), ex.StackTrace);
            }
        }
Пример #16
0
 public ReportTemplateService(ILogService logger)
 {
     _context          = new EisInventoryContext();
     _logger           = logger;
     _connectionString = ConfigurationManager.ConnectionStrings["InventoryConnection"].ConnectionString;
 }
Пример #17
0
 public ProfitProcessor()
 {
     _context = new EisInventoryContext();
 }
 public BigCommerceProductProvider()
 {
     _context = new EisInventoryContext();
     _logger  = Core.Get <ILogService>();
 }
Пример #19
0
        private void persistOrderItems(List <PurchaseOrderItem> orders)
        {
            // write order items to the file and insert it into the database
            if (!orders.Any())
            {
                Logger.LogInfo(LogEntryType.GeneratePoTaskService, "No purchase orders to be generatated for task name: " + _task.Name);
                return;
            }

            // get the purchase order details
            _purchaseOrder                 = initPoVendorInfo(_task.VendorId);
            _purchaseOrder.Items           = orders;
            _purchaseOrder.PurchaseOrderId = string.Format("{0:MM}{0:dd}{0:yy}-{0:hh}{0:mm}{0:ss}", DateTime.UtcNow);

            using (var streamWriter = new StreamWriter(_generatedFile))
            {
                using (var context = new EisInventoryContext())
                {
                    var csvWriter = new CsvWriter(streamWriter);

                    // write first the headers for the CSV file
                    csvWriter.WriteField("PurchaseOrderId");
                    csvWriter.WriteField("EisOrderId");
                    csvWriter.WriteField("SKU");
                    csvWriter.WriteField("Item");
                    csvWriter.WriteField("Quantity");
                    csvWriter.WriteField("Subtotal");
                    csvWriter.WriteField("VendorFees");
                    csvWriter.WriteField("PurchaseDate");
                    csvWriter.NextRecord();

                    // add first the purchase order data
                    context.purchaseorders.Add(new purchaseorder
                    {
                        Id            = _purchaseOrder.PurchaseOrderId,
                        VendorId      = _purchaseOrder.VendorId,
                        IsManual      = false,
                        PaymentStatus = PaymentStatus.NotPaid,
                        Created       = DateTime.UtcNow
                    });

                    // and save it
                    context.SaveChanges();

                    // iterate to its orders and save it to the database
                    foreach (var order in orders)
                    {
                        // write first to the file
                        csvWriter.WriteField(_purchaseOrder.PurchaseOrderId);
                        csvWriter.WriteField(order.EisOrderId);
                        csvWriter.WriteField(order.SupplierSKU);
                        csvWriter.WriteField(order.ItemName);
                        csvWriter.WriteField(order.SupplierQtyOrdered);
                        csvWriter.WriteField(order.Total);
                        csvWriter.WriteField(order.VendorFees);
                        csvWriter.WriteField(order.PurchaseDate);
                        csvWriter.NextRecord();

                        // then, add it to the database
                        context.purchaseorderitems.Add(new purchaseorderitem
                        {
                            PurchaseOrderId = _purchaseOrder.PurchaseOrderId,
                            EisOrderId      = order.EisOrderId,
                            ItemName        = order.ItemName,
                            SKU             = order.SupplierSKU,
                            Qty             = order.SupplierQtyOrdered,
                            UnitPrice       = order.UnitPrice,
                            ShippingPrices  = order.ShippingPrices,
                            Taxes           = order.Taxes,
                            Discounts       = order.Discounts,
                            IsPaid          = order.IsPaid,
                            Profit          = order.Profit
                        });
                    }

                    // save it to the database
                    context.SaveChanges();
                }
            }

            Console.WriteLine("Done creating PO file -> " + _generatedFile);
        }
Пример #20
0
 public KitService()
 {
     _context = new EisInventoryContext();
 }
Пример #21
0
 public OrderGroupService()
 {
     _context = new EisInventoryContext();
 }
Пример #22
0
 public CustomerService(IFileHelper fileHelper, ILogService logger)
 {
     _fileHelper = fileHelper;
     _logger     = logger;
     _context    = new EisInventoryContext();
 }
Пример #23
0
 public VendorProductLinkService(ILogService logger)
 {
     _logger  = logger;
     _context = new EisInventoryContext();
 }
Пример #24
0
 public CompanyService(ILogService logger)
 {
     _logger  = logger;
     _context = new EisInventoryContext();
 }
Пример #25
0
 public ShippingService(ILogService logger)
 {
     _logger  = logger;
     _context = new EisInventoryContext();
 }
Пример #26
0
        private bool doInsertOrUpdateProduct(Shadow shadow, bool isCreate)
        {
            using (var context = new EisInventoryContext())
            {
                // let's check first if Shadow's ParentSKU exist
                var parentProduct = context.products.FirstOrDefault(x => x.EisSKU == shadow.ParentSKU);
                if (parentProduct == null)
                {
                    _logger.LogWarning(LogEntryType.ShadowFileUploadWorker,
                                       string.Format("Parent SKU \"{0}\" for Shadow product \"{1}\" does not exist from the EIS products.",
                                                     shadow.ParentSKU, shadow.ShadowSKU));
                    return(false);
                }

                // create new product if it doesn't exist to database
                var shadowProduct = context.products.FirstOrDefault(x => x.EisSKU == shadow.ShadowSKU);
                if (shadowProduct == null)
                {
                    if (isCreate == false)
                    {
                        return(false);
                    }
                    // create shadow product based on its parent Product details
                    context.products.Add(new product
                    {
                        EisSKU           = shadow.ShadowSKU,
                        CompanyId        = parentProduct.CompanyId,
                        Name             = parentProduct.Name,
                        Description      = parentProduct.Description,
                        ShortDescription = parentProduct.ShortDescription,
                        Category         = parentProduct.Category,
                        ProductTypeId    = parentProduct.ProductTypeId,
                        UPC            = parentProduct.UPC,
                        SellerPrice    = parentProduct.SellerPrice,
                        PkgLength      = parentProduct.PkgLength,
                        PkgWidth       = parentProduct.PkgWidth,
                        PkgHeight      = parentProduct.PkgHeight,
                        PkgLenghtUnit  = parentProduct.PkgLenghtUnit,
                        PkgWeight      = parentProduct.PkgWeight,
                        PkgWeightUnit  = parentProduct.PkgWeightUnit,
                        ItemLength     = parentProduct.ItemLength,
                        ItemWidth      = parentProduct.ItemWidth,
                        ItemHeight     = parentProduct.ItemHeight,
                        ItemLenghtUnit = parentProduct.ItemLenghtUnit,
                        ItemWeight     = parentProduct.ItemWeight,
                        ItemWeightUnit = parentProduct.ItemWeightUnit,
                        EAN            = parentProduct.EAN,
                        Brand          = parentProduct.Brand,
                        Color          = parentProduct.Color,
                        Model          = parentProduct.Model,
                        // exclude these data for copying shadows GuessedWeight, AccurateWeight, GuessedShipping, AccurateShipping and its Units
                        IsKit         = false,
                        IsBlacklisted = parentProduct.IsBlacklisted,
                        SkuType       = SkuType.Shadow,
                        CreatedBy     = _systemJob.SubmittedBy,
                        Created       = DateTime.UtcNow
                    });
                }
                else
                {
                    // let's update its sku type; just to ensure that this is really a shadow product
                    shadowProduct.SkuType    = SkuType.Shadow;
                    shadowProduct.ModifiedBy = _systemJob.SubmittedBy;
                    shadowProduct.Modified   = DateTime.UtcNow;
                }

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

                return(true);
            }
        }
Пример #27
0
 public ProductGroupService()
 {
     _context = new EisInventoryContext();
 }
Пример #28
0
        /// <summary>
        /// Insert new record or update for order item into database
        /// </summary>
        /// <param name="item">The record of order item to save to database</param>
        public void DoInsertOrUpdateOrderItem(MarketplaceOrderItem item)
        {
            try
            {
                using (var context = new EisInventoryContext())
                {
                    // check if there is existing order item
                    var orderItem = context.orderitems
                                    .FirstOrDefault(x => x.OrderItemId == item.OrderItemId && x.OrderId == item.OrderId);

                    if (orderItem == null)
                    {
                        context.orderitems.Add(new orderitem
                        {
                            OrderItemId       = item.OrderItemId,
                            OrderId           = item.OrderId,
                            ItemId            = item.MarketplaceItemId,
                            SKU               = item.SKU,
                            Title             = item.Title,
                            QtyOrdered        = item.QtyOrdered,
                            QtyShipped        = item.QtyShipped,
                            Price             = item.Price,
                            ShippingPrice     = item.ShippingPrice,
                            GiftWrapPrice     = item.GiftWrapPrice,
                            ItemTax           = item.Tax,
                            ShippingTax       = item.ShippingTax,
                            GiftWrapTax       = item.GiftWrapTax,
                            ShippingDiscount  = item.ShippingDiscount,
                            PromotionDiscount = item.PromotionDiscount,
                            ConditionNote     = item.ConditionNote,
                        });
                    }
                    else
                    {
                        orderItem.ItemId            = item.MarketplaceItemId;
                        orderItem.SKU               = item.SKU;
                        orderItem.Title             = item.Title;
                        orderItem.QtyOrdered        = item.QtyOrdered;
                        orderItem.QtyShipped        = item.QtyShipped;
                        orderItem.Price             = item.Price;
                        orderItem.ShippingPrice     = item.ShippingPrice;
                        orderItem.GiftWrapPrice     = item.GiftWrapPrice;
                        orderItem.ItemTax           = item.Tax;
                        orderItem.ShippingTax       = item.ShippingTax;
                        orderItem.GiftWrapTax       = item.GiftWrapTax;
                        orderItem.ShippingDiscount  = item.ShippingDiscount;
                        orderItem.PromotionDiscount = item.PromotionDiscount;
                        orderItem.ConditionNote     = item.ConditionNote;
                    }

                    // save the changes
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error occured on order item id: {0} \nError Message: {1} \n{2} ", item.OrderItemId, ex.Message, ex.StackTrace);
                _logger.LogError(LogEntryType.OrderService,
                                 string.Format("Error occured in inserting or creating order item {0} and order id {1} to DB <br/>Error message: {2}",
                                               item.OrderItemId,
                                               item.OrderId,
                                               EisHelper.GetExceptionMessage(ex)),
                                 ex.StackTrace);
            }
        }
Пример #29
0
 public CustomerScheduledTaskService()
 {
     _context = new EisInventoryContext();
 }
Пример #30
0
        public int DoUpdateOrInsertAmazon(ProductAmazon model, string submittedBy)
        {
            using (var context = new EisInventoryContext())
            {
                // check if the bigcommerce product already exists
                var product = context.productamazons.FirstOrDefault(x => x.EisSKU == model.EisSKU);

                // create new item if it doesn't exists
                if (product == null)
                {
                    var domain = Mapper.Map <productamazon>(model);
                    domain.CreatedBy = submittedBy;
                    domain.Created   = DateTime.UtcNow;
                    context.productamazons.Add(domain);
                }
                else
                {
                    if (!string.IsNullOrEmpty(model.ASIN))
                    {
                        product.ASIN = model.ASIN;
                    }
                    if (model.Price != null)
                    {
                        product.Price = model.Price;
                    }
                    if (model.LeadtimeShip != null)
                    {
                        product.LeadtimeShip = model.LeadtimeShip;
                    }
                    if (model.PackageQty != null)
                    {
                        product.PackageQty = model.PackageQty;
                    }
                    if (model.NumOfItems != null)
                    {
                        product.NumOfItems = model.NumOfItems;
                    }
                    if (model.MaxOrderQty != null)
                    {
                        product.MaxOrderQty = model.MaxOrderQty;
                    }
                    if (model.ProductTitle != null)
                    {
                        product.ProductTitle = model.ProductTitle;
                    }
                    if (model.MapPrice != 0)
                    {
                        product.MapPrice = model.MapPrice;
                    }
                    if (model.isAllowGiftWrapSet)
                    {
                        product.IsAllowGiftWrap = model.IsAllowGiftWrap;
                    }
                    if (model.isAllowGiftMsgSet)
                    {
                        product.IsAllowGiftMsg = model.IsAllowGiftMsg;
                    }
                    if (model.Condition != null)
                    {
                        product.Condition = model.Condition;
                    }
                    if (model.ConditionNote != null)
                    {
                        product.ConditionNote = model.ConditionNote;
                    }
                    if (model.FulfilledBy != null)
                    {
                        product.FulfilledBy = model.FulfilledBy;
                    }
                    if (model.FbaSKU != null)
                    {
                        product.FbaSKU = model.FbaSKU;
                    }
                    if (model.isEnabledSet)
                    {
                        product.IsEnabled = model.IsEnabled;
                    }
                    if (!string.IsNullOrEmpty(model.ProductGroup))
                    {
                        product.ProductGroup = model.ProductGroup;
                    }
                    if (model.ProductTypeName != null)
                    {
                        product.ProductTypeName = model.ProductTypeName;
                    }
                    if (model.TaxCode != null)
                    {
                        product.TaxCode = model.TaxCode;
                    }
                    //if (model.WeightBox1 != null) product.WeightBox1 = model.WeightBox1;
                    //if (!string.IsNullOrEmpty(model.WeightBox1Unit)) product.WeightBox1Unit = model.WeightBox1Unit;
                    //if (model.WeightBox2 != null) product.WeightBox2 = model.WeightBox2;
                    //if (!string.IsNullOrEmpty(model.WeightBox2Unit)) product.WeightBox2Unit = model.WeightBox2Unit;

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

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

            return(1);
        }