/// <summary>
 /// Indicates whether the given value is unique in the database
 /// </summary>
 /// <param name="customUrl"></param>
 /// <returns></returns>
 public bool IsUnique(string customUrl)
 {
     // is a non-empty value provided?
     if (!string.IsNullOrEmpty(customUrl))
     {
         // is the new value different from the existing value?
         if (this.OriginalValue.ToUpperInvariant() != customUrl.ToUpperInvariant())
         {
             // make sure the new value does not appear in the database
             return(!CustomUrlDataSource.IsAlreadyUsed(customUrl));
         }
     }
     return(true);
 }
        private void UpdateField(Category category, string field)
        {
            if (field != null)
            {
                string cleanField = field.Trim().ToLowerInvariant();
                string fieldValue = GetValueFromFormPost(category.Id, cleanField);
                switch (cleanField)
                {
                case "customurl":
                    bool   isValid      = false;
                    string oldCustomUrl = category.CustomUrl;
                    string newCustomUrl = fieldValue.Trim();
                    if (!string.IsNullOrEmpty(newCustomUrl) && string.IsNullOrEmpty(oldCustomUrl) || oldCustomUrl != newCustomUrl)
                    {
                        isValid = !CustomUrlDataSource.IsAlreadyUsed(newCustomUrl);
                    }
                    else
                    {
                        isValid = true;
                    }
                    if (isValid)
                    {
                        category.CustomUrl = fieldValue;
                    }
                    break;

                case "displaypage":
                    if (IsValidListItemValue(category, field, fieldValue, true))
                    {
                        category.Webpage = WebpageDataSource.Load(AlwaysConvert.ToInt(fieldValue));
                    }
                    break;

                case "visibilityid":
                    if (IsValidListItemValue(category, field, fieldValue, false))
                    {
                        category.VisibilityId = AlwaysConvert.ToByte(fieldValue);
                    }
                    break;

                case "description":
                    category.Description = fieldValue;
                    break;

                case "metadescription":
                    category.MetaDescription = fieldValue;
                    break;

                case "metakeywords":
                    category.MetaKeywords = fieldValue;
                    break;

                case "name":
                    if (!string.IsNullOrEmpty(fieldValue))
                    {
                        category.Name = fieldValue;
                    }
                    break;

                case "summary":
                    category.Summary = fieldValue;
                    break;

                case "thumbnailalttext":
                    category.ThumbnailAltText = fieldValue;
                    break;

                case "thumbnailurl":
                    category.ThumbnailUrl = fieldValue;
                    break;

                case "pagetitle":
                    category.Title = fieldValue;
                    break;

                case "htmlhead":
                    category.HtmlHead = fieldValue;
                    break;
                }
            }
        }