Esempio n. 1
0
        public static webModel.Catalog ToWebModel(this moduleModel.Catalog catalog, bool convertProps = true)
        {
            var retVal = new webModel.Catalog();

            //Do not use omu.InjectFrom for performance reasons
            retVal.Id         = catalog.Id;
            retVal.Name       = catalog.Name;
            retVal.IsVirtual  = catalog.IsVirtual;
            retVal.Properties = new List <webModel.Property>();

            if (catalog.Languages != null)
            {
                retVal.Languages = catalog.Languages.Select(x => x.ToWebModel()).ToList();
            }

            if (convertProps)
            {
                //Need add property for each meta info
                if (catalog.Properties != null)
                {
                    foreach (var property in catalog.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.Catalog;
                        retVal.Properties.Add(webModelProperty);
                    }
                }

                //Populate property for property values
                if (catalog.PropertyValues != null)
                {
                    var sort = false;
                    foreach (var propValue in catalog.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, catalog.Id, moduleModel.PropertyType.Catalog);
                            retVal.Properties.Add(property);
                            sort = true;
                        }
                        property.Values.Add(propValue);
                    }
                    if (sort)
                    {
                        retVal.Properties = retVal.Properties.OrderBy(x => x.Name).ToList();
                    }
                }
            }
            return(retVal);
        }
Esempio n. 2
0
        public static moduleModel.Catalog ToModuleModel(this webModel.Catalog catalog)
        {
            var retVal = new moduleModel.Catalog();

            retVal.InjectFrom(catalog);
            if (catalog.Languages != null)
            {
                retVal.Languages = catalog.Languages.Select(x => x.ToModuleModel()).ToList();
            }

            if (catalog.Properties != null)
            {
                retVal.PropertyValues = new List <moduleModel.PropertyValue>();
                foreach (var property in catalog.Properties)
                {
                    foreach (var propValue in property.Values)
                    {
                        propValue.ValueType = property.ValueType;
                        //Need populate required fields
                        propValue.PropertyName = property.Name;
                        retVal.PropertyValues.Add(propValue.ToModuleModel());
                    }
                }
            }
            return(retVal);
        }
        private void UpdateCatalog(webModel.Catalog catalog)
        {
            var moduleCatalog = catalog.ToModuleModel();

            CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Update, catalog);

            _catalogService.Update(new[] { moduleCatalog });
        }
        public IHttpActionResult Create(webModel.Catalog catalog)
        {
            var newCatalog = _catalogService.Create(catalog.ToModuleModel());
            var retVal     = newCatalog.ToWebModel();

            //Need for UI permission checks
            retVal.SecurityScopes = GetObjectPermissionScopeStrings(newCatalog);
            return(Ok(retVal));
        }
 public IHttpActionResult Create(webModel.Catalog catalog)
 {
     if ((_permissionService.UserHasAnyPermission(RequestContext.Principal.Identity.Name, PredefinedPermissions.CatalogsManage) && !catalog.Virtual) ||
         (_permissionService.UserHasAnyPermission(RequestContext.Principal.Identity.Name, PredefinedPermissions.VirtualCatalogsManage) && catalog.Virtual))
     {
         var retVal = _catalogService.Create(catalog.ToModuleModel());
         return(Ok(retVal.ToWebModel()));
     }
     else
     {
         throw new UnauthorizedAccessException();
     }
 }
		public static webModel.Catalog ToWebModel(this moduleModel.Catalog catalog, bool convertProps = true)
		{
			var retVal = new webModel.Catalog();
			retVal.InjectFrom(catalog);
			retVal.Properties = new List<webModel.Property>();
			if (catalog.Languages != null)
			{
				retVal.Languages = catalog.Languages.Select(x=>x.ToWebModel()).ToList();
			}

            if (convertProps)
            {
                //Need add property for each meta info
                if (catalog.Properties != null)
                {
                    foreach (var property in catalog.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.Catalog;
                        retVal.Properties.Add(webModelProperty);
                    }
                }

                //Populate property for property values
                if (catalog.PropertyValues != null)
                {
                    foreach (var propValue in catalog.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, catalog.Id, null, moduleModel.PropertyType.Catalog);
                            retVal.Properties.Add(property);
                        }
                       property.Values.Add(propValue);
                    }
                }
            }
			return retVal;
		}
