Example #1
0
 /// <summary>
 /// Gets the catalog entry dto.
 /// </summary>
 /// <param name="catalogEntryCode">The catalog entry code.</param>
 /// <returns></returns>
 public CatalogEntryDto GetCatalogEntryDto(string catalogEntryCode)
 {
     return(CatalogEntryManager.GetCatalogEntryDto(catalogEntryCode, new CatalogEntryResponseGroup()));
 }
Example #2
0
 /// <summary>
 /// Gets the catalog entry dto.
 /// </summary>
 /// <param name="catalogEntryCode">The catalog entry code.</param>
 /// <param name="responseGroup">The response group.</param>
 /// <returns></returns>
 public CatalogEntryDto GetCatalogEntryDto(string catalogEntryCode, CatalogEntryResponseGroup responseGroup)
 {
     return(CatalogEntryManager.GetCatalogEntryDto(catalogEntryCode, responseGroup));
 }
Example #3
0
 /// <summary>
 /// Gets the catalog entry dto.
 /// </summary>
 /// <param name="catalogEntryId">The catalog entry id.</param>
 /// <returns></returns>
 public CatalogEntryDto GetCatalogEntryDto(int catalogEntryId)
 {
     return(CatalogEntryManager.GetCatalogEntryDto(catalogEntryId, new CatalogEntryResponseGroup()));
 }
Example #4
0
 /// <summary>
 /// Gets the catalog entry dto.
 /// </summary>
 /// <param name="catalogEntryId">The catalog entry id.</param>
 /// <param name="responseGroup">The response group.</param>
 /// <returns></returns>
 public CatalogEntryDto GetCatalogEntryDto(int catalogEntryId, CatalogEntryResponseGroup responseGroup)
 {
     return(CatalogEntryManager.GetCatalogEntryDto(catalogEntryId, responseGroup));
 }
        protected override int CreateSystemRow(FillDataMode Mode, int RowIndex, params object[] Item)
        {
            int    i = 0;
            object objSysRowAction = Item[i++];
            object objCode         = Item[i++];
            //Variation
            object objListPrice      = Item[i++];
            object objTaxCategoryId  = Item[i++];
            object objTrackInventory = Item[i++];
            object objMerchantId     = Item[i++];
            object objWarehouseId    = Item[i++];
            object objWeight         = Item[i++];
            object objPackageId      = Item[i++];
            object objMinQuantity    = Item[i++];
            object objMaxQuantity    = Item[i++];
            //Inventory
            object objInStockQuantity           = Item[i++];
            object objReservedQuantity          = Item[i++];
            object objReorderMinQuantity        = Item[i++];
            object objPreorderQuantity          = Item[i++];
            object objBackorderQuantity         = Item[i++];
            object objAllowBackorder            = Item[i++];
            object objAllowPreorder             = Item[i++];
            object objInventoryStatus           = Item[i++];
            object objPreorderAvailabilityDate  = Item[i++];
            object objBackorderAvailabilityDate = Item[i++];

            CatalogEntryDto.VariationRow variationRow = null;
            CatalogEntryDto.InventoryRow inventoryRow = null;

            try
            {
                RowAction sysRowAction = RowAction.Default;

                if (objSysRowAction != null)
                {
                    sysRowAction = GetRowActionEnum((string)objSysRowAction);
                }

                string Code;
                if (objCode != null)
                {
                    Code = (string)objCode;
                }
                else
                {
                    throw new AbsentValue("Code");
                }

                bool            bVariationIsNew = false;
                bool            bInventoryIsNew = false;
                CatalogEntryDto catalogEntryDto = CatalogEntryManager.GetCatalogEntryDto(Code, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
                if (catalogEntryDto.CatalogEntry.Count > 0)
                {
                    CatalogEntryDto.CatalogEntryRow entry = catalogEntryDto.CatalogEntry[0];
                    if (entry.ClassTypeId.Equals(EntryType.Variation, StringComparison.OrdinalIgnoreCase) ||
                        entry.ClassTypeId.Equals(EntryType.Package, StringComparison.OrdinalIgnoreCase))
                    {
                        if (catalogEntryDto.Variation.Count > 0)
                        {
                            if (sysRowAction == RowAction.Insert)
                            {
                                throw new MDPImportException(String.Format("The Variation with with Entry Code '{0}' already exists.", Code));
                            }

                            variationRow = catalogEntryDto.Variation[0];

                            if (sysRowAction == RowAction.Delete)
                            {
                                variationRow.Delete();
                            }
                        }
                        else
                        {
                            if (sysRowAction == RowAction.Update)
                            {
                                throw new MDPImportException(String.Format("The Variation with with Entry Code '{0}' does not exists.", Code));
                            }

                            if (sysRowAction == RowAction.Delete)
                            {
                                throw new MDPImportException(String.Format("The Variation with with Entry Code '{0}' does not exists.", Code));
                            }

                            variationRow = catalogEntryDto.Variation.NewVariationRow();
                            variationRow.CatalogEntryId = entry.CatalogEntryId;
                            variationRow.ListPrice      = 0;
                            variationRow.TaxCategoryId  = 0;
                            variationRow.TrackInventory = false;
                            variationRow.WarehouseId    = 0;
                            variationRow.Weight         = 1;
                            variationRow.PackageId      = 0;
                            variationRow.MinQuantity    = 1;
                            variationRow.MaxQuantity    = 100;
                            bVariationIsNew             = true;
                        }

                        if (catalogEntryDto.Inventory.Count > 0)
                        {
                            if (sysRowAction == RowAction.Insert)
                            {
                                throw new MDPImportException(String.Format("The Inventory with with Entry Code '{0}' already exists.", Code));
                            }

                            inventoryRow = catalogEntryDto.Inventory[0];

                            if (sysRowAction == RowAction.Delete)
                            {
                                inventoryRow.Delete();
                            }
                        }
                        else
                        {
                            if (sysRowAction == RowAction.Update)
                            {
                                throw new MDPImportException(String.Format("The Inventory with with Entry Code '{0}' does not exists.", Code));
                            }

                            if (sysRowAction == RowAction.Delete)
                            {
                                throw new MDPImportException(String.Format("The Inventory with with Entry Code '{0}' does not exists.", Code));
                            }

                            inventoryRow = catalogEntryDto.Inventory.NewInventoryRow();
                            inventoryRow.ApplicationId             = CatalogConfiguration.Instance.ApplicationId;
                            inventoryRow.SkuId                     = entry.Code;
                            inventoryRow.InStockQuantity           = 10;
                            inventoryRow.ReservedQuantity          = 2;
                            inventoryRow.ReorderMinQuantity        = 1;
                            inventoryRow.PreorderQuantity          = 10;
                            inventoryRow.BackorderQuantity         = 10;
                            inventoryRow.AllowBackorder            = false;
                            inventoryRow.AllowPreorder             = false;
                            inventoryRow.InventoryStatus           = 0;
                            inventoryRow.PreorderAvailabilityDate  = DateTime.UtcNow;
                            inventoryRow.BackorderAvailabilityDate = DateTime.UtcNow;
                            bInventoryIsNew = true;
                        }
                    }
                    else
                    {
                        throw new MDPImportException(String.Format("The Entry with code '{0}' has wrong type ('{1}') for Variation/Inventory import.", Code, entry.ClassTypeId));
                    }
                }
                else
                {
                    throw new MDPImportException(String.Format("The Entry with code '{0}' does not exists.", Code));
                }

                if (sysRowAction == RowAction.Delete)
                {
                    CatalogContext.Current.SaveCatalogEntry(catalogEntryDto);
                    return(0);
                }

                //Variation
                if (objListPrice != null)
                {
                    decimal ListPrice = (decimal)objListPrice;
                    variationRow.ListPrice = ListPrice;
                }

                if (objTaxCategoryId != null)
                {
                    variationRow.TaxCategoryId = GetTaxCategoryId((string)objTaxCategoryId);
                }

                if (objTrackInventory != null)
                {
                    variationRow.TrackInventory = (bool)objTrackInventory;
                }

                if (objMerchantId != null)
                {
                    Guid merchantId = GetMerchantId((string)objMerchantId);
                    if (merchantId != Guid.Empty)
                    {
                        variationRow.MerchantId = merchantId;
                    }
                }

                if (objWarehouseId != null)
                {
                    variationRow.WarehouseId = GetWarehouseId((string)objWarehouseId);
                }

                if (objWeight != null)
                {
                    variationRow.Weight = (double)objWeight;
                }

                if (objPackageId != null)
                {
                    variationRow.PackageId = GetPackageId((string)objPackageId);
                }

                if (objMinQuantity != null)
                {
                    variationRow.MinQuantity = (decimal)objMinQuantity;
                }

                if (objMaxQuantity != null)
                {
                    variationRow.MaxQuantity = (decimal)objMaxQuantity;
                }

                if (bVariationIsNew)
                {
                    catalogEntryDto.Variation.AddVariationRow(variationRow);
                }

                //Inventory
                if (objInStockQuantity != null)
                {
                    inventoryRow.InStockQuantity = (decimal)objInStockQuantity;
                }

                if (objReservedQuantity != null)
                {
                    inventoryRow.ReservedQuantity = (decimal)objReservedQuantity;
                }

                if (objReorderMinQuantity != null)
                {
                    inventoryRow.ReorderMinQuantity = (decimal)objReorderMinQuantity;
                }

                if (objPreorderQuantity != null)
                {
                    inventoryRow.PreorderQuantity = (decimal)objPreorderQuantity;
                }

                if (objBackorderQuantity != null)
                {
                    inventoryRow.BackorderQuantity = (decimal)objBackorderQuantity;
                }

                if (objAllowBackorder != null)
                {
                    inventoryRow.AllowBackorder = (bool)objAllowBackorder;
                }

                if (objAllowPreorder != null)
                {
                    inventoryRow.AllowPreorder = (bool)objAllowPreorder;
                }

                if (objInventoryStatus != null)
                {
                    inventoryRow.InventoryStatus = (int)objInventoryStatus;
                }

                if (objPreorderAvailabilityDate != null)
                {
                    inventoryRow.PreorderAvailabilityDate = ((DateTime)objPreorderAvailabilityDate).ToUniversalTime();
                }

                if (objBackorderAvailabilityDate != null)
                {
                    inventoryRow.BackorderAvailabilityDate = ((DateTime)objBackorderAvailabilityDate).ToUniversalTime();
                }

                if (bInventoryIsNew)
                {
                    catalogEntryDto.Inventory.AddInventoryRow(inventoryRow);
                }



                using (TransactionScope tx = new TransactionScope())
                {
                    // Save modifications
                    if (catalogEntryDto.HasChanges())
                    {
                        CatalogContext.Current.SaveCatalogEntry(catalogEntryDto);
                    }

                    tx.Complete();
                }
            }
            catch (Exception ex)
            {
                throw new MDPImportException(ex.Message, null, RowIndex, null, null, Item);
            }

            return(variationRow.CatalogEntryId);
        }
Example #6
0
        protected override int CreateSystemRow(FillDataMode mode, int RowIndex, params object[] item)
        {
            int    i = 0;
            object objSysRowAction = item[i++];
            //Entry
            object objCode          = item[i++];
            object objName          = item[i++];
            object objClassTypeId   = item[i++];
            object objStartDate     = item[i++];
            object objEndDate       = item[i++];
            object objTemplateName  = item[i++];
            object objIsActive      = item[i++];
            object objCategoryCodes = item[i++];
            object objSortOrder     = item[i++];
            //SEO
            object objSeoTitle       = item[i++];
            object objSeoUrl         = item[i++];
            object objSeoDescription = item[i++];
            object objSeoKeywords    = item[i++];

            CatalogEntryDto.CatalogEntryRow entryRow = null;

            try
            {
                RowAction sysRowAction = RowAction.Default;

                if (objSysRowAction != null)
                {
                    sysRowAction = GetRowActionEnum((string)objSysRowAction);
                }

                string code;
                if (objCode != null)
                {
                    code = (string)objCode;
                }
                else
                {
                    throw new AbsentValue("Code");
                }

                bool            bIsNew          = false;
                CatalogEntryDto catalogEntryDto = CatalogEntryManager.GetCatalogEntryDto(code, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
                if (catalogEntryDto.CatalogEntry.Count > 0)
                {
                    if (sysRowAction == RowAction.Insert)
                    {
                        throw new MDPImportException(String.Format("The Entry with code '{0}' already exists.", code));
                    }

                    entryRow = catalogEntryDto.CatalogEntry[0];

                    if (sysRowAction == RowAction.Delete)
                    {
                        CatalogContext.Current.DeleteCatalogEntry(entryRow.CatalogEntryId, true);
                        return(0);
                    }
                }
                else
                {
                    if (sysRowAction == RowAction.Update)
                    {
                        throw new MDPImportException(String.Format("The Entry with code '{0}' does not exists.", code));
                    }

                    if (sysRowAction == RowAction.Delete)
                    {
                        throw new MDPImportException(String.Format("The Entry with code '{0}' does not exists.", code));
                    }

                    entryRow = catalogEntryDto.CatalogEntry.NewCatalogEntryRow();
                    entryRow.ApplicationId = CatalogConfiguration.Instance.ApplicationId;
                    entryRow.CatalogId     = _CatalogId;
                    entryRow.Code          = code;
                    bIsNew = true;
                }

                //Entry
                if (objName != null)
                {
                    string Name = (string)objName;
                    entryRow.Name = Name;
                }
                else if (bIsNew)
                {
                    throw new AbsentValue("Name");
                }

                if (objClassTypeId != null)
                {
                    string classTypeId = (string)objClassTypeId;
                    entryRow.ClassTypeId = classTypeId;
                }
                else if (bIsNew)
                {
                    entryRow.ClassTypeId = EntryType.Product;
                }

                if (objStartDate != null)
                {
                    DateTime startDate = (DateTime)objStartDate;
                    entryRow.StartDate = startDate.ToUniversalTime();
                }
                else if (bIsNew)
                {
                    entryRow.StartDate = DateTime.UtcNow;
                }

                if (objEndDate != null)
                {
                    DateTime endDate = (DateTime)objEndDate;
                    entryRow.EndDate = endDate.ToUniversalTime();
                }
                else if (bIsNew)
                {
                    entryRow.EndDate = DateTime.UtcNow.AddYears(1);
                }

                if (objTemplateName != null)
                {
                    string templateName = (string)objTemplateName;
                    entryRow.TemplateName = templateName;
                }
                else if (bIsNew)
                {
                    entryRow.TemplateName = String.Empty;
                }

                if (objIsActive != null)
                {
                    bool IsActive = (bool)objIsActive;
                    entryRow.IsActive = IsActive;
                }
                else if (bIsNew)
                {
                    entryRow.IsActive = false;
                }

                int oldMetaClassId = 0;
                if (!_isSystemClass && _metaClassId > 0)
                {
                    if (!bIsNew)
                    {
                        oldMetaClassId = entryRow.MetaClassId;
                    }

                    entryRow.MetaClassId = _metaClassId;
                }
                else if (bIsNew)
                {
                    throw new MDPImportException("The new entry cannot be created without metaclass definition.");
                }

                if (bIsNew)
                {
                    catalogEntryDto.CatalogEntry.AddCatalogEntryRow(entryRow);
                }
                else
                {
                    entryRow.SerializedData = null;
                }

                //SEO
                CatalogEntryDto.CatalogItemSeoRow catalogItemSeoRow = null;
                bool bSeoIsNew = false;
                if (!String.IsNullOrEmpty(this.Context.Language))
                {
                    if (catalogEntryDto.CatalogItemSeo.Count > 0)
                    {
                        DataRow[] drs = catalogEntryDto.CatalogItemSeo.Select(String.Format("LanguageCode LIKE '{0}' AND CatalogEntryId = {1}", this.Context.Language, entryRow.CatalogEntryId));
                        if (drs.Length > 0)
                        {
                            catalogItemSeoRow = (CatalogEntryDto.CatalogItemSeoRow)drs[0];
                        }
                    }

                    if (catalogItemSeoRow == null)
                    {
                        catalogItemSeoRow = catalogEntryDto.CatalogItemSeo.NewCatalogItemSeoRow();
                        catalogItemSeoRow.ApplicationId  = CatalogConfiguration.Instance.ApplicationId;
                        catalogItemSeoRow.LanguageCode   = this.Context.Language.ToLower();
                        catalogItemSeoRow.CatalogEntryId = entryRow.CatalogEntryId;
                        bSeoIsNew = true;
                    }

                    if (objSeoTitle != null)
                    {
                        catalogItemSeoRow.Title = (string)objSeoTitle;
                    }

                    if (objSeoUrl != null)
                    {
                        catalogItemSeoRow.Uri = (string)objSeoUrl;
                    }
                    else if (bSeoIsNew)
                    {
                        // Auto generate the URL if empty
                        string name = catalogEntryDto.CatalogEntry.Count > 0 ? catalogEntryDto.CatalogEntry[0].Name : "";
                        string url  = String.Format("{0}.aspx", CommerceHelper.CleanUrlField(name));

                        int index = 1;
                        while (CatalogContext.Current.GetCatalogEntryByUriDto(url, this.Context.Language).CatalogEntry.Count != 0 || CatalogContext.Current.GetCatalogNodeDto(url, this.Context.Language).CatalogNode.Count != 0)
                        {
                            url = String.Format("{0}-{1}.aspx", CommerceHelper.CleanUrlField(name), index.ToString());
                            index++;
                        }

                        catalogItemSeoRow.Uri = url;
                    }

                    if (objSeoDescription != null)
                    {
                        catalogItemSeoRow.Description = (string)objSeoDescription;
                    }

                    if (objSeoKeywords != null)
                    {
                        catalogItemSeoRow.Keywords = (string)objSeoKeywords;
                    }

                    if (bSeoIsNew)
                    {
                        catalogEntryDto.CatalogItemSeo.AddCatalogItemSeoRow(catalogItemSeoRow);
                    }
                }

                using (TransactionScope tx = new TransactionScope())
                {
                    // Save modifications
                    if (catalogEntryDto.HasChanges())
                    {
                        CatalogContext.Current.SaveCatalogEntry(catalogEntryDto);
                    }

                    int sortOrder = -1;
                    if (objSortOrder != null)
                    {
                        sortOrder = (int)objSortOrder;
                    }

                    if (objCategoryCodes != null)
                    {
                        //NodeEntryRelation

                        string[] categoryCodes = ((string)objCategoryCodes).Split(',');

                        Catalog.Dto.CatalogRelationDto catalogRelationDto = FrameworkContext.Current.CatalogSystem.GetCatalogRelationDto(this._CatalogId, 0, entryRow.CatalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry));

                        Catalog.Dto.CatalogNodeDto catalogNodeDto = FrameworkContext.Current.CatalogSystem.GetCatalogNodesDto(this._CatalogId);
                        if (catalogNodeDto.CatalogNode.Count > 0)
                        {
                            //remove product from category
                            if (catalogRelationDto.NodeEntryRelation.Count > 0)
                            {
                                foreach (CatalogRelationDto.NodeEntryRelationRow nodeEntryRelationRow in catalogRelationDto.NodeEntryRelation)
                                {
                                    DataRow[] catalogNodeDataRows = catalogNodeDto.CatalogNode.Select(String.Format("CatalogNodeId = {0}", nodeEntryRelationRow.CatalogNodeId));
                                    if (catalogNodeDataRows.Length > 0)
                                    {
                                        Catalog.Dto.CatalogNodeDto.CatalogNodeRow catalogNode = (Catalog.Dto.CatalogNodeDto.CatalogNodeRow)catalogNodeDataRows[0];

                                        bool bExist = false;
                                        foreach (string categoryCode in categoryCodes)
                                        {
                                            if (catalogNode.Code.Equals(categoryCode))
                                            {
                                                if (sortOrder >= 0)
                                                {
                                                    nodeEntryRelationRow.SortOrder = sortOrder;
                                                }

                                                bExist = true;
                                                break;
                                            }
                                        }
                                        if (!bExist)
                                        {
                                            nodeEntryRelationRow.Delete();
                                        }
                                    }
                                }
                            }

                            //add entry to category
                            foreach (string categoryCode in categoryCodes)
                            {
                                DataRow[] catalogNodeDataRows = catalogNodeDto.CatalogNode.Select(String.Format("Code = '{0}'", categoryCode.Replace("'", "''")));
                                if (catalogNodeDataRows.Length > 0)
                                {
                                    Catalog.Dto.CatalogNodeDto.CatalogNodeRow catalogNode = (Catalog.Dto.CatalogNodeDto.CatalogNodeRow)catalogNodeDataRows[0];

                                    DataRow[] nodeEntryRelationDataRows = catalogRelationDto.NodeEntryRelation.Select(String.Format("CatalogNodeId = {0}", catalogNode.CatalogNodeId));
                                    if (nodeEntryRelationDataRows.Length == 0)
                                    {
                                        Catalog.Dto.CatalogRelationDto.NodeEntryRelationRow row = catalogRelationDto.NodeEntryRelation.NewNodeEntryRelationRow();
                                        row.CatalogId      = this._CatalogId;
                                        row.CatalogEntryId = entryRow.CatalogEntryId;
                                        row.CatalogNodeId  = catalogNode.CatalogNodeId;

                                        if (sortOrder >= 0)
                                        {
                                            row.SortOrder = sortOrder;
                                        }
                                        else
                                        {
                                            row.SortOrder = 0;
                                        }

                                        catalogRelationDto.NodeEntryRelation.AddNodeEntryRelationRow(row);
                                    }
                                }
                            }
                        }

                        if (catalogRelationDto.HasChanges())
                        {
                            CatalogContext.Current.SaveCatalogRelationDto(catalogRelationDto);
                        }
                    }

                    if (!bIsNew && !_isSystemClass && oldMetaClassId != entryRow.MetaClassId)
                    {
                        MetaObject.Delete(this.Context, entryRow.CatalogEntryId, oldMetaClassId);
                        MetaObject obj = MetaObject.NewObject(this.Context, entryRow.CatalogEntryId, entryRow.MetaClassId);
                        obj.AcceptChanges(this.Context);
                    }

                    tx.Complete();
                }
            }
            catch (Exception ex)
            {
                throw new MDPImportException(ex.Message, null, RowIndex, null, null, item);
            }

            return(entryRow.CatalogEntryId);
        }
Example #7
0
        /// <summary>
        /// Creates the system row.
        /// </summary>
        /// <param name="Mode">The mode.</param>
        /// <param name="RowIndex">Index of the row.</param>
        /// <param name="Item">The item.</param>
        /// <returns></returns>
        protected override int CreateSystemRow(FillDataMode Mode, int RowIndex, params object[] Item)
        {
            int    i = 0;
            object objSysRowAction = Item[i++];
            object objCode         = Item[i++];
            //SaleType
            object objSaleType    = Item[i++];
            object objSaleCode    = Item[i++];
            object objUnitPrice   = Item[i++];
            object objCurrency    = Item[i++];
            object objMinQuantity = Item[i++];
            object objStartDate   = Item[i++];
            object objEndDate     = Item[i++];

            int salePriceId = 0;

            CatalogEntryDto.SalePriceRow newSalePriceRow = null;

            try
            {
                RowAction sysRowAction = RowAction.Default;

                if (objSysRowAction != null)
                {
                    sysRowAction = GetRowActionEnum((string)objSysRowAction);
                }

                string Code;
                if (objCode != null)
                {
                    Code = (string)objCode;
                }
                else
                {
                    throw new AbsentValue("Code");
                }

                bool            bSalePriceIsNew = false;
                CatalogEntryDto catalogEntryDto = CatalogEntryManager.GetCatalogEntryDto(Code, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
                if (catalogEntryDto.CatalogEntry.Count > 0)
                {
                    CatalogEntryDto.CatalogEntryRow entry = catalogEntryDto.CatalogEntry[0];
                    if (entry.ClassTypeId.Equals(EntryType.Variation, StringComparison.OrdinalIgnoreCase) ||
                        entry.ClassTypeId.Equals(EntryType.Package, StringComparison.OrdinalIgnoreCase))
                    {
                        if (catalogEntryDto.SalePrice.Count == 0)
                        {
                            if (sysRowAction == RowAction.Update)
                            {
                                throw new MDPImportException(String.Format("The Sales Price for Entry code '{0}' does not exists.", Code));
                            }

                            if (sysRowAction == RowAction.Delete)
                            {
                                throw new MDPImportException(String.Format("The Sales Price for Entry code '{0}' does not exists.", Code));
                            }

                            bSalePriceIsNew = true;
                        }

                        newSalePriceRow             = catalogEntryDto.SalePrice.NewSalePriceRow();
                        newSalePriceRow.ItemCode    = entry.Code;
                        newSalePriceRow.SaleType    = 0;
                        newSalePriceRow.SaleCode    = String.Empty;
                        newSalePriceRow.UnitPrice   = 0;
                        newSalePriceRow.Currency    = GetCatalogDefaultCurrency();
                        newSalePriceRow.MinQuantity = 0;
                        newSalePriceRow.StartDate   = DateTime.UtcNow;
                        newSalePriceRow.EndDate     = DateTime.UtcNow.AddMonths(1);
                    }
                    else
                    {
                        throw new MDPImportException(String.Format("The Entry with code '{0}' has wrong type ('{1}') for Variation/Inventory import.", Code, entry.ClassTypeId));
                    }
                }
                else
                {
                    throw new MDPImportException(String.Format("The Entry with code '{0}' does not exists.", Code));
                }

                //SalePrice
                if (objSaleType != null)
                {
                    newSalePriceRow.SaleType = (int)GetSaleTypeId((string)objSaleType);
                }

                if (objSaleCode != null)
                {
                    newSalePriceRow.SaleCode = (string)objSaleCode;
                }

                if (objUnitPrice != null)
                {
                    newSalePriceRow.UnitPrice = (decimal)objUnitPrice;
                }

                if (objCurrency != null)
                {
                    newSalePriceRow.Currency = GetCurrencyCode((string)objCurrency);
                }

                if (objMinQuantity != null)
                {
                    newSalePriceRow.MinQuantity = (decimal)objMinQuantity;
                }

                if (objStartDate != null)
                {
                    newSalePriceRow.StartDate = ((DateTime)objStartDate).ToUniversalTime();
                }

                if (objEndDate != null)
                {
                    newSalePriceRow.EndDate = ((DateTime)objEndDate).ToUniversalTime();
                }

                if (bSalePriceIsNew)
                {
                    catalogEntryDto.SalePrice.AddSalePriceRow(newSalePriceRow);
                }
                else
                {
                    IEnumerable <int> result = from SalePriceTable in catalogEntryDto.SalePrice
                                               where SalePriceTable.SaleType == newSalePriceRow.SaleType &&
                                               SalePriceTable.SaleCode == newSalePriceRow.SaleCode &&
                                               SalePriceTable.Currency == newSalePriceRow.Currency &&
                                               SalePriceTable.StartDate == newSalePriceRow.StartDate &&
                                               SalePriceTable.EndDate == newSalePriceRow.EndDate
                                               select SalePriceTable.SalePriceId;

                    if (result.Count() == 0)
                    {
                        if (sysRowAction == RowAction.Update)
                        {
                            throw new MDPImportException(String.Format("The Sales Price for Entry code '{0}' does not exists.", Code));
                        }

                        if (sysRowAction == RowAction.Delete)
                        {
                            throw new MDPImportException(String.Format("The Sales Price for Entry code '{0}' does not exists.", Code));
                        }

                        catalogEntryDto.SalePrice.AddSalePriceRow(newSalePriceRow);
                    }
                    else
                    {
                        if (sysRowAction == RowAction.Insert)
                        {
                            throw new MDPImportException(String.Format("The Sales Price for Entry code '{0}' already exists.", Code));
                        }

                        CatalogEntryDto.SalePriceRow salePriceRow = catalogEntryDto.SalePrice.FindBySalePriceId(result.First());

                        if (sysRowAction == RowAction.Delete)
                        {
                            salePriceRow.Delete();
                        }

                        if (sysRowAction == RowAction.Update)
                        {
                            salePriceId              = salePriceRow.SalePriceId;
                            salePriceRow.UnitPrice   = newSalePriceRow.UnitPrice;
                            salePriceRow.MinQuantity = newSalePriceRow.MinQuantity;
                        }
                    }
                }

                using (TransactionScope tx = new TransactionScope())
                {
                    // Save modifications
                    if (catalogEntryDto.HasChanges())
                    {
                        CatalogContext.Current.SaveCatalogEntry(catalogEntryDto);
                    }

                    tx.Complete();
                }
            }
            catch (Exception ex)
            {
                throw new MDPImportException(ex.Message, null, RowIndex, null, null, Item);
            }

            return(salePriceId);
        }
Example #8
0
        protected override int CreateSystemRow(FillDataMode Mode, int RowIndex, params object[] Item)
        {
            int    i = 0;
            object objSysRowAction    = Item[i++];
            object objAssociationName = Item[i++];
            object objParentCode      = Item[i++];
            object objChildCode       = Item[i++];
            object objSortOrder       = Item[i++];
            object objAssociationType = Item[i++];

            try
            {
                RowAction sysRowAction = RowAction.Default;

                if (objSysRowAction != null)
                {
                    sysRowAction = GetRowActionEnum((string)objSysRowAction);
                }

                string AssociationName;
                if (!String.IsNullOrEmpty((string)objAssociationName))
                {
                    AssociationName = (string)objAssociationName;
                }
                else
                {
                    throw new AbsentValue("Association Name");
                }

                string parentCode;
                if (!String.IsNullOrEmpty((string)objParentCode))
                {
                    parentCode = (string)objParentCode;
                }
                else
                {
                    throw new AbsentValue("Parent Entry Code");
                }

                string childCode;
                if (!String.IsNullOrEmpty((string)objChildCode))
                {
                    childCode = (string)objChildCode;
                }
                else
                {
                    throw new AbsentValue("Child Entry Code");
                }

                bool bIsNew = false;

                //Parent Entry
                CatalogEntryDto.CatalogEntryRow parentEntryRow = null;
                CatalogEntryDto catalogEntryDto = CatalogEntryManager.GetCatalogEntryDto(parentCode, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.Associations));
                if (catalogEntryDto.CatalogEntry.Count > 0)
                {
                    parentEntryRow = catalogEntryDto.CatalogEntry[0];
                }
                else
                {
                    throw new MDPImportException(String.Format("The Parent Entry with code '{0}' does not exists.", parentCode));
                }

                //Child Entry
                CatalogEntryDto.CatalogEntryRow childEntryRow = null;
                CatalogEntryDto childEntryDto = CatalogEntryManager.GetCatalogEntryDto(childCode, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo));
                if (childEntryDto.CatalogEntry.Count > 0)
                {
                    childEntryRow = childEntryDto.CatalogEntry[0];
                }
                else
                {
                    throw new MDPImportException(String.Format("The Child Entry with code '{0}' does not exists.", childCode));
                }

                //CatalogAssociation (define CatalogAssociationId)
                int catalogAssociationId = 0;
                CatalogEntryDto.CatalogAssociationRow[] catalogAssociationRows = (CatalogEntryDto.CatalogAssociationRow[])catalogEntryDto.CatalogAssociation.Select(String.Format("AssociationName = '{0}'", AssociationName));
                if (catalogAssociationRows.Length == 0)
                {
                    CatalogEntryDto.CatalogAssociationRow newCatalogAssociationRow = catalogEntryDto.CatalogAssociation.NewCatalogAssociationRow();
                    newCatalogAssociationRow.CatalogEntryId         = parentEntryRow.CatalogEntryId;
                    newCatalogAssociationRow.AssociationName        = AssociationName;
                    newCatalogAssociationRow.AssociationDescription = String.Empty;
                    newCatalogAssociationRow.SortOrder = 0;
                    catalogEntryDto.CatalogAssociation.AddCatalogAssociationRow(newCatalogAssociationRow);

                    CatalogContext.Current.SaveCatalogEntry(catalogEntryDto);

                    catalogAssociationId = newCatalogAssociationRow.CatalogAssociationId;
                }
                else
                {
                    catalogAssociationId = catalogAssociationRows[0].CatalogAssociationId;
                }

                //catalogEntryAssociationRow
                CatalogAssociationDto catalogAssociationDto = CatalogAssociationManager.GetCatalogAssociationDto(catalogAssociationId);
                CatalogAssociationDto.CatalogAssociationRow catalogAssociationRow = catalogAssociationDto.CatalogAssociation[0];

                CatalogAssociationDto.CatalogEntryAssociationRow catalogEntryAssociationRow = null;

                CatalogAssociationDto.CatalogEntryAssociationRow[] catalogEntryAssociationRows = (CatalogAssociationDto.CatalogEntryAssociationRow[])catalogAssociationDto.CatalogEntryAssociation.Select(String.Format("CatalogEntryId = {0}", childEntryRow.CatalogEntryId));
                if (catalogEntryAssociationRows.Length == 0)
                {
                    if (sysRowAction == RowAction.Update)
                    {
                        throw new MDPImportException(String.Format("The Catalog Entry Association with name '{0}' for entry code '{1}' and child code '{2}' does not exists.", AssociationName, parentCode, childCode));
                    }

                    if (sysRowAction == RowAction.Delete)
                    {
                        throw new MDPImportException(String.Format("The Catalog Entry Association with name '{0}' for entry code '{1}' and child code '{2}' does not exists.", AssociationName, parentCode, childCode));
                    }

                    catalogEntryAssociationRow = catalogAssociationDto.CatalogEntryAssociation.NewCatalogEntryAssociationRow();
                    catalogEntryAssociationRow.CatalogAssociationId = catalogAssociationId;
                    catalogEntryAssociationRow.CatalogEntryId       = childEntryRow.CatalogEntryId;
                    catalogEntryAssociationRow.SortOrder            = 0;
                    if (catalogAssociationDto.AssociationType.Count > 0)
                    {
                        catalogEntryAssociationRow.AssociationTypeId = catalogAssociationDto.AssociationType[0].AssociationTypeId;
                    }

                    bIsNew = true;
                }
                else
                {
                    if (sysRowAction == RowAction.Insert)
                    {
                        throw new MDPImportException(String.Format("The Catalog Entry Association with name '{0}' for entry code '{1}' and child code '{2}' already exists.", AssociationName, parentCode, childCode));
                    }

                    catalogEntryAssociationRow = catalogEntryAssociationRows[0];

                    if (sysRowAction == RowAction.Delete)
                    {
                        catalogEntryAssociationRow.Delete();
                        CatalogContext.Current.SaveCatalogAssociation(catalogAssociationDto);
                        return(0);
                    }
                }

                if (objSortOrder != null)
                {
                    catalogEntryAssociationRow.SortOrder = (int)objSortOrder;
                }

                if (objAssociationType != null)
                {
                    string associationType = (string)objAssociationType;
                    if (!catalogEntryAssociationRow.AssociationTypeId.Equals(associationType))
                    {
                        CatalogAssociationDto.AssociationTypeRow[] associationTypeRows = (CatalogAssociationDto.AssociationTypeRow[])catalogAssociationDto.AssociationType.Select(String.Format("AssociationTypeId = '{0}'", associationType));
                        if (associationTypeRows.Length > 0)
                        {
                            catalogEntryAssociationRow.AssociationTypeId = associationTypeRows[0].AssociationTypeId;
                        }
                    }
                }

                if (bIsNew)
                {
                    catalogAssociationDto.CatalogEntryAssociation.AddCatalogEntryAssociationRow(catalogEntryAssociationRow);
                }

                using (TransactionScope tx = new TransactionScope())
                {
                    // Save modifications
                    if (catalogAssociationDto.HasChanges())
                    {
                        CatalogContext.Current.SaveCatalogAssociation(catalogAssociationDto);
                    }

                    tx.Complete();
                }
            }
            catch (Exception ex)
            {
                throw new MDPImportException(ex.Message, null, RowIndex, null, null, Item);
            }

            return(1);
        }
        protected override int CreateSystemRow(FillDataMode Mode, int RowIndex, params object[] Item)
        {
            int    i = 0;
            object objSysRowAction = Item[i++];
            object objParentCode   = Item[i++];
            object objChildCode    = Item[i++];
            object objQuantity     = Item[i++];
            object objGroupName    = Item[i++];
            object objSortOrder    = Item[i++];

            CatalogRelationDto.CatalogEntryRelationRow catalogEntryRelationRow = null;
            CatalogRelationDto catalogRelationDto = new CatalogRelationDto();

            try
            {
                RowAction sysRowAction = RowAction.Default;

                if (objSysRowAction != null)
                {
                    sysRowAction = GetRowActionEnum((string)objSysRowAction);
                }

                string parentCode;
                if (!String.IsNullOrEmpty((string)objParentCode))
                {
                    parentCode = (string)objParentCode;
                }
                else
                {
                    throw new AbsentValue("Parent Entry Code");
                }

                string childCode;
                if (!String.IsNullOrEmpty((string)objChildCode))
                {
                    childCode = (string)objChildCode;
                }
                else
                {
                    throw new AbsentValue("Child Entry Code");
                }

                bool            bIsNew          = false;
                CatalogEntryDto catalogEntryDto = CatalogEntryManager.GetCatalogEntryDto(parentCode, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo));
                if (catalogEntryDto.CatalogEntry.Count > 0)
                {
                    CatalogEntryDto.CatalogEntryRow entry = catalogEntryDto.CatalogEntry[0];
                    if (entry.ClassTypeId.Equals(EntryType.Product, StringComparison.OrdinalIgnoreCase) ||
                        entry.ClassTypeId.Equals(EntryType.Bundle, StringComparison.OrdinalIgnoreCase) ||
                        entry.ClassTypeId.Equals(EntryType.Package, StringComparison.OrdinalIgnoreCase) ||
                        entry.ClassTypeId.Equals(EntryType.DynamicPackage, StringComparison.OrdinalIgnoreCase))
                    {
                        CatalogEntryDto childEntryDto = CatalogEntryManager.GetCatalogEntryDto(childCode, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo));
                        if (childEntryDto.CatalogEntry.Count > 0)
                        {
                            CatalogEntryDto.CatalogEntryRow childEntry = childEntryDto.CatalogEntry[0];

                            catalogRelationDto = CatalogRelationManager.GetCatalogRelationDto(this._CatalogId, 0, entry.CatalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.CatalogEntry));
                            if (catalogRelationDto.CatalogEntryRelation.Count > 0)
                            {
                                DataRow[] drs = catalogRelationDto.CatalogEntryRelation.Select(String.Format("ParentEntryId = {0} AND ChildEntryId = {1}", entry.CatalogEntryId, childEntry.CatalogEntryId));
                                if (drs.Length > 0)
                                {
                                    catalogEntryRelationRow = (CatalogRelationDto.CatalogEntryRelationRow)drs[0];

                                    if (sysRowAction == RowAction.Insert)
                                    {
                                        throw new MDPImportException(String.Format("The Relation with Parent Entry code '{0}' and Child Entry code '{1}' already exists.", parentCode, childCode));
                                    }

                                    if (sysRowAction == RowAction.Delete)
                                    {
                                        catalogEntryRelationRow.Delete();
                                        CatalogRelationManager.SaveCatalogRelation(catalogRelationDto);
                                        return(0);
                                    }
                                }
                            }

                            if (catalogEntryRelationRow == null)
                            {
                                if (sysRowAction == RowAction.Update)
                                {
                                    throw new MDPImportException(String.Format("The Relation with Parent Entry code '{0}' and Child Entry code '{1}' does not exists.", parentCode, childCode));
                                }

                                if (sysRowAction == RowAction.Delete)
                                {
                                    throw new MDPImportException(String.Format("The Relation with Parent Entry code '{0}' and Child Entry code '{1}' does not exists.", parentCode, childCode));
                                }

                                catalogEntryRelationRow = catalogRelationDto.CatalogEntryRelation.NewCatalogEntryRelationRow();
                                catalogEntryRelationRow.ParentEntryId = entry.CatalogEntryId;
                                catalogEntryRelationRow.ChildEntryId  = childEntry.CatalogEntryId;
                                catalogEntryRelationRow.Quantity      = 1;
                                catalogEntryRelationRow.GroupName     = String.Empty;
                                catalogEntryRelationRow.SortOrder     = 0;

                                switch (entry.ClassTypeId)
                                {
                                case EntryType.Product:
                                    catalogEntryRelationRow.RelationTypeId = EntryRelationType.ProductVariation;
                                    break;

                                case EntryType.Package:
                                    catalogEntryRelationRow.RelationTypeId = EntryRelationType.PackageEntry;
                                    break;

                                case EntryType.Bundle:
                                case EntryType.DynamicPackage:
                                    catalogEntryRelationRow.RelationTypeId = EntryRelationType.BundleEntry;
                                    break;
                                }

                                bIsNew = true;
                            }
                        }
                        else
                        {
                            throw new MDPImportException(String.Format("The Child Entry with code '{0}' does not exists.", childCode));
                        }
                    }
                    else
                    {
                        throw new MDPImportException(String.Format("The Parent Entry with code '{0}' has wrong type ('{1}').", parentCode, entry.ClassTypeId));
                    }
                }
                else
                {
                    throw new MDPImportException(String.Format("The Parent Entry with code '{0}' does not exists.", parentCode));
                }

                //SalePrice
                if (objQuantity != null)
                {
                    catalogEntryRelationRow.Quantity = (decimal)objQuantity;
                }

                if (objGroupName != null)
                {
                    catalogEntryRelationRow.GroupName = (string)objGroupName;
                }

                if (objSortOrder != null)
                {
                    catalogEntryRelationRow.SortOrder = (int)objSortOrder;
                }

                if (bIsNew)
                {
                    catalogRelationDto.CatalogEntryRelation.AddCatalogEntryRelationRow(catalogEntryRelationRow);
                }

                using (TransactionScope tx = new TransactionScope())
                {
                    // Save modifications
                    if (catalogRelationDto.HasChanges())
                    {
                        CatalogContext.Current.SaveCatalogRelationDto(catalogRelationDto);
                    }

                    tx.Complete();
                }
            }
            catch (Exception ex)
            {
                throw new MDPImportException(ex.Message, null, RowIndex, null, null, Item);
            }

            return(catalogEntryRelationRow.ParentEntryId);
        }