Ejemplo n.º 1
0
        public IHttpActionResult CreateOrUpdateCategory(webModel.Category category)
        {
            var coreCategory = category.ToModuleModel();

            if (coreCategory.Id == null)
            {
                if (coreCategory.SeoInfos == null || !coreCategory.SeoInfos.Any())
                {
                    var slugUrl = category.Name.GenerateSlug();
                    if (!String.IsNullOrEmpty(slugUrl))
                    {
                        var catalog         = _catalogService.GetById(category.CatalogId);
                        var defaultLanguage = catalog.Languages.First(x => x.IsDefault).LanguageCode;
                        coreCategory.SeoInfos = new[] { new SeoInfo {
                                                            LanguageCode = defaultLanguage, SemanticUrl = slugUrl
                                                        } };
                    }
                }

                CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Create, coreCategory);

                var retVal = _categoryService.Create(coreCategory).ToWebModel(_blobUrlResolver);
                retVal.Catalog = null;
                return(Ok(retVal));
            }
            else
            {
                CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Update, coreCategory);

                _categoryService.Update(new[] { coreCategory });
                return(StatusCode(HttpStatusCode.NoContent));
            }
        }
        public static moduleModel.Category ToModuleModel(this webModel.Category category)
        {
            var retVal = new moduleModel.Category();

            retVal.InjectFrom(category);
            retVal.SeoInfos = category.SeoInfos;

            if (category.Links != null)
            {
                retVal.Links = category.Links.Select(x => x.ToCoreModel()).ToList();
            }

            if (category.Properties != null)
            {
                retVal.PropertyValues = new List <moduleModel.PropertyValue>();
                foreach (var property in category.Properties)
                {
                    foreach (var propValue in property.Values)
                    {
                        propValue.ValueType = property.ValueType;
                        //Need populate required fields
                        propValue.PropertyId   = property.Id;
                        propValue.PropertyName = property.Name;
                        retVal.PropertyValues.Add(propValue.ToCoreModel());
                    }
                }
            }

            if (category.Images != null)
            {
                retVal.Images = category.Images.Select(x => x.ToCoreModel()).ToList();
            }

            return(retVal);
        }
        public IHttpActionResult Post(webModel.Category category)
        {
            var coreCategory = category.ToModuleModel();

            if (coreCategory.Id == null)
            {
                if (coreCategory.SeoInfos == null || !coreCategory.SeoInfos.Any())
                {
                    var slugUrl = category.Name.GenerateSlug();
                    if (!String.IsNullOrEmpty(slugUrl))
                    {
                        var catalog         = _catalogService.GetById(category.CatalogId);
                        var defaultLanguage = catalog.Languages.First(x => x.IsDefault).LanguageCode;
                        coreCategory.SeoInfos = new SeoInfo[] { new SeoInfo {
                                                                    LanguageCode = defaultLanguage, SemanticUrl = slugUrl
                                                                } };
                    }
                }

                var retVal = _categoryService.Create(coreCategory).ToWebModel();
                retVal.Catalog = null;
                return(Ok(retVal));
            }
            else
            {
                _categoryService.Update(new[] { coreCategory });
                return(StatusCode(HttpStatusCode.NoContent));
            }
        }
        public static webModel.Category ToWebModel(this moduleModel.Category category, IBlobUrlResolver blobUrlResolver = null, bool convertProps = true)
        {
            var retVal = new webModel.Category();

            retVal.InjectFrom(category);
            retVal.Catalog = category.Catalog.ToWebModel();
            //Reset properties for size economy
            retVal.Catalog.Properties = null;
            retVal.SeoInfos           = category.SeoInfos;

            if (category.Parents != null)
            {
                retVal.Parents = category.Parents.ToDictionary(x => x.Id, x => x.Name);
            }
            //For virtual category links not needed
            if (!category.Virtual && category.Links != null)
            {
                retVal.Links = category.Links.Select(x => x.ToWebModel()).ToList();
            }

            //Need add property for each meta info
            retVal.Properties = new List <webModel.Property>();
            if (convertProps)
            {
                foreach (var property in category.Properties)
                {
                    var webModelProperty = property.ToWebModel();
                    //Reset dict values to decrease response size
                    webModelProperty.DictionaryValues = null;
                    webModelProperty.Values           = new List <webModel.PropertyValue>();
                    webModelProperty.IsManageable     = true;
                    webModelProperty.IsReadOnly       = property.Type != moduleModel.PropertyType.Category;
                    retVal.Properties.Add(webModelProperty);
                }

                //Populate property values
                if (category.PropertyValues != null)
                {
                    foreach (var propValue in category.PropertyValues.Select(x => x.ToWebModel()))
                    {
                        var property = retVal.Properties.FirstOrDefault(x => x.Id == propValue.PropertyId);
                        if (property == null)
                        {
                            //Need add dummy property for each value without property
                            property = new webModel.Property(propValue, category.CatalogId, category.Id, moduleModel.PropertyType.Category);
                            retVal.Properties.Add(property);
                        }
                        property.Values.Add(propValue);
                    }
                }
            }
            if (category.Images != null)
            {
                retVal.Images = category.Images.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
            }
            return(retVal);
        }
