private void SetupBindings()
 {
     _modelBinder.ViewModel = _viewModel;
     _modelBinder.Bind(model => model.FromDate, () => dtFrom.Value = _viewModel.FromDate);
     _modelBinder.Bind(model => model.ToDate, () => dtTo.Value     = _viewModel.ToDate);
     _modelBinder.Bind(model => model.FormattedRowCount, () => lblRowsCount.Text = _viewModel.FormattedRowCount);
     dtFrom.CloseUp += (sender, args) => _viewModel.FromDate = dtFrom.Value;
     dtTo.CloseUp   += (sender, args) => _viewModel.ToDate = dtTo.Value;
 }
Example #2
0
        private void SetupBindings()
        {
            _modelBinder.ViewModel = _viewModel;
            _modelBinder.Bind(model => model.CurrentUser, () => lblCurrentUser.Text = _viewModel.CurrentUser.UserName);
            _modelBinder.Bind(model => model.AllTags, () =>
            {
                cboTags.DisplayMember = "TagText";
                cboTags.DataSource    = AllTagsWithEmptyFirstTag();
            });

            _modelBinder.Bind(model => model.Observation, () =>
            {
                pnlTags.Controls.Clear();
                var observationTags = _viewModel.Observation.Tags;
                if (observationTags == null)
                {
                    return;
                }
                foreach (var tag in observationTags)
                {
                    var tagItemView = CreateTagItemView(tag);
                    pnlTags.Controls.Add(tagItemView);
                }
                cboTags.SelectedIndex = 0;
            });

            _modelBinder.Bind(model => model.CanAddTags, () =>
            {
                if (!_viewModel.CanAddTags)
                {
                    MessageBox.Show("You cannot add more than 4 tags for an observation.", "Cannot add tag", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            });

            _modelBinder.Bind(model => model.TagAlreadyAdded, () =>
            {
                if (_viewModel.TagAlreadyAdded)
                {
                    var tag      = _viewModel.Tag;
                    cboTags.Text = "";
                    MessageBox.Show(string.Format("Tag: '{0}' has already been added.", tag));
                }
            });
            cboTags.TextChanged += (sender, args) => { _viewModel.Tag = cboTags.Text; };
        }
Example #3
0
        /// <summary>
        ///   Instantiates a runtime model.
        /// </summary>
        /// <param name="components">The root components of the model that should be instantiated.</param>
        internal static ModelBase InitializeModel(params IComponent[] components)
        {
            var model = new Model {
                Roots = components
            };

            ModelBinder.Bind(model);

            return(model);
        }
Example #4
0
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            // NOTE this feels a bit dirty, would like to maybe have a context provider or something
            var context = new HttpActorRequestContext(_fiberFactory(), requestContext);

            // NOTE this rocks, need to make sure we are thread safe
            var inputModel = (TInput)_modelBinder.Bind(typeof(TInput), context);

            var handler = new ActorHttpAsyncHandler <TInput>(context, inputModel, _channelProvider.GetChannel(inputModel));

            return(handler);
        }
Example #5
0
        private void SetupBindings()
        {
            _modelBinder.ViewModel = _viewModel;
            _modelBinder.Bind(model => model.Tag, () =>
            {
                lblTag.Text    = _viewModel.Tag.TagText;
                btnRemove.Left = this.lblTag.Width + 5;
                this.Size      = new Size(this.lblTag.Width + 20, this.Height);
            });

            btnRemove.Click += (sender, args) => _viewModel.RemoveTag();
        }
Example #6
0
        public async Task <IHttpActionResult> Put()
        {
            var bikeDTO = ModelBinder.Bind <BikeDTO>();

            if (!bikeDTO.TryValidate(out var errors))
            {
                var errorMessage = string.Join(", ", errors.Select(e => e.ErrorMessage));
                return(BadRequest(errorMessage));
            }
            var bike = Mapper.Map(bikeDTO);
            await _bikeService.UpdateBike(bike.ID, bike);

            return(Ok(bikeDTO));
        }
        public ActionResult Upload(HttpPostedFileBase upload)
        {
            if (ModelState.IsValid)
            {
                if (upload != null && upload.ContentLength > 0)
                {
                    //need to check and change if we should not use .csv
                    if (upload.FileName.EndsWith(".csv"))
                    {
                        //converting the ccsv file to datatable
                        DataTable csvTable = _csvReader.ExcelToDataTable(upload);

                        //declaring variables
                        var IndividualMember = new ViewModel();
                        var searchParameters = new List <ViewModel>();
                        for (int i = 0; i < csvTable.Rows.Count; i++)
                        {
                            //used to bind the values and if the row is corrupted
                            IndividualMember = ModelBinder.Bind(csvTable, i);

                            if ((IndividualMember != null))
                            {
                                searchParameters.Add(IndividualMember);
                            }
                        }

                        foreach (var customer in searchParameters)
                        {
                            GenerateFiles(customer);
                        }

                        return(View(csvTable));
                    }
                    else
                    {
                        // displays error if differnt format file is
                        ModelState.AddModelError("File", "This file format is not supported");
                        return(View());
                    }
                }
                else
                {
                    // displays error if upload
                    ModelState.AddModelError("File", "Please Upload Your file");
                }
            }
            return(View());
        }
Example #8
0
        public T Bind <T>()
        {
            var obj = _binder.Bind <T>(_context);

            return(obj);
        }