Esempio n. 1
0
        public ActionResult PropertyTypeDelete(PropertyTypeDetail model)
        {
            string html = null;

            try
            {
                int a = obj.FunExecuteNonQuery("exec dbo.PropertyTypeDetail_Delete '" + model.PropertyTypeId + "'");
                if (a > 0)
                {
                    //return RedirectToAction("PropertyTypeGet");
                    DataTable dt = obj.FunDataTable("SELECT * from dbo.PropertyTypeDetail_Get ()");
                    if (dt.Rows.Count > 0)
                    {
                        int[]         columnHide = { 0 };
                        StringBuilder htmlTable  = CommonUtil.htmlTableEditMode(dt, columnHide);
                        return(Json(new { Flag = 0, Html = htmlTable.ToString() }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        html = "<div class='alert alert-danger'>'" + Resources.Resource1.norecord + "'</div>";
                        return(Json(new { Flag = 0, Html = html }, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    html = Resources.Resource1.deletefailed;
                    return(Json(new { Flag = 2, Html = html }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                html = Resources.Resource1.deletefailed;
                return(Json(new { Flag = 2, Html = html }, JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 2
0
        public ActionResult PropertyTypeGet(PropertyTypeDetail model)
        {
            string html = null;

            try
            {
                DataTable dt = obj.FunDataTable("SELECT * from dbo.PropertyTypeDetail_Get ()");
                if (dt.Rows.Count > 0)
                {
                    int[]         columnHide = { 0 };
                    StringBuilder htmlTable  = CommonUtil.htmlTableEditMode(dt, columnHide);
                    return(Json(new { Flag = 0, Html = htmlTable.ToString() }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    html = "<div class='alert alert-danger'>'" + Resources.Resource1.norecord + "'</div>";
                    return(Json(new { Flag = 0, Html = html }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                html = "Fatch Result Failed !!!";
                return(Json(new { Flag = 2, Html = html }, JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 3
0
    public void Is_Built_Correctly()
    {
        // Arrange
        const int    testId                = 99;
        var          testKey               = Guid.NewGuid();
        const string testAlias             = "memberType";
        const string testName              = "Member Type";
        const string testPropertyGroupName = "Content";
        const int    testParentId          = 98;
        const int    testCreatorId         = 22;
        var          testCreateDate        = DateTime.Now.AddHours(-1);
        var          testUpdateDate        = DateTime.Now;
        const int    testLevel             = 3;
        const string testPath              = "-1, 4, 10";
        const int    testSortOrder         = 5;
        const string testDescription       = "The description";
        const string testIcon              = "icon";
        const string testThumbnail         = "thumnail";
        const bool   testTrashed           = true;
        const int    testPropertyTypeIdsIncrementingFrom = 200;
        var          testPropertyType1 =
            new PropertyTypeDetail {
            Alias = "title", Name = "Title", SortOrder = 1, DataTypeId = -88
        };
        var testPropertyType2 =
            new PropertyTypeDetail {
            Alias = "bodyText", Name = "Body Text", SortOrder = 2, DataTypeId = -87
        };
        var testPropertyData1 = new KeyValuePair <string, object>("title", "Name member");

        var builder = new MemberTypeBuilder();

        // Act
        var memberType = builder
                         .WithId(testId)
                         .WithKey(testKey)
                         .WithAlias(testAlias)
                         .WithName(testName)
                         .WithCreatorId(testCreatorId)
                         .WithCreateDate(testCreateDate)
                         .WithUpdateDate(testUpdateDate)
                         .WithParentId(testParentId)
                         .WithLevel(testLevel)
                         .WithPath(testPath)
                         .WithSortOrder(testSortOrder)
                         .WithDescription(testDescription)
                         .WithIcon(testIcon)
                         .WithThumbnail(testThumbnail)
                         .WithTrashed(testTrashed)
                         .WithPropertyTypeIdsIncrementingFrom(200)
                         .WithMembershipPropertyGroup()
                         .AddPropertyGroup()
                         .WithId(1)
                         .WithName(testPropertyGroupName)
                         .WithSortOrder(1)
                         .AddPropertyType()
                         .WithAlias(testPropertyType1.Alias)
                         .WithName(testPropertyType1.Name)
                         .WithSortOrder(testPropertyType1.SortOrder)
                         .Done()
                         .AddPropertyType()
                         .WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
                         .WithValueStorageType(ValueStorageType.Ntext)
                         .WithAlias(testPropertyType2.Alias)
                         .WithName(testPropertyType2.Name)
                         .WithSortOrder(testPropertyType2.SortOrder)
                         .WithDataTypeId(testPropertyType2.DataTypeId)
                         .Done()
                         .Done()
                         .WithMemberCanEditProperty(testPropertyType1.Alias, true)
                         .WithMemberCanViewProperty(testPropertyType2.Alias, true)
                         .Build();

        // Assert
        Assert.AreEqual(testId, memberType.Id);
        Assert.AreEqual(testAlias, memberType.Alias);
        Assert.AreEqual(testName, memberType.Name);
        Assert.AreEqual(testKey, memberType.Key);
        Assert.AreEqual(testCreateDate, memberType.CreateDate);
        Assert.AreEqual(testUpdateDate, memberType.UpdateDate);
        Assert.AreEqual(testCreatorId, memberType.CreatorId);
        Assert.AreEqual(testParentId, memberType.ParentId);
        Assert.AreEqual(testLevel, memberType.Level);
        Assert.AreEqual(testPath, memberType.Path);
        Assert.AreEqual(testSortOrder, memberType.SortOrder);
        Assert.AreEqual(testDescription, memberType.Description);
        Assert.AreEqual(testIcon, memberType.Icon);
        Assert.AreEqual(testThumbnail, memberType.Thumbnail);
        Assert.AreEqual(testTrashed, memberType.Trashed);
        Assert.IsFalse(memberType.IsContainer);
        Assert.AreEqual(3, memberType.PropertyTypes.Count()); // 1 from membership properties group, 2 custom

        var propertyTypeIds = memberType.PropertyTypes.Select(x => x.Id).OrderBy(x => x).ToArray();

        Assert.AreEqual(testPropertyTypeIdsIncrementingFrom + 1, propertyTypeIds.Min());
        Assert.AreEqual(testPropertyTypeIdsIncrementingFrom + 3, propertyTypeIds.Max());

        Assert.IsTrue(memberType.MemberCanEditProperty(testPropertyType1.Alias));
        Assert.IsFalse(memberType.MemberCanViewProperty(testPropertyType1.Alias));
        Assert.IsTrue(memberType.MemberCanViewProperty(testPropertyType2.Alias));
        Assert.IsFalse(memberType.MemberCanEditProperty(testPropertyType2.Alias));
    }
Esempio n. 4
0
    public void Is_Built_Correctly()
    {
        // Arrange
        const int    testMemberTypeId                = 99;
        const string testMemberTypeAlias             = "memberType";
        const string testMemberTypeName              = "Member Type";
        const string testMemberTypePropertyGroupName = "Content";
        const int    testId                     = 10;
        const string testName                   = "Fred";
        const string testUsername               = "******";
        const string testRawPasswordValue       = "raw pass";
        const string testEmail                  = "*****@*****.**";
        const int    testCreatorId              = 22;
        const int    testLevel                  = 3;
        const string testPath                   = "-1, 4, 10";
        const bool   testIsApproved             = true;
        const bool   testIsLockedOut            = true;
        const int    testSortOrder              = 5;
        const bool   testTrashed                = false;
        var          testKey                    = Guid.NewGuid();
        var          testCreateDate             = DateTime.Now.AddHours(-1);
        var          testUpdateDate             = DateTime.Now;
        const int    testFailedPasswordAttempts = 22;
        var          testLastLockoutDate        = DateTime.Now.AddHours(-2);
        var          testLastLoginDate          = DateTime.Now.AddHours(-3);
        var          testLastPasswordChangeDate = DateTime.Now.AddHours(-4);
        var          testPropertyType1          =
            new PropertyTypeDetail {
            Alias = "title", Name = "Title", SortOrder = 1, DataTypeId = -88
        };
        var testPropertyType2 =
            new PropertyTypeDetail {
            Alias = "bodyText", Name = "Body Text", SortOrder = 2, DataTypeId = -87
        };
        var testPropertyType3 = new PropertyTypeDetail
        {
            Alias       = "author",
            Name        = "Author",
            Description = "Writer of the article",
            SortOrder   = 1,
            DataTypeId  = -88,
        };
        var       testGroups                      = new[] { "group1", "group2" };
        var       testPropertyData1               = new KeyValuePair <string, object>("title", "Name member");
        var       testPropertyData2               = new KeyValuePair <string, object>("bodyText", "This is a subpage");
        var       testPropertyData3               = new KeyValuePair <string, object>("author", "John Doe");
        var       testAdditionalData1             = new KeyValuePair <string, object>("test1", 123);
        var       testAdditionalData2             = new KeyValuePair <string, object>("test2", "hello");
        const int testPropertyIdsIncrementingFrom = 200;

        var builder = new MemberBuilder();

        // Act
        var member = builder
                     .AddMemberType()
                     .WithId(testMemberTypeId)
                     .WithAlias(testMemberTypeAlias)
                     .WithName(testMemberTypeName)
                     .WithMembershipPropertyGroup()
                     .AddPropertyGroup()
                     .WithId(1)
                     .WithName(testMemberTypePropertyGroupName)
                     .WithSortOrder(1)
                     .AddPropertyType()
                     .WithAlias(testPropertyType1.Alias)
                     .WithName(testPropertyType1.Name)
                     .WithSortOrder(testPropertyType1.SortOrder)
                     .WithDataTypeId(testPropertyType1.DataTypeId)
                     .Done()
                     .AddPropertyType()
                     .WithValueStorageType(ValueStorageType.Ntext)
                     .WithAlias(testPropertyType2.Alias)
                     .WithName(testPropertyType2.Name)
                     .WithSortOrder(testPropertyType2.SortOrder)
                     .WithDataTypeId(testPropertyType2.DataTypeId)
                     .Done()
                     .AddPropertyType()
                     .WithAlias(testPropertyType3.Alias)
                     .WithName(testPropertyType3.Name)
                     .WithDescription(testPropertyType3.Description)
                     .WithSortOrder(testPropertyType3.SortOrder)
                     .WithDataTypeId(testPropertyType3.DataTypeId)
                     .Done()
                     .Done()
                     .Done()
                     .WithId(testId)
                     .WithKey(testKey)
                     .WithName(testName)
                     .WithLogin(testUsername, testRawPasswordValue)
                     .WithEmail(testEmail)
                     .WithCreatorId(testCreatorId)
                     .WithCreateDate(testCreateDate)
                     .WithUpdateDate(testUpdateDate)
                     .WithLevel(testLevel)
                     .WithPath(testPath)
                     .WithFailedPasswordAttempts(testFailedPasswordAttempts)
                     .WithIsApproved(testIsApproved)
                     .WithIsLockedOut(testIsLockedOut, testLastLockoutDate)
                     .WithLastLoginDate(testLastLoginDate)
                     .WithLastPasswordChangeDate(testLastPasswordChangeDate)
                     .WithSortOrder(testSortOrder)
                     .WithTrashed(testTrashed)
                     .AddMemberGroups()
                     .WithValue(testGroups[0])
                     .WithValue(testGroups[1])
                     .Done()
                     .AddAdditionalData()
                     .WithKeyValue(testAdditionalData1.Key, testAdditionalData1.Value)
                     .WithKeyValue(testAdditionalData2.Key, testAdditionalData2.Value)
                     .Done()
                     .WithPropertyIdsIncrementingFrom(200)
                     .AddPropertyData()
                     .WithKeyValue(testPropertyData1.Key, testPropertyData1.Value)
                     .WithKeyValue(testPropertyData2.Key, testPropertyData2.Value)
                     .WithKeyValue(testPropertyData3.Key, testPropertyData3.Value)
                     .Done()
                     .Build();

        // Assert
        Assert.AreEqual(testMemberTypeId, member.ContentTypeId);
        Assert.AreEqual(testMemberTypeAlias, member.ContentType.Alias);
        Assert.AreEqual(testMemberTypeName, member.ContentType.Name);
        Assert.AreEqual(testId, member.Id);
        Assert.AreEqual(testKey, member.Key);
        Assert.AreEqual(testName, member.Name);
        Assert.AreEqual(testCreateDate, member.CreateDate);
        Assert.AreEqual(testUpdateDate, member.UpdateDate);
        Assert.AreEqual(testCreatorId, member.CreatorId);
        Assert.AreEqual(testFailedPasswordAttempts, member.FailedPasswordAttempts);
        Assert.AreEqual(testIsApproved, member.IsApproved);
        Assert.AreEqual(testIsLockedOut, member.IsLockedOut);
        Assert.AreEqual(testLastLockoutDate, member.LastLockoutDate);
        Assert.AreEqual(testLastLoginDate, member.LastLoginDate);
        Assert.AreEqual(testLastPasswordChangeDate, member.LastPasswordChangeDate);
        Assert.AreEqual(testGroups, member.Groups.ToArray());
        Assert.AreEqual(4, member.Properties.Count); // 1 from membership properties group, 3 custom
        Assert.AreEqual(testPropertyData1.Value, member.GetValue <string>(testPropertyData1.Key));
        Assert.AreEqual(testPropertyData2.Value, member.GetValue <string>(testPropertyData2.Key));
        Assert.AreEqual(testPropertyData3.Value, member.GetValue <string>(testPropertyData3.Key));

        var propertyIds = member.Properties.Select(x => x.Id).OrderBy(x => x).ToArray();

        Assert.AreEqual(testPropertyIdsIncrementingFrom + 1, propertyIds.Min());
        Assert.AreEqual(testPropertyIdsIncrementingFrom + 4, propertyIds.Max());

        Assert.AreEqual(2, member.AdditionalData.Count);
        Assert.AreEqual(testAdditionalData1.Value, member.AdditionalData[testAdditionalData1.Key]);
        Assert.AreEqual(testAdditionalData2.Value, member.AdditionalData[testAdditionalData2.Key]);
    }
    public void Is_Built_Correctly()
    {
        // Arrange
        const int    testId                = 99;
        var          testKey               = Guid.NewGuid();
        const string testAlias             = "mediaType";
        const string testName              = "Content Type";
        const string testPropertyGroupName = "Content";
        const int    testParentId          = 98;
        const int    testCreatorId         = 22;
        var          testCreateDate        = DateTime.Now.AddHours(-1);
        var          testUpdateDate        = DateTime.Now;
        const int    testLevel             = 3;
        const string testPath              = "-1, 4, 10";
        const int    testSortOrder         = 5;
        const string testDescription       = "The description";
        const string testIcon              = "icon";
        const string testThumbnail         = "thumnail";
        const bool   testTrashed           = true;
        const int    testPropertyTypeIdsIncrementingFrom = 200;
        var          testPropertyType1 =
            new PropertyTypeDetail {
            Alias = "title", Name = "Title", SortOrder = 1, DataTypeId = -88
        };
        var testPropertyType2 =
            new PropertyTypeDetail {
            Alias = "bodyText", Name = "Body Text", SortOrder = 2, DataTypeId = -87
        };
        var testTemplate1 = new TemplateDetail {
            Id = 200, Alias = "template1", Name = "Template 1"
        };
        var testTemplate2 = new TemplateDetail {
            Id = 201, Alias = "template2", Name = "Template 2"
        };
        var testAllowedContentType1 = new AllowedContentTypeDetail {
            Id = 300, Alias = "subType1", SortOrder = 1
        };
        var testAllowedContentType2 = new AllowedContentTypeDetail {
            Id = 301, Alias = "subType2", SortOrder = 2
        };

        var builder = new ContentTypeBuilder();

        // Act
        var contentType = builder
                          .WithId(testId)
                          .WithKey(testKey)
                          .WithAlias(testAlias)
                          .WithName(testName)
                          .WithCreatorId(testCreatorId)
                          .WithCreateDate(testCreateDate)
                          .WithUpdateDate(testUpdateDate)
                          .WithParentId(testParentId)
                          .WithLevel(testLevel)
                          .WithPath(testPath)
                          .WithSortOrder(testSortOrder)
                          .WithDescription(testDescription)
                          .WithIcon(testIcon)
                          .WithThumbnail(testThumbnail)
                          .WithTrashed(testTrashed)
                          .WithPropertyTypeIdsIncrementingFrom(200)
                          .AddPropertyGroup()
                          .WithName(testPropertyGroupName)
                          .WithSortOrder(1)
                          .AddPropertyType()
                          .WithAlias(testPropertyType1.Alias)
                          .WithName(testPropertyType1.Name)
                          .WithSortOrder(testPropertyType1.SortOrder)
                          .WithDataTypeId(testPropertyType1.DataTypeId)
                          .Done()
                          .AddPropertyType()
                          .WithValueStorageType(ValueStorageType.Ntext)
                          .WithAlias(testPropertyType2.Alias)
                          .WithName(testPropertyType2.Name)
                          .WithSortOrder(testPropertyType2.SortOrder)
                          .WithDataTypeId(testPropertyType2.DataTypeId)
                          .Done()
                          .Done()
                          .AddAllowedTemplate()
                          .WithId(testTemplate1.Id)
                          .WithAlias(testTemplate1.Alias)
                          .WithName(testTemplate1.Name)
                          .Done()
                          .AddAllowedTemplate()
                          .WithId(testTemplate2.Id)
                          .WithAlias(testTemplate2.Alias)
                          .WithName(testTemplate2.Name)
                          .Done()
                          .WithDefaultTemplateId(testTemplate1.Id)
                          .AddAllowedContentType()
                          .WithId(testAllowedContentType1.Id)
                          .WithAlias(testAllowedContentType1.Alias)
                          .WithSortOrder(testAllowedContentType1.SortOrder)
                          .Done()
                          .AddAllowedContentType()
                          .WithId(testAllowedContentType2.Id)
                          .WithAlias(testAllowedContentType2.Alias)
                          .WithSortOrder(testAllowedContentType2.SortOrder)
                          .Done()
                          .Build();

        // Assert
        Assert.AreEqual(testId, contentType.Id);
        Assert.AreEqual(testAlias, contentType.Alias);
        Assert.AreEqual(testName, contentType.Name);
        Assert.AreEqual(testKey, contentType.Key);
        Assert.AreEqual(testCreateDate, contentType.CreateDate);
        Assert.AreEqual(testUpdateDate, contentType.UpdateDate);
        Assert.AreEqual(testCreatorId, contentType.CreatorId);
        Assert.AreEqual(testParentId, contentType.ParentId);
        Assert.AreEqual(testLevel, contentType.Level);
        Assert.AreEqual(testPath, contentType.Path);
        Assert.AreEqual(testSortOrder, contentType.SortOrder);
        Assert.AreEqual(testDescription, contentType.Description);
        Assert.AreEqual(testIcon, contentType.Icon);
        Assert.AreEqual(testThumbnail, contentType.Thumbnail);
        Assert.AreEqual(testTrashed, contentType.Trashed);
        Assert.IsFalse(contentType.IsContainer);
        Assert.AreEqual(2, contentType.PropertyTypes.Count());

        var propertyTypeIds = contentType.PropertyTypes.Select(x => x.Id).OrderBy(x => x).ToArray();

        Assert.AreEqual(testPropertyTypeIdsIncrementingFrom + 1, propertyTypeIds.Min());
        Assert.AreEqual(testPropertyTypeIdsIncrementingFrom + 2, propertyTypeIds.Max());

        var allowedTemplates = contentType.AllowedTemplates.ToList();

        Assert.AreEqual(2, allowedTemplates.Count);
        Assert.AreEqual(testTemplate1.Id, allowedTemplates[0].Id);
        Assert.AreEqual(testTemplate1.Alias, allowedTemplates[0].Alias);
        Assert.AreEqual(testTemplate1.Name, allowedTemplates[0].Name);
        Assert.AreEqual(testTemplate1.Id, contentType.DefaultTemplate.Id);

        var allowedContentTypes = contentType.AllowedContentTypes.ToList();

        Assert.AreEqual(2, allowedContentTypes.Count);
        Assert.AreEqual(testAllowedContentType1.Id, allowedContentTypes[0].Id.Value);
        Assert.AreEqual(testAllowedContentType1.Alias, allowedContentTypes[0].Alias);
        Assert.AreEqual(testAllowedContentType1.SortOrder, allowedContentTypes[0].SortOrder);
    }