Ejemplo n.º 5
0
		public static webModel.Category ToWebModel(this moduleModel.Category category, IBlobUrlResolver blobUrlResolver = null, bool convertProps = true)
		{
			var retVal = new webModel.Category();
			retVal.InjectFrom(category);
			retVal.Catalog = category.Catalog.ToWebModel();
            //Reset properties for size economy
            retVal.Catalog.Properties = null;
			retVal.SeoInfos = category.SeoInfos;
	
			if(category.Parents != null)
			{
				retVal.Parents = category.Parents.ToDictionary(x => x.Id, x => x.Name);
			}
			//For virtual category links not needed
			if (!category.Virtual && category.Links != null)
			{
				retVal.Links = category.Links.Select(x => x.ToWebModel()).ToList();
			}

            //Need add property for each meta info
            retVal.Properties = new List<webModel.Property>();
            if (convertProps)
            {
                foreach (var property in category.Properties)
                {
                    var webModelProperty = property.ToWebModel();
                    //Reset dict values to decrease response size
                    webModelProperty.DictionaryValues = null;
                    webModelProperty.Values = new List<webModel.PropertyValue>();
                    webModelProperty.IsManageable = true;
                    webModelProperty.IsReadOnly = property.Type != moduleModel.PropertyType.Category;
                    retVal.Properties.Add(webModelProperty);
                }

                //Populate property values
                if (category.PropertyValues != null)
                {
                    foreach (var propValue in category.PropertyValues.Select(x => x.ToWebModel()))
                    {
                        var property = retVal.Properties.FirstOrDefault(x => x.Id == propValue.PropertyId);
                        if (property == null)
                        {
                            //Need add dummy property for each value without property
                            property = new webModel.Property(propValue, category.CatalogId, category.Id, moduleModel.PropertyType.Category);
                            retVal.Properties.Add(property);
                        }
                        property.Values.Add(propValue);
                    }
                }
            }
			if (category.Images != null)
			{
				retVal.Images = category.Images.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
			}
			return retVal;
		}
Ejemplo n.º 6
0
 public ListEntryCategory(Category category)
     : base(TypeName)
 {
     Id = category.Id;
     ImageUrl = "";
     Code = category.Code;
     Name = category.Name;
     IsActive = category.IsActive;
     if (category.Links != null)
     {
         Links = category.Links.Select(x => new ListEntryLink(x)).ToArray();
     }
 }
        public IHttpActionResult GetNewCategory(string catalogId, [FromUri]string parentCategoryId = null)
        {
            var retVal = new webModel.Category
            {
                ParentId = parentCategoryId,
                CatalogId = catalogId,
                Catalog = _catalogService.GetById(catalogId).ToWebModel(),
                Code = Guid.NewGuid().ToString().Substring(0, 5),
                SeoInfos = new List<SeoInfo>(),
				IsActive = true
            };

            return Ok(retVal);
        }
        public IHttpActionResult GetNewCategory(string catalogId, [FromUri] string parentCategoryId = null)
        {
            var retVal = new webModel.Category
            {
                ParentId  = parentCategoryId,
                CatalogId = catalogId,
                Catalog   = _catalogService.GetById(catalogId).ToWebModel(),
                Code      = Guid.NewGuid().ToString().Substring(0, 5),
                SeoInfos  = new List <SeoInfo>(),
                IsActive  = true
            };

            return(Ok(retVal));
        }
