public async Task <IActionResult> Edit(int id, [Bind("SampleID,Text")] SampleViewModel sampleViewModel)
        {
            if (id != sampleViewModel.SampleID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(sampleViewModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SampleViewModelExists(sampleViewModel.SampleID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(sampleViewModel));
        }
        public void Asyncのコマンドを実行してThrowsTypeOfだと受け取れないけどtrycatchでは受け取れる()
        {
            var sample = new Mock <ISample>()
            {
                CallBase = true
            };

            sample.Setup(m => m.MethodAsync())
            .ThrowsAsync(new HttpRequestException());
//                .Throws(new HttpRequestException());    //どっちでもOKぽい

            var vm = new SampleViewModel(sample.Object);

            Assert.IsTrue(vm.SampleMethodAsyncCommand.CanExecute());

            // 例外を受け取れない !!! no exception thrown !!!
//                        Assert.That(() => vm.SampleMethodAsyncCommand.Execute(), Throws.TypeOf<HttpRequestException>());

            try
            {
                vm.SampleMethodAsyncCommand.Execute();
            }
            catch (Exception ex)
            {
                Assert.AreEqual(typeof(HttpRequestException), ex.GetType()); //受け取れる!!
            }
        }
Exemple #3
0
        public async Task <IActionResult> Post(string componentName, [FromBody] SampleViewModel vm)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var newSample = Mapper.Map <Sample>(vm);

                    _repository.AddSample(componentName, creatorName, newSample);

                    if (await _repository.SaveChangesAsync())
                    {
                        return(Created($"/api/components/{componentName}/samples/{newSample.Name}",
                                       Mapper.Map <SampleViewModel>(newSample)));
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("Failed to save new Sample: {0}", ex);
                return(BadRequest("Failed to save new Sample"));
            }

            // Fall through from the validation check
            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(Json("Validation failed on new Sample"));
        }
        public void Waitでコマンドを実行するとAggregateExceptionを受け取る()
        {
            var sample = new Mock <ISample>()
            {
                CallBase = true
            };

            sample.Setup(m => m.MethodAsync())
            .Throws(new HttpRequestException());

            var vm = new SampleViewModel(sample.Object);

            Assert.IsTrue(vm.SampleMethodWaitCommand.CanExecute());
            Assert.That(() => vm.SampleMethodWaitCommand.Execute(), Throws.TypeOf <AggregateException>());

            try
            {
                vm.SampleMethodWaitCommand.Execute();
            }
            catch (AggregateException ex)
            {
                Assert.AreEqual(1, ex.InnerExceptions.Count);
                Assert.AreEqual(typeof(HttpRequestException), ex.InnerExceptions[0].GetType());
            }
        }
Exemple #5
0
        public SamplePage()
        {
            InitializeComponent();

            CreateView();
            BindingContext = new SampleViewModel();
        }
Exemple #6
0
        protected override void Init()
        {
            var boxview = new BoxView {
                BackgroundColor = Color.Aqua, AutomationId = "Victory"
            };

            var contentView = new ContentView
            {
                Content = boxview
            };

            contentView.SetBinding(IsVisibleProperty, "IsContentVisible");

            var layout = new AbsoluteLayout
            {
                Children = { contentView }
            };

            Content = layout;

            var vm = new SampleViewModel();

            BindingContext = vm;

            vm.IsContentVisible = true;
        }
Exemple #7
0
        public async Task <int> Edit(SampleViewModel viewModel)
        {
            if (viewModel == null)
            {
                return(0);
            }

            var model = (await _mongoDbContext.Sample.FindAsync(q => q.Id == viewModel.Id)).FirstOrDefault();

            if (model == null)
            {
                return(0);
            }

            model.Id         = viewModel.Id;
            model.Title      = viewModel.Title;
            model.UpdateDate = DateTime.Now;

            var updateFilter = Builders <SampleModel> .Filter.Eq(q => q.Id, model.Id);

            var updateTitle = Builders <SampleModel> .Update.Set(q => q.Title, model.Title);

            var updateDate = updateTitle.Set(q => q.UpdateDate, model.UpdateDate);

            await _mongoDbContext.Sample.UpdateOneAsync(updateFilter, updateDate);

            return(model.Id);
        }
Exemple #8
0
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            // Show graphics profiling information while debugging.
            if (System.Diagnostics.Debugger.IsAttached)
            {
                // Display the current frame rate counters.
                Application.Current.Host.Settings.EnableFrameRateCounter = true;

                // Show the areas of the app that are being redrawn in each frame.
                //Application.Current.Host.Settings.EnableRedrawRegions = true;

                // Enable non-production analysis visualization mode,
                // which shows areas of a page that are being GPU accelerated with a colored overlay.
                //Application.Current.Host.Settings.EnableCacheVisualization = true;
            }

            // Standard Silverlight initialization
            InitializeComponent();

            // Phone-specific initialization
            InitializePhoneApplication();

            DispatcherHelper.Initialize();

            ViewModel = new SampleViewModel();
        }
        public ActionResult ShowFormData(FormCollection fc)
        {
            SampleViewModel model = new SampleViewModel();

            model = new FormCollectionToModel <SampleViewModel>(fc).GetModel;
            return(View(model));
        }
        // GET: TestVal
        public ActionResult Index()
        {
            var SampleVM = new SampleViewModel();

            SampleVM.Products = new List <Product>
            {
                new Product {
                    ID = 1, Name = "IPhone"
                },
                new Product {
                    ID = 2, Name = "MacBook Pro"
                },
                new Product {
                    ID = 3, Name = "iPod"
                }
            };

            SampleVM.Hobbies = new List <Hobby>()
            {
                new Hobby()
                {
                    Name = "Reading", IsSelected = false
                },
                new Hobby()
                {
                    Name = "Sports", IsSelected = false
                },
                new Hobby()
                {
                    Name = "Movies", IsSelected = false
                }
            };
            return(View(SampleVM));
        }
Exemple #11
0
 public FocusSample() : base(60)
 {
     Sample = new SampleViewModel
     {
         Name   = "Focus",
         Fiddle = ToFiddle(new FormDefinition
         {
             Fields = new[]
             {
                 new FieldDefinition {
                     Key = "label", Type = "label", Prompt = "Focus should be on 'value2'"
                 },
                 new FieldDefinition {
                     Key = "key1", Type = "string", Prompt = "key1"
                 },
                 new FieldDefinition {
                     Key = "key2", Type = "string", Prompt = "key2"
                 }
             }
         },
                           new Dictionary <string, string>
         {
             { "key1", "value1" },
             { "key2", "value2" },
             // this sets the focus!!
             { "__focusOn", "key2" }
         })
     };
 }
Exemple #12
0
        public async void Test_SampleViewModel()
        {
            var acl = new Acl();

            WorkflowAnalysisExtension.Acl = acl;


            SampleWorkflow GetSampleWorkflow(Sample s, IDataLocker <Sample> d) => new SampleWorkflow(s, d, null);

            var vm = new SampleViewModel(null, null, null, null, null, GetSampleWorkflow);

            vm.Inject(
                null,
                r => new DataLocker <Sample>(r, null, acl, null, null, null),
                acl, null
                );

            vm.Model = new Sample();

            vm.Workflow.CurrentStage = SampleWorkflow.Reception;

            await vm.Locker.ActivateAsync();

            Assert.True(vm.EditMode);

            vm.Workflow.CurrentStage = SampleWorkflow.Production;
            Assert.False(vm.EditMode);
        }
Exemple #13
0
        protected override void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(bundle);

            global::Xamarin.Forms.Forms.Init(this, bundle);

            LoadApplication(new App());

            SetContentView(Resource.Layout.Main);

            mViewModel = new SampleViewModel();

            mViewModel.Buckets.CollectionChanged += Buckets_CollectionChanged;

            this.mBucketListView = (RadListView)FindViewById(Resource.Id.lv_Dashboard_ListView);

            clickbtn = (Button)FindViewById(Resource.Id.click);

            clickbtn.Click += Clickbtn_Click;

            //clickbtn.SetCommand("Click", mViewModel.GetSampleSelection);

            mSampleAdapter = new SampleAdapter(this, mViewModel);

            mBucketListView.SetAdapter(mSampleAdapter);
        }
    public ActionResult Index()
    {
        var model = new SampleViewModel();


        return(View(model));
    }
Exemple #15
0
        public IActionResult Post([FromBody] SampleViewModel model)
        {
            SampleModel sample = new SampleModel
            {
                name = model.name,
                note = model.note
            };

            if (sample == null)
            {
                return(BadRequest(ApiResponse <string>(message: "No data found")));
            }
            try
            {
                if (TheRepository.Insert(sample) && TheRepository.SaveAll())
                {
                    return(Created("Successfully Created", sample));
                }
            }
            catch (Exception ex)
            {
                //TODO Logging
                return(HandleError(ex));
            }

            return(BadRequest(ApiResponse <string>(message: "Something went wrong")));
        }
Exemple #16
0
 public ActionResult HtmlPost(SampleViewModel model)
 {
     if (ModelState.IsValid)
     {
         model.Message = string.Format("Post new value = {0}", model.Value);
     }
     return(View("Index", model));
 }
Exemple #17
0
 public ActionResult Index(SampleViewModel viewModel)
 {
     if (!ModelState.IsValid)
     {
         return(View(viewModel));
     }
     return(RedirectToAction("Create", "Clientes"));
 }
Exemple #18
0
 public ActionResult AjaxPost(SampleViewModel model)
 {
     if (ModelState.IsValid)
     {
         return(Content(string.Format("Post (Ajax) new value = {0}", model.Value)));
     }
     return(Content("Invalid model!"));
 }
        public ActionResult Create()
        {
            var model = new SampleViewModel();

            model.Image.Width  = 100;
            model.Image.Height = 100;
            return(View(model));
        }
        public async Task WhenSwitchToModelFirstTime_ThenLoadModelAsyncAndApplyModelCalled()
        {
            var viewModel = new SampleViewModel();
            await viewModel.SwitchToModelAsync("one");

            Assert.AreEqual(1, viewModel.LoadModelCalls);
            Assert.AreEqual(1, viewModel.ApplyCalls);
        }
        public object CreateMainView()
        {
            var viewModel = new SampleViewModel(new SampleView());

            sampleController = new SampleController(logService, eventAggregator, viewModel, () => new DialogViewModel(new DialogWindow()));
            sampleController.Initialize();
            return(viewModel.View);
        }
Exemple #22
0
 protected override async void OnAppearing()
 {
     vm = this.BindingContext as SampleViewModel;
     base.OnAppearing();
     currentIndex = vm.CurrentIndex;
     //vm.SecurityQuestionAnswers.Clear();
     //await vm.GetSecurityQuestions();
 }
        public ActionResult Index(SampleViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            return(Content("Success"));
        }
 public SamplePage(double longitude, double latitude, Appointment appointment)
 {
     InitializeComponent();
     appt           = appointment;
     location       = new Position(latitude, longitude);
     mapView        = new TKCustomMap(MapSpan.FromCenterAndRadius(location, Distance.FromKilometers(4)));
     BindingContext = new SampleViewModel(longitude, latitude, appt);
     CreateView();
 }
Exemple #25
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var viewModel = new SampleViewModel();

            Application.Run(new SampleView(viewModel));
        }
    public ActionResult Index(SampleViewModel model)
    {
        // model.Property1 is accessable here
        // as well as model.Property2

        // but if you want something not in the view model, use Request.Form
        ViewData["CustomProperty"] = Request.Form["CustomProperty"];
        return(View(model));
    }
Exemple #27
0
        private async Task FillInput(int?id)
        {
            var model = await SampleService.GetById(id.Value);

            if (model.Value != null)
            {
                Input = model.Value;
            }
        }
        public ActionResult Edit(int id, SampleViewModel model)
        {
            var context = new MainContext();
            var sample  = context.Samples.FirstOrDefault(s => s.Id == id);

            sample = Mapper.Map(model, sample);
            context.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public IActionResult Index()
        {
            var viewModel = new SampleViewModel
            {
                Table    = _sampleTable,
                Language = Language.German
            };

            return(View(viewModel));
        }
        internal void Run()
        {
            //var addBrepsToDoc = new AddBrepsToDocument();

            var viewModel = new SampleViewModel(/*addBrepsToDoc*/);

            var mainWindow = new MainWindow(viewModel);

            mainWindow.ShowDialog();
        }
        public SampleViewModel Build(SampleDomainModel domainModel)
        {
            var result = new SampleViewModel();
            result.IntValueString = domainModel.IntValue.ToString();
            result.StringValue = domainModel.StringValue;
            result.DateTimeValueString = domainModel.DateTimeValue.ToString();
            result.GuidValueString = domainModel.GuidValue.ToString();
            result.BoolValueString = domainModel.BoolValue.ToString();

            result.StaticValue = "static value";

            return result;
        }
Exemple #32
0
        public MainPage()
        {
            InitializeComponent();

            sampleVM = new SampleViewModel();
            myTreeView.ItemsSource = sampleVM;

            this.textBox.Text = "90.3.3.3";

            BusinessItem item = this.sampleVM.GetItemByName(this.textBox.Text);
            if (item != null)
            {
                item.IsSelected = true;
                string path = item.GetPath();
                myTreeView.BringPathIntoView(path);
            }
        }
Exemple #33
0
		protected override void Init ()
		{
			var boxview = new BoxView{ BackgroundColor = Color.Aqua, AutomationId = "Victory" };

			var contentView = new ContentView { 
				Content = boxview
			};

			contentView.SetBinding (IsVisibleProperty, Binding.Create<SampleViewModel> (t => t.IsContentVisible));

			var layout = new AbsoluteLayout {
				Children = { contentView }
			};

			Content = layout;

			var vm = new SampleViewModel ();

			BindingContext = vm;

			vm.IsContentVisible = true;
		}
Exemple #34
0
        /// <summary>
        /// Creates and adds a few ItemViewModel objects into the Items collection.
        /// </summary>
        public void LoadData()
        {
            XDocument samplesDoc = XDocument.Load("Samples/samples.xml");
            XName n = XName.Get("sample");

            var q = from file in samplesDoc.Descendants("sample")
                    select new SampleInfo()
                    {
                        Name = file.Element("name").Value,
                        Description = file.Element("description").Value,
                        CSharpSourceCodeFile = file.Element("csharpsourcecode").Value,
                        VbNetSourceCodeFile = file.Element("vbnetsourcecode").Value,
                        ID = file.Element("id").Value,
                    };

            foreach (SampleInfo si in q)
            {
                SampleViewModel svm = new SampleViewModel(si);
                this.Items.Add(svm);
            }

            this.IsDataLoaded = true;
        }
        public void route_input_should_substitute_method()
        {
            SingleProperty accessor = SingleProperty.Build<SampleViewModel>(x => x.InPath);
            var viewModel = new SampleViewModel
            {
                InPath = "5"
            };
            var routeInput = new RouteInput(accessor);

            routeInput.Substitute(viewModel, "test/edit/{InPath}").ShouldEqual("test/edit/5");
        }
        public void MatchViewWithSuffixAndControlProperty()
        {
            const string expected = "changed";
            var viewModel = new SampleViewModel { Puma = "initial" };
            var view = new SampleViewWithSuffix();
            Subject.Bind(viewModel, view);
            Assert.That(view.PumaLabel.Text, Is.EqualTo("initial"));

            viewModel.Puma = expected;

            Assert.That(view.PumaLabel.Text, Is.EqualTo(expected));
        }
Exemple #37
0
        /// <summary>
        /// Creates and adds a few ItemViewModel objects into the Items collection.
        /// </summary>
        public void LoadData()
        {
            XDocument samplesDoc = XDocument.Load("Samples/samples.xml");
            XName n = XName.Get("sample");

            var q = from file in samplesDoc.Descendants("sample")
                    select new SampleInfo()
                    {
                        Name = file.Element("name").Value,
                        Description = file.Element("description").Value,
                        CSharpSourceCodeFile = file.Element("csharpsourcecode").Value,
                        VbNetSourceCodeFile = file.Element("vbnetsourcecode").Value,
                        ID = file.Element("id").Value,
                    };

            foreach (SampleInfo si in q)
            {
                SampleViewModel svm = new SampleViewModel(si);
                this.Items.Add(svm);
            }

            this.IsDataLoaded = true;

            //// Sample data; replace with real data
            //this.Items.Add(new ItemViewModel() { ID = "0", Name = "runtime one", Description = "Maecenas praesent accumsan bibendum", LineThree = "Facilisi faucibus habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis senectus sociosqu" });
            //this.Items.Add(new ItemViewModel() { ID = "1", Name = "runtime two", Description = "Dictumst eleifend facilisi faucibus", LineThree = "Suscipit torquent ultrices vehicula volutpat maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus" });
            //this.Items.Add(new ItemViewModel() { ID = "2", Name = "runtime three", Description = "Habitant inceptos interdum lobortis", LineThree = "Habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis senectus sociosqu suscipit torquent" });
            //this.Items.Add(new ItemViewModel() { ID = "3", Name = "runtime four", Description = "Nascetur pharetra placerat pulvinar", LineThree = "Ultrices vehicula volutpat maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus habitant inceptos" });
            //this.Items.Add(new ItemViewModel() { ID = "4", Name = "runtime five", Description = "Maecenas praesent accumsan bibendum", LineThree = "Maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus habitant inceptos interdum lobortis nascetur" });
            //this.Items.Add(new ItemViewModel() { ID = "5", Name = "runtime six", Description = "Dictumst eleifend facilisi faucibus", LineThree = "Pharetra placerat pulvinar sagittis senectus sociosqu suscipit torquent ultrices vehicula volutpat maecenas praesent" });
            //this.Items.Add(new ItemViewModel() { ID = "6", Name = "runtime seven", Description = "Habitant inceptos interdum lobortis", LineThree = "Accumsan bibendum dictumst eleifend facilisi faucibus habitant inceptos interdum lobortis nascetur pharetra placerat" });
            //this.Items.Add(new ItemViewModel() { ID = "7", Name = "runtime eight", Description = "Nascetur pharetra placerat pulvinar", LineThree = "Pulvinar sagittis senectus sociosqu suscipit torquent ultrices vehicula volutpat maecenas praesent accumsan bibendum" });
            //this.Items.Add(new ItemViewModel() { ID = "8", Name = "runtime nine", Description = "Maecenas praesent accumsan bibendum", LineThree = "Facilisi faucibus habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis senectus sociosqu" });
            //this.Items.Add(new ItemViewModel() { ID = "9", Name = "runtime ten", Description = "Dictumst eleifend facilisi faucibus", LineThree = "Suscipit torquent ultrices vehicula volutpat maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus" });
            //this.Items.Add(new ItemViewModel() { ID = "10", Name = "runtime eleven", Description = "Habitant inceptos interdum lobortis", LineThree = "Habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis senectus sociosqu suscipit torquent" });
            //this.Items.Add(new ItemViewModel() { ID = "11", Name = "runtime twelve", Description = "Nascetur pharetra placerat pulvinar", LineThree = "Ultrices vehicula volutpat maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus habitant inceptos" });
            //this.Items.Add(new ItemViewModel() { ID = "12", Name = "runtime thirteen", Description = "Maecenas praesent accumsan bibendum", LineThree = "Maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus habitant inceptos interdum lobortis nascetur" });
            //this.Items.Add(new ItemViewModel() { ID = "13", Name = "runtime fourteen", Description = "Dictumst eleifend facilisi faucibus", LineThree = "Pharetra placerat pulvinar sagittis senectus sociosqu suscipit torquent ultrices vehicula volutpat maecenas praesent" });
            //this.Items.Add(new ItemViewModel() { ID = "14", Name = "runtime fifteen", Description = "Habitant inceptos interdum lobortis", LineThree = "Accumsan bibendum dictumst eleifend facilisi faucibus habitant inceptos interdum lobortis nascetur pharetra placerat" });
            //this.Items.Add(new ItemViewModel() { ID = "15", Name = "runtime sixteen", Description = "Nascetur pharetra placerat pulvinar", LineThree = "Pulvinar sagittis senectus sociosqu suscipit torquent ultrices vehicula volutpat maecenas praesent accumsan bibendum" });

            this.IsDataLoaded = true;
        }