PageModel.Create C# (CSharp) Method

Create() public method

public Create ( dynamic, item ) : PageModel,
item dynamic,
return PageModel,
    public PageModel Create(dynamic item)
    {
        Assert.IsTrue(item != null);
        Value = item;
        Value.Id = Value.Title;
        Validate();
        if (HasError) return this;

        if (Repository.Exists(Value.Id))
        {
            Errors.Add("Title", string.Format("{0} exisits already.", Value.Title));
        }

        if (!HasError) Value.Id = Repository.Save(Value.Id, Value);

        return this;
    }

Usage Example

コード例 #1
0
ファイル: PageModelTest.cs プロジェクト: yysun/Rabbit
    public void Create_Should_Validate_Title()
    {
        dynamic data = new ExpandoObject();
        data.Id = "id";
        data.Title = null; // <-- it should catch this
        var repository = new Mock();
        var model = new PageModel();
        model.Repository = repository;

        model.Create(data);
        Assert.IsTrue(model.HasError);
    }
All Usage Examples Of PageModel::Create