Ejemplo n.º 9
0
        public static webModel.Category ToWebModel(this moduleModel.Category category, moduleModel.Property[] properties = null)
        {
            var retVal = new webModel.Category();

            retVal.InjectFrom(category);
            retVal.Catalog  = category.Catalog.ToWebModel();
            retVal.SeoInfos = category.SeoInfos;

            if (category.Parents != null)
            {
                retVal.Parents = category.Parents.ToDictionary(x => x.Id, x => x.Name);
            }
            //For virtual category links not needed
            if (!category.Virtual && category.Links != null)
            {
                retVal.Links = category.Links.Select(x => x.ToWebModel()).ToList();
            }
            retVal.Properties = new List <webModel.Property>();
            //Need add property for each meta info
            if (properties != null)
            {
                retVal.Properties = new List <webModel.Property>();
                foreach (var property in properties)
                {
                    var webModelProperty = property.ToWebModel();
                    webModelProperty.Values       = new List <webModel.PropertyValue>();
                    webModelProperty.IsManageable = true;
                    webModelProperty.IsReadOnly   = property.Type != moduleModel.PropertyType.Category;
                    retVal.Properties.Add(webModelProperty);
                }
            }

            //Populate property values
            if (category.PropertyValues != null)
            {
                foreach (var propValue in category.PropertyValues.Select(x => x.ToWebModel()))
                {
                    var property = retVal.Properties.FirstOrDefault(x => x.IsSuitableForValue(propValue));
                    if (property == null)
                    {
                        //Need add dummy property for each value without property
                        property = new webModel.Property(propValue, category.CatalogId, category.Id, moduleModel.PropertyType.Category);
                        retVal.Properties.Add(property);
                    }
                    property.Values.Add(propValue);
                }
            }

            return(retVal);
        }
Ejemplo n.º 10
0
		public static webModel.Category ToWebModel(this moduleModel.Category category, moduleModel.Property[] properties = null)
		{
			var retVal = new webModel.Category();
			retVal.InjectFrom(category);
			retVal.Catalog = category.Catalog.ToWebModel();
			retVal.SeoInfos = category.SeoInfos;
	
			if(category.Parents != null)
			{
				retVal.Parents = category.Parents.ToDictionary(x => x.Id, x => x.Name);
			}
			//For virtual category links not needed
			if (!category.Virtual && category.Links != null)
			{
				retVal.Links = category.Links.Select(x => x.ToWebModel()).ToList();
			}
			retVal.Properties = new List<webModel.Property>();
			//Need add property for each meta info
			if (properties != null)
			{
				retVal.Properties = new List<webModel.Property>();
				foreach (var property in properties)
				{
					var webModelProperty = property.ToWebModel();
					webModelProperty.Values = new List<webModel.PropertyValue>();
					webModelProperty.IsManageable = true;
					webModelProperty.IsReadOnly = property.Type != moduleModel.PropertyType.Category;
					retVal.Properties.Add(webModelProperty);
				}
			}

			//Populate property values
			if (category.PropertyValues != null)
			{
				foreach (var propValue in category.PropertyValues.Select(x => x.ToWebModel()))
				{
					var property = retVal.Properties.FirstOrDefault(x => x.IsSuitableForValue(propValue));
					if (property == null)
					{
						//Need add dummy property for each value without property
						property = new webModel.Property(propValue, category.CatalogId, category.Id, moduleModel.PropertyType.Category);
						retVal.Properties.Add(property);
					}
					property.Values.Add(propValue);
				}
			}

			return retVal;
		}
        public IHttpActionResult GetNewCategory(string catalogId, [FromUri] string parentCategoryId = null)
        {
            var retVal = new webModel.Category
            {
                ParentId  = parentCategoryId,
                CatalogId = catalogId,
                Code      = Guid.NewGuid().ToString().Substring(0, 5),
                SeoInfos  = new List <SeoInfo>(),
                IsActive  = true
            };

            CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Create, retVal.ToModuleModel());
            retVal.SecurityScopes = GetObjectPermissionScopeStrings(retVal.ToModuleModel());

            return(Ok(retVal));
        }
        public IHttpActionResult GetNewCategory(string catalogId, [FromUri]string parentCategoryId = null)
        {
            var retVal = new webModel.Category
            {
                ParentId = parentCategoryId,
                CatalogId = catalogId,
                Catalog = _catalogService.GetById(catalogId).ToWebModel(),
                Code = Guid.NewGuid().ToString().Substring(0, 5),
                SeoInfos = new List<SeoInfo>(),
				IsActive = true
            };

            base.CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Create, retVal.ToModuleModel());
            retVal.SecurityScopes = base.GetObjectPermissionScopeStrings(retVal.ToModuleModel());

            return Ok(retVal);
        }
        public static webModel.Category ToWebModel(this moduleModel.Category category, IBlobUrlResolver blobUrlResolver = null, bool convertProps = true)
        {
            var retVal = new webModel.Category();

            //Do not use omu.InjectFrom for performance reasons
            retVal.Id           = category.Id;
            retVal.IsActive     = category.IsActive;
            retVal.IsVirtual    = category.IsVirtual;
            retVal.Name         = category.Name;
            retVal.ParentId     = category.ParentId;
            retVal.Path         = category.Path;
            retVal.TaxType      = category.TaxType;
            retVal.CatalogId    = category.CatalogId;
            retVal.Code         = category.Code;
            retVal.CreatedBy    = category.CreatedBy;
            retVal.CreatedDate  = category.CreatedDate;
            retVal.ModifiedBy   = category.ModifiedBy;
            retVal.ModifiedDate = category.ModifiedDate;

            retVal.SeoInfos = category.SeoInfos;
            if (!category.Outlines.IsNullOrEmpty())
            {
                //Minimize outline size
                retVal.Outlines = category.Outlines.Select(x => x.ToWebModel()).ToList();
            }

            //Init outline and path
            var parents = new List <moduleModel.Category>();

            if (category.Parents != null)
            {
                retVal.Outline = string.Join("/", category.Parents.Select(x => x.Id));
                retVal.Path    = string.Join("/", category.Parents.Select(x => x.Name));
            }

            //For virtual category links not needed
            if (!category.IsVirtual && category.Links != null)
            {
                retVal.Links = category.Links.Select(x => x.ToWebModel()).ToList();
            }

            //Need add property for each meta info
            retVal.Properties = new List <webModel.Property>();
            if (convertProps)
            {
                if (!category.Properties.IsNullOrEmpty())
                {
                    foreach (var property in category.Properties)
                    {
                        var webModelProperty = property.ToWebModel();
                        //Reset dict values to decrease response size
                        webModelProperty.DictionaryValues = null;
                        webModelProperty.Values           = new List <webModel.PropertyValue>();
                        webModelProperty.IsManageable     = true;
                        webModelProperty.IsReadOnly       = property.Type != moduleModel.PropertyType.Category;
                        retVal.Properties.Add(webModelProperty);
                    }
                }

                //Populate property values
                if (category.PropertyValues != null)
                {
                    foreach (var propValue in category.PropertyValues.Select(x => x.ToWebModel()))
                    {
                        var property = retVal.Properties.FirstOrDefault(x => x.Id == propValue.PropertyId);
                        if (property == null)
                        {
                            property = retVal.Properties.FirstOrDefault(x => x.Name.EqualsInvariant(propValue.PropertyName));
                        }
                        if (property == null)
                        {
                            //Need add dummy property for each value without property
                            property = new webModel.Property(propValue, category.CatalogId, moduleModel.PropertyType.Category);
                            retVal.Properties.Add(property);
                        }
                        property.Values.Add(propValue);
                    }
                }
            }

            if (category.Images != null)
            {
                retVal.Images = category.Images.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
            }

            return(retVal);
        }