<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Signum.Entities.Reflection;
using Signum.Entities;
using Signum.Utilities;
using System.Text.RegularExpressions;
using Signum.Engine;
using Signum.Web.Properties;

namespace Signum.Web.Controllers
{
    public class LiteModelBinder : DefaultModelBinder
    {
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) 
        {
             Type cleanType = Reflector.ExtractLite(bindingContext.ModelType);
             if (cleanType != null)
             {
                 string value = controllerContext.HttpContext.Request[bindingContext.ModelName];
                 if (value == null)
                 {
                     if (controllerContext.RouteData.Values[bindingContext.ModelName] is Lite)
                         return controllerContext.RouteData.Values[bindingContext.ModelName];
                     else
                         value = (string)controllerContext.RouteData.Values[bindingContext.ModelName];
                 }
                 int id;
                 if (int.TryParse(value, out id))
                     return Lite.Create(cleanType, id);

                 return TypeLogic.ParseLite(cleanType, value);
             }
             return base.BindModel(controllerContext, bindingContext);
        }
    }

    public class DateModelBinder : DefaultModelBinder
    {
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            string value = controllerContext.HttpContext.Request[bindingContext.ModelName];
            Match m = Regex.Match(value, @"^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$");

            if (m == null) return base.BindModel(controllerContext, bindingContext);

            return new DateTime(
                int.Parse(m.Groups["year"].Value),
                int.Parse(m.Groups["month"].Value),
                int.Parse(m.Groups["day"].Value),
                0,0,0,                    <commit_msg>(TFS CS 7024)<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Signum.Entities.Reflection;
using Signum.Entities;
using Signum.Utilities;
using System.Text.RegularExpressions;
using Signum.Engine;
using Signum.Web.Properties;

namespace Signum.Web.Controllers
{
    public class LiteModelBinder : DefaultModelBinder
    {
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) 
        {
             Type cleanType = Reflector.ExtractLite(bindingContext.ModelType);
             if (cleanType != null)
             {
                 string value = controllerContext.HttpContext.Request[bindingContext.ModelName];
                 if (value == null)
                 {
                     object routeValue = controllerContext.RouteData.Values[bindingContext.ModelName];
                     if (routeValue is Lite)
                         return routeValue;
                     else if(routeValue is int)
                         return Lite.Create(cleanType, (int)routeValue);
                     else
                         value = (string)routeValue;
                 }
                 int id;
                 if (int.TryParse(value, out id))
                     return Lite.Create(cleanType, id);

                 return TypeLogic.ParseLite(cleanType, value);
             }
             return base.BindModel(controllerContext, bindingContext);
        }
    }

    public class DateModelBinder : DefaultModelBinder
    {
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            string value = controllerContext.HttpContext.Request[bindingContext.ModelName];
            Match m = Regex.Match(value, @"^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$");

            if (m == null) return base.BindModel(controllerContext, bindingContext);

            return new DateTime(
                int.Parse(m.Groups["year"].Value),
                int.Parse(m.Groups["month"].Value),
                int.Parse(m.Groups["day"].Value),
                0,0,0,                    
{'fraction_non_alphanumeric': 0.09450092421441775, 'fraction_numerical': 0.0036968576709796672, 'mean_word_length': 2.052891396332863, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6806175', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1063, 'n_words': 216}