コード例 #1
0
        public IActionResult Buy(string id)
        {
            DataContextViewModel productModel = new DataContextViewModel("server=localhost;port=3306;database=proyectoasp_noe_bor;user=admin;password=1111");

            if (SessionHelper.GetObjectFromJson <BillViewModel>(HttpContext.Session, "cart") == null)
            {
                BillViewModel cart = new BillViewModel();
                cart.LineasFactura.Add(new BillDetailViewModel()
                {
                    Producto = productModel.GetProduct(int.Parse(id)), Cantidad = 1
                });
                SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart);
            }
            else
            {
                BillViewModel cart  = SessionHelper.GetObjectFromJson <BillViewModel>(HttpContext.Session, "cart");
                int           index = isExist(id);
                if (index != -1)
                {
                    cart.LineasFactura[index].Cantidad++;
                }
                else
                {
                    cart.LineasFactura.Add(new BillDetailViewModel()
                    {
                        Producto = productModel.GetProduct(int.Parse(id)), Cantidad = 1
                    });
                }
                SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart);
            }
            return(RedirectToAction("Index"));
        }
コード例 #2
0
        /// <summary>
        /// Conversion to cjson format compatible with a data context root Vm
        /// Can be used as an entry for neutronium-vm-loader https://github.com/NeutroniumCore/neutronium-vm-loader
        /// </summary>
        /// <param name="object">object to be serialiazed</param>
        /// <returns>cjson string value</returns>
        public string ToRootVmCjson(object @object)
        {
            var context = new DataContextViewModel(@object);
            var glue    = _Converter.Map(context);

            return(glue.AsCircularVersionedJson());
        }
コード例 #3
0
 public void HideDataContext(DataContextViewModel dataContextViewModel)
 {
     SessionData.Current.HideDataContext(dataContextViewModel);
 }
コード例 #4
0
 public void ShowDataContext(DataContextViewModel dataContextViewModel)
 {
     SessionData.Current.ShowDataContext(dataContextViewModel);
 }
コード例 #5
0
        private Task <IHtmlBinding> Navigate(Uri uri, object viewModel, JavascriptBindingMode mode = JavascriptBindingMode.TwoWay)
        {
            if (uri == null)
            {
                throw ExceptionHelper.GetArgument($"ViewModel not registered: {viewModel.GetType()}");
            }

            _Navigating = true;

            var oldvm = GetMainViewModel(Binding) as INavigable;

            if (_UseINavigable && (oldvm != null))
            {
                oldvm.Navigation = null;
            }

            if (_CurrentWebControl != null)
            {
                _CurrentWebControl.HtmlWindow.Crashed -= Crashed;
            }

            var closetask = (_CurrentWebControl != null) ? _Window.CloseAsync() : TaskHelper.Ended();

            _NextWebControl = _WebViewLifeCycleManager.Create();
            _NextWebControl.HtmlWindow.ConsoleMessage += ConsoleMessage;

            var moderWindow = _NextWebControl.HtmlWindow as IModernWebBrowserWindow;

            var injectorFactory = GetInjectorFactory(uri);
            var engine          = new HtmlViewEngine(_NextWebControl, injectorFactory, _webSessionLogger);

            var dataContext = new DataContextViewModel(viewModel);
            var initVm      = HtmlBinding.GetBindingBuilder(engine, dataContext, mode);

            if (moderWindow != null)
            {
                var debugContext = _WebViewLifeCycleManager.DebugContext;
                EventHandler <BeforeJavascriptExcecutionArgs> before = null;
                before = (o, e) =>
                {
                    moderWindow.BeforeJavascriptExecuted -= before;
                    e.JavascriptExecutor(_JavascriptFrameworkManager.GetMainScript(debugContext));
                };
                moderWindow.BeforeJavascriptExecuted += before;
            }
            var tcs = new TaskCompletionSource <IHtmlBinding>();

            EventHandler <LoadEndEventArgs> sourceupdate = null;

            sourceupdate = async(o, e) =>
            {
                _NextWebControl.HtmlWindow.LoadEnd -= sourceupdate;

                var builder = await initVm;
                await builder.CreateBinding(_WebViewLifeCycleManager.DebugContext).WaitWith(closetask, t => Switch(t, dataContext.Window, tcs)).ConfigureAwait(false);
            };

            Url = uri;
            _NextWebControl.HtmlWindow.LoadEnd += sourceupdate;
            _NextWebControl.HtmlWindow.NavigateTo(uri);

            return(tcs.Task);
        }
コード例 #6
0
 public UserController(IHostingEnvironment hostingEnvironment)
 {
     _hostingEnvironment = hostingEnvironment;
     db = new DataContextViewModel("server=localhost;port=3306;database=proyectoasp_noe_bor;user=admin;password=1111");
 }
コード例 #7
0
        private DataContextViewModel GetOrCreateDataContext(ExecutionContext context)
        {
            var result = _dataContexts.FirstOrDefault(x => x.Identifier == context.Identifier);
            if (result != null)
            {
                return result;
            }

            result = new DataContextViewModel
            {
                Description = context.Description,
                Identifier = context.Identifier
            };

            _dataContexts.Insert(0, result);

            return result;
        }
コード例 #8
0
 public void HideDataContext(DataContextViewModel dataContextViewModel)
 {
     if (dataContextViewModel != null)
     {
         var isSelected = SelectedDataContext == dataContextViewModel;
         var indexOf = VisibleDataContexts.IndexOf(dataContextViewModel);
         var count = VisibleDataContexts.Count - 1;
         dataContextViewModel.IsHidden = true;
         InvalidateDataContextsVisibility();
         if (isSelected)
         {
             SelectedDataContext = indexOf == count
                 ? VisibleDataContexts.LastOrDefault()
                 : VisibleDataContexts.Skip(indexOf).FirstOrDefault();
         }
     }
 }
コード例 #9
0
 public void ShowDataContext(DataContextViewModel dataContextViewModel)
 {
     if (dataContextViewModel != null)
     {
         dataContextViewModel.IsHidden = false;
         InvalidateDataContextsVisibility();
     }
 }