예제 #1
0
        public Tagge.Common.Models.ProductVariantResponse ConvertToResponse(string companyId, IMongoDatabase db)
        {
            var response = new Tagge.Common.Models.ProductVariantResponse();

            response.Id           = Id;
            response.Sku          = Sku;
            response.DefaultPrice = DefaultPrice;
            response.MSRP         = MSRP;
            response.SalePrice    = SalePrice;
            response.Barcode      = Barcode;
            response.Width        = Width;
            response.Height       = Height;
            response.Depth        = Depth;
            response.Weight       = Weight;
            response.Status       = Status;

            // Collections
            // Kit
            if (Kit != null && Kit.IsActive)
            {
                response.Kit = Kit.ConvertToResponse(companyId, "PC_VariantKit", db);
            }


            // Inventory - Managed in PC_Inventory

            // Categories
            if (Categories != null)
            {
                response.Categories = new List <Tagge.Common.Models.CategoryAssignmentResponse>();
                foreach (var category in Categories)
                {
                    if (category.IsActive)
                    {
                        response.Categories.Add(category.ConvertToGenericResponse());
                    }
                }
            }

            // Options
            if (Options != null)
            {
                response.Options = new List <Tagge.Common.Models.OptionValueResponse>();
                foreach (var option in Options)
                {
                    if (option.IsActive)
                    {
                        response.Options.Add(option.ConvertToResponse(companyId, "PC_ProductVariantOption", db));
                    }
                }
            }

            // AlternateIds
            if (AlternateIds != null)
            {
                response.AlternateIds = new List <Tagge.Common.Models.ProductAlternateIdResponse>();
                foreach (var alternateId in AlternateIds)
                {
                    if (alternateId.IsActive)
                    {
                        response.AlternateIds.Add(alternateId.ConvertToResponse(companyId, "PC_ProductVariantAlternateId", db));
                    }
                }
            }

            // Custom Fields
            if (CustomFields != null)
            {
                response.CustomFields = new List <Tagge.Common.Models.GenericCustomFieldResponse>();
                foreach (var customField in CustomFields)
                {
                    response.CustomFields.Add(customField.ConvertToResponse());
                }
            }

            // ExternalIds - Managed in PC_ExternalId

            return(response);
        }
예제 #2
0
        /// <summary>
        /// Converts the Product to a Product Response
        /// </summary>
        /// <returns></returns>
        public Tagge.Common.Models.ProductResponse ConvertToResponse(string companyId, IMongoDatabase db)
        {
            var response = new Tagge.Common.Models.ProductResponse();

            // Build the response
            response.Id               = Id;
            response.Name             = Name;
            response.Sku              = Sku;
            response.Description      = Description;
            response.DefaultPrice     = DefaultPrice;
            response.MSRP             = MSRP;
            response.SalePrice        = SalePrice;
            response.TaxClass         = TaxClass;
            response.Barcode          = Barcode;
            response.Unit             = Unit;
            response.Type             = Type;
            response.Status           = Status;
            response.TrackingMethod   = TrackingMethod;
            response.AllowDiscounts   = AllowDiscounts;
            response.AllowBackorders  = AllowBackorders;
            response.InStockThreshold = InStockThreshold;
            response.Width            = Width;
            response.Height           = Height;
            response.Depth            = Depth;
            response.Weight           = Weight;

            // Collections
            // Kit
            if (Kit != null && Kit.IsActive)
            {
                response.Kit = Kit.ConvertToResponse(companyId, "PC_Kit", db);
            }

            // Variants - Managed in PC_ProductVariant
            // Inventory - Managed in PC_Inventory

            // Categories
            if (Categories != null)
            {
                response.Categories = new List <Tagge.Common.Models.CategoryAssignmentResponse>();
                foreach (var category in Categories)
                {
                    if (category.IsActive)
                    {
                        response.Categories.Add(category.ConvertToGenericResponse());
                    }
                }
            }

            // Options
            if (Options != null)
            {
                response.Options = new List <Tagge.Common.Models.OptionResponse>();
                foreach (var option in Options)
                {
                    if (option.IsActive)
                    {
                        response.Options.Add(option.ConvertToResponse(companyId, "PC_ProductOption", db));
                    }
                }
            }

            // Units
            if (Units != null)
            {
                response.Units = new List <Tagge.Common.Models.ProductUnitResponse>();
                foreach (var unit in Units)
                {
                    if (unit.IsActive)
                    {
                        response.Units.Add(unit.ConvertToResponse(companyId, "PC_ProductUnit", db));
                    }
                }
            }

            // AlternateIds
            if (AlternateIds != null)
            {
                response.AlternateIds = new List <Tagge.Common.Models.ProductAlternateIdResponse>();
                foreach (var alternateId in AlternateIds)
                {
                    if (alternateId.IsActive)
                    {
                        response.AlternateIds.Add(alternateId.ConvertToResponse(companyId, "PC_ProductAlternateId", db));
                    }
                }
            }

            // Custom Fields
            if (CustomFields != null)
            {
                response.CustomFields = new List <Tagge.Common.Models.GenericCustomFieldResponse>();
                foreach (var customField in CustomFields)
                {
                    response.CustomFields.Add(customField.ConvertToResponse());
                }
            }

            // ExternalIds - Managed in PC_ExternalId

            return(response);
        }