public DataboundDatagridItemCreatorForm(ISomeService someService)
        {
            _view = new DataboundDatagridItemCreatorFormView();

            var someText   = LocalValueFieldBuilder.Build(_view.SomeText, Validator.IsNotNullRef);
            var someNumber = LocalValueFieldBuilder.BuildNullableInt(_view.SomeNumber, Validator.IsNotNull, Validator.MustBePositive <int>());
            var someBool   = LocalValueFieldBuilder.Build(_view.SomeBool);

            _view.SomeTrait.PermittedValues = EnumExtensions.GetEnumValues <SomeTraitType>().Select(x => (SomeTraitType?)x);
            var someTrait = LocalValueFieldBuilder.Build(_view.SomeTrait, Validator.IsNotNull);

            var createProduct = RemoteActionBuilder.Build(_view.CreateAction,
                                                          () => someService.Create(
                                                              new SomeDto {
                SomeNumber = someNumber.Value.GetValueOrDefault(),
                SomeText   = someText.Value,
                SomeBool   = someBool.Value,
                SomeTrait  = someTrait.Value.Value
            }),
                                                          x => {
                CreatedItem = x;
                Ended?.Invoke(this, Outcome.Created);
            });

            var isFormValid = new AggregatedErrorsValue <bool>(false, self => !self.Errors.Any(), x => {
                x.Observes(someText);
                x.Observes(someNumber);
                x.Observes(someBool);
                x.Observes(someTrait);
            });

            createProduct.BindEnableAndInitialize(isFormValid);
        }
예제 #2
0
        public DataboundDatagridForm()
        {
            _view = new DataboundDatagridFormView();
            Func <string, BaseUnboundColumnBuilder <SomeDto> > build = x => UnboundDataGridColumnBuilder.For <SomeDto>(x);

            Items = DataGridModel <SomeDto> .CreateAndBindReloadable(
                _view.Items,
                () => Ended?.Invoke(this, Outcome.ReloadData),
                (el, theaderHeight, _) => //most of the time you would use Toolkit.DefaultTableBodyHeightProvider()
                el.GetAvailableHeightForFormElement(0, 2) - theaderHeight - _view.Help.Widget.OffsetHeight,
                new List <IDataGridColumn <SomeDto> > {
                build("#")
                .WithValueLocalized(x => Items.Items.IndexOf(x) + 1)
                .NonTransformable()
                .Build(),
                build("SomeNumber")
                .WithValueLocalized(x => x.SomeNumber)
                .TransformableDefault()
                .Observes(x => nameof(x.SomeNumber))
                .Build(),
                build("SomeText")
                .WithValue(x => x.SomeText)
                .TransformableDefault()
                .Observes(x => nameof(x.SomeText))
                .Build(),
                build("SomeBool")
                .WithValueLocalized(x => x.SomeBool)
                .TransformableDefault()
                .Observes(x => nameof(x.SomeBool))
                .Build(),
                build("SomeTrait")
                .WithValueAsText(x => x.SomeTrait, x => x.ToString())
                .TransformableAsText()
                .Observes(x => nameof(x.SomeTrait))
                .Build(),
            }).model;

            Items.Activated.Changed += (sender, oldValue, newValue, errors, isUserChange) => {
                if (newValue == null)
                {
                    return;
                }
                ChoosenItem = Items.Activated.Value;
                Ended?.Invoke(this, Outcome.EditItemDemanded);
            };

            LocalActionBuilder.Build(_view.Creator, () => Ended?.Invoke(this, Outcome.CreateItemDemanded));

            //button that is activated only if exactly one record is selected in the datagarid
            var activateEditor = LocalActionBuilder.Build(_view.Editor, () => {
                ChoosenItem = Items.Selected[0];
                Ended?.Invoke(this, Outcome.EditItemDemanded);
            });

            activateEditor.BindSelectionIntoEnabled(Items, SelectionNeeded.ExactlyOneSelected);
        }
        public async Task InitializeFrom(SomeDto itemToEdit)
        {
            _someDtoId = itemToEdit.Id;

            await _someText.BindTo(itemToEdit);

            await _someNumber.BindTo(itemToEdit);

            await _someBool.BindTo(itemToEdit);

            await _someTrait.BindTo(itemToEdit);
        }
예제 #4
0
        static void Main(string[] args)
        {
            string connectionString = null;
            string tableName        = null;
            string keyName          = null;
            string valueName        = null;

            var parser = new Fclp.FluentCommandLineParser();

            parser.Setup <string>('c', "connectionString").Callback(x => connectionString = x);
            parser.Setup <string>('t', "tableName").Callback(x => tableName = x);
            parser.Setup <string>('k', "key").Callback(x => keyName         = x);
            parser.Setup <string>('v', "value").Callback(x => valueName     = x);
            parser.Parse(args);

            Console.WriteLine("Connecting...");

            var dic1 = new SqlDictionary <int, int>();

            dic1.Load(connectionString, "intint", keyName, valueName);
            Console.WriteLine("SqlDictionary.Clear");
            dic1.Clear();
            Console.WriteLine("dic1.Count == 0");
            Debug.Assert(dic1.Count == 0);
            dic1.Add(1, 2);
            Console.WriteLine("dic1.Count == 1");
            Debug.Assert(dic1.Count == 1);
            Console.WriteLine("dic1[1] == 2");
            Debug.Assert(dic1[1] == 2);
            dic1.Remove(1);
            Console.WriteLine("dic1.Count == 0");
            Debug.Assert(dic1.Count == 0);
            dic1[1] = 3;
            Console.WriteLine("dic1[1] == 3");
            Debug.Assert(dic1[1] == 3);
            dic1[1] = 4;
            Console.WriteLine("dic1[1] == 4");
            Debug.Assert(dic1[1] == 4);

            var dic2 = new SqlDictionary <int, string>();

            dic2.Load(connectionString, "intstring", keyName, valueName);
            dic2.Clear();
            dic2.Add(1, "2");
            dic2.Remove(1);
            dic2[1] = "3";
            dic2[1] = "4";

            var dic3 = new SqlDictionary <string, string>();

            dic3.Load(connectionString, "stringstring", keyName, valueName);
            dic3.Clear();
            dic3.Add("1", "2");
            dic3.Remove("1");
            dic3["1"] = "3";
            dic3["1"] = "4";

            var dic4 = new SqlDictionary <string, SomeDto>();

            dic4.Load(connectionString, "stringdto", keyName, valueName);
            dic4.Clear();
            dic4.Add("1", new SomeDto()
            {
                Id = 1, Name = "SomeName"
            });
            dic4.Remove("1");
            dic4["1"] = new SomeDto()
            {
                Id = 2, Name = "SomeName"
            };
            dic4["1"] = new SomeDto()
            {
                Id = 3, Name = "SomeName"
            };


            var dic5 = new SqlNoMemoryDictionary <int, int>();

            dic5.Prepare(connectionString, "lazyintint", keyName, valueName);
            dic5.Clear();
            dic5.Add(1, 2);
            dic5.Remove(1);
            dic5[1] = 3;
            dic5[1] = 4;

            Console.WriteLine("OK!");
        }
예제 #5
0
    public void Process(SomeDto dto)
    {
        IActionHandler actionHanlder = this.strategyResolver.Resolve <IActionHandler>(dto.SomeProperty);

        actionHanlder.Handle(dto);
    }
예제 #6
0
 // PUT: api/Some/5
 public IHttpActionResult Put(int id, SomeDto entity, [FromIfMatch] string eTag)
 {
     //throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.Conflict, eTag));
     return(Ok(new { Entity = entity, ETag = eTag }));
 }