Esempio n. 7
0
        public static webModel.Catalog ToWebModel(this moduleModel.Catalog catalog, bool convertProps = true)
        {
            var retVal = new webModel.Catalog();

            retVal.InjectFrom(catalog);
            retVal.Properties = new List <webModel.Property>();
            if (catalog.Languages != null)
            {
                retVal.Languages = catalog.Languages.Select(x => x.ToWebModel()).ToList();
            }

            if (convertProps)
            {
                //Need add property for each meta info
                if (catalog.Properties != null)
                {
                    foreach (var property in catalog.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.Catalog;
                        retVal.Properties.Add(webModelProperty);
                    }
                }

                //Populate property for property values
                if (catalog.PropertyValues != null)
                {
                    foreach (var propValue in catalog.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, catalog.Id, null, moduleModel.PropertyType.Catalog);
                            retVal.Properties.Add(property);
                        }
                        property.Values.Add(propValue);
                    }
                }
            }
            return(retVal);
        }
        public IHttpActionResult GetNewCatalog()
        {
            var retVal = new webModel.Catalog
            {
                Name      = "New catalog",
                Languages = new List <webModel.CatalogLanguage>
                {
                    new webModel.CatalogLanguage
                    {
                        IsDefault    = true,
                        LanguageCode = "en-US"
                    }
                }
            };

            //retVal = _catalogService.Create(retVal.ToModuleModel()).ToWebModel();
            return(Ok(retVal));
        }
        public IHttpActionResult GetNewCatalog()
        {
            var retVal = new webModel.Catalog
            {
                Name      = "New catalog",
                Languages = new List <webModel.CatalogLanguage>
                {
                    new webModel.CatalogLanguage
                    {
                        IsDefault    = true,
                        LanguageCode = "en-US"
                    }
                }
            };

            retVal.SecurityScopes = GetObjectPermissionScopeStrings(retVal);

            return(Ok(retVal));
        }
Esempio n. 10
0
        public static webModel.Catalog ToWebModel(this moduleModel.Catalog catalog, moduleModel.Property[] properties = null)
        {
            var retVal = new webModel.Catalog();

            retVal.InjectFrom(catalog);
            retVal.Properties = new List <webModel.Property>();
            if (catalog.Languages != null)
            {
                retVal.Languages = catalog.Languages.Select(x => x.ToWebModel()).ToList();
            }

            //Need add property for each meta info
            if (properties != null)
            {
                foreach (var property in properties)
                {
                    var webModelProperty = property.ToWebModel();
                    webModelProperty.Values       = new List <webModel.PropertyValue>();
                    webModelProperty.IsManageable = true;
                    webModelProperty.IsReadOnly   = property.Type != moduleModel.PropertyType.Catalog;
                    retVal.Properties.Add(webModelProperty);
                }
            }

            //Populate property values
            if (catalog.PropertyValues != null)
            {
                foreach (var propValue in catalog.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, catalog.Id, null, moduleModel.PropertyType.Catalog);
                        retVal.Properties.Add(property);
                    }
                    property.Values.Add(propValue);
                }
            }

            return(retVal);
        }
		public static webModel.Catalog ToWebModel(this moduleModel.Catalog catalog, moduleModel.Property[] properties = null)
		{
			var retVal = new webModel.Catalog();
			retVal.InjectFrom(catalog);
			retVal.Properties = new List<webModel.Property>();
			if (catalog.Languages != null)
			{
				retVal.Languages = catalog.Languages.Select(x=>x.ToWebModel()).ToList();
			}
		
			//Need add property for each meta info
			if (properties != null)
			{
				foreach (var property in properties)
				{
					var webModelProperty = property.ToWebModel();
					webModelProperty.Values = new List<webModel.PropertyValue>();
					webModelProperty.IsManageable = true;
					webModelProperty.IsReadOnly = property.Type != moduleModel.PropertyType.Catalog;
					retVal.Properties.Add(webModelProperty);
				}
			}

			//Populate property values
			if (catalog.PropertyValues != null)
			{
				foreach (var propValue in catalog.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, catalog.Id, null, moduleModel.PropertyType.Catalog);
						retVal.Properties.Add(property);
					}
					property.Values.Add(propValue);
				}
			}

			return retVal;
		}
        public IHttpActionResult GetNewCatalog()
        {
            var retVal = new webModel.Catalog
            {
                Name = "New catalog",
                Languages = new List<webModel.CatalogLanguage>
                {
                    new webModel.CatalogLanguage
                    {
                        IsDefault = true,
                        LanguageCode = "en-US"
                    }
                }
            };

            retVal.SecurityScopes = GetObjectPermissionScopeStrings(retVal);

            return Ok(retVal);
        }
Esempio n. 13
0
 public IHttpActionResult Update(webModel.Catalog catalog)
 {
     UpdateCatalog(catalog);
     return(StatusCode(HttpStatusCode.NoContent));
 }
 public IHttpActionResult GetNewVirtualCatalog()
 {
     var retVal = new webModel.Catalog
     {
         Name = "New virtual catalog",
         Virtual = true,
         Languages = new List<webModel.CatalogLanguage>
         {
             new webModel.CatalogLanguage
             {
                 IsDefault = true, 
                 LanguageCode = "en-US"
             }
         }
     };
     //retVal = _catalogService.Create(retVal.ToModuleModel()).ToWebModel();
     return Ok(retVal);
 }
        private void UpdateCatalog(webModel.Catalog catalog)
        {
            var moduleCatalog = catalog.ToModuleModel();

            _catalogService.Update(new moduleModel.Catalog[] { moduleCatalog });
        }