/// <summary>
        /// Attempts to bind a model.
        /// </summary>
        /// <param name="bindingContext">The binding context.</param>
        /// <returns>The result of the model binding process.</returns>
        public Task BindModelAsync(ModelBindingContext bindingContext)
        {
            if (bindingContext == null)
            {
                throw new ArgumentNullException(nameof(bindingContext));
            }

            if (bindingContext.ModelType == typeof(JqGridCellUpdateRequest))
            {
                JqGridCellUpdateRequest model = new JqGridCellUpdateRequest
                {
                    Id = bindingContext.ValueProvider.GetValue("id").FirstValue
                };

                foreach (KeyValuePair <string, Type> supportedCell in SupportedCells)
                {
                    if (BindCellProperties(model, bindingContext, supportedCell.Key, supportedCell.Value))
                    {
                        break;
                    }
                }

                bindingContext.Result = ModelBindingResult.Success(model);
            }
            else
            {
                bindingContext.Result = ModelBindingResult.Failed();
            }

            return(CompatibilityHelper.CompletedTask);
        }
        private bool BindCellProperties(JqGridCellUpdateRequest model, ModelBindingContext bindingContext, string cellName, Type cellType)
        {
            bool cellBinded = false;

            ValueProviderResult valueProviderResult = bindingContext.ValueProvider.GetValue(cellName);

            if ((valueProviderResult != ValueProviderResult.None) && (valueProviderResult.Values.Count > 0))
            {
                model.CellName  = cellName;
                model.CellValue = (valueProviderResult.Values.Count == 1) ? (object)valueProviderResult.FirstValue : valueProviderResult.Values.ToArray();
            }

            return(cellBinded);
        }
        private bool BindCellProperties(JqGridCellUpdateRequest model, ModelBindingContext bindingContext, string cellName, Type cellType)
        {
            bool cellBinded = false;

            ValueProviderResult valueProviderResult = bindingContext.ValueProvider.GetValue(cellName);

            if (valueProviderResult != ValueProviderResult.None)
            {
                model.CellName  = cellName;
                model.CellValue = valueProviderResult.ConvertTo(cellType);
            }

            return(cellBinded);
        }
        public IActionResult UpdateCharacterProperty([ModelBinder(BinderType = typeof(CharacterCellUpdateRequestModelBinder))] JqGridCellUpdateRequest characterProperty)
        {
            bool status = false;

            try
            {
                int characterId;
                if ((characterProperty != null) && Int32.TryParse(characterProperty.Id, out characterId))
                {
                    Character character = StarWarsContext.Characters.FirstOrDefault(c => c.Id == characterId);
                    if (character != null)
                    {
                        switch (characterProperty.CellName)
                        {
                        case nameof(Character.Name):
                            character.Name = (string)characterProperty.CellValue;
                            break;

                        case nameof(Character.Height):
                            character.Height = (int)characterProperty.CellValue;
                            break;

                        case nameof(Character.Weight):
                            character.Weight = (int?)characterProperty.CellValue;
                            break;

                        case nameof(Character.BirthYear):
                            character.BirthYear = (string)characterProperty.CellValue;
                            break;

                        case nameof(Character.FirstAppearance):
                            character.FirstAppearance = DateTime.Parse((string)characterProperty.CellValue);
                            break;
                        }

                        status = true;
                    }
                }
            }
            catch
            { }

            return(Json(status));
        }