예제 #1
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            NameValueCollection request = controllerContext.HttpContext.Request.HttpMethod == "GET"
                ? controllerContext.HttpContext.Request.QueryString
                : controllerContext.HttpContext.Request.Form;

            FilterViewModel viewModel = new FilterViewModel();

            var start = request.Get(nameof(viewModel.Start));
            var end   = request.Get(nameof(viewModel.End));
            var guid  = request.Get(nameof(viewModel.DeviceGuid));

            if (!string.IsNullOrWhiteSpace(guid))
            {
                try
                {
                    viewModel.DeviceGuid = new Guid(guid);
                }
                catch (OverflowException ex)
                {
                    Trace.TraceError($"Overflow exception. {ex}");
                }
            }


            var dateTimeFormat = "dd-MM-yyyy hh:mm";

            try
            {
                if (!string.IsNullOrWhiteSpace(start))
                {
                    viewModel.Start = DateTime.ParseExact(start, dateTimeFormat, CultureInfo.InvariantCulture);
                }
                if (!string.IsNullOrWhiteSpace(end))
                {
                    viewModel.End = DateTime.ParseExact(end, dateTimeFormat, CultureInfo.InvariantCulture);
                }
            }
            catch (FormatException ex)
            {
                Trace.TraceError($"Incorrect date format from web. Format should be {dateTimeFormat}.");
            }
            return(viewModel);
        }
예제 #2
0
 public IndexViewModel()
 {
     Filter       = new FilterViewModel();
     Temperatures = new List <TemperatureViewModel>();
 }