コード例 #1
0
        public async Task <IActionResult> Basic(BasicViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await _userService.GetUserByIdAsync(await _userService.GetCurrentUserIdAsync());

            _mapper.Map(model, user);

            if (model.ProfilePicture != null)
            {
                user.ProfilePictureUrl = await UploadPhotoAsync(model.ProfilePicture, user.ProfilePictureUrl);
            }

            if (model.ProfileCoverPicture != null)
            {
                user.ProfileCoverPictureUrl = await UploadPhotoAsync(model.ProfileCoverPicture, user.ProfileCoverPictureUrl);
            }

            await _unitOfWork.CompleteAsync();

            return(RedirectToAction(nameof(Basic)));
        }
コード例 #2
0
        public void Should_Success_Instantiate()
        {
            BasicViewModel viewModel = new BasicViewModel()
            {
                Id                 = 1,
                Active             = true,
                _CreatedAgent      = "agen",
                _CreatedBy         = "someone",
                _CreatedUtc        = DateTime.Now,
                _IsDeleted         = false,
                _LastModifiedAgent = "agen",
                _LastModifiedBy    = "someone",
                _LastModifiedUtc   = DateTime.Now,
            };

            Assert.Equal(1, viewModel.Id);
            Assert.True(viewModel.Active);
            Assert.Equal("agen", viewModel._CreatedAgent);
            Assert.Equal("someone", viewModel._CreatedBy);
            Assert.True(DateTime.MinValue < viewModel._CreatedUtc);
            Assert.True(DateTime.MinValue < viewModel._LastModifiedUtc);
            Assert.Equal("agen", viewModel._LastModifiedAgent);
            Assert.Equal("someone", viewModel._LastModifiedBy);
            Assert.False(viewModel._IsDeleted);
        }
        public async void Should_GetTypePropertiesAsKeyValuePairs()
        {
            var vm = new BasicViewModel
            {
                Id            = 1,
                Title         = "VM 1",
                IsValid       = true,
                PrimaryColour = new SelectOptionViewModel <Colour>
                {
                    Id   = Colour.Red,
                    Name = "Red"
                },
                AdditionalColours = new List <SelectOptionViewModel <Colour> >
                {
                    new SelectOptionViewModel <Colour>
                    {
                        Id   = Colour.Red,
                        Name = "Red"
                    }
                }
            };

            var formData = new MultipartFormDataContent();

            formData.AddStringContent(nameof(vm.Id), vm.Id);
            formData.AddStringContent(nameof(vm.Title), vm.Title);
            formData.AddStringContent(nameof(vm.IsValid), vm.IsValid);
            formData.AddTypeProperties(vm.PrimaryColour, nameof(vm.PrimaryColour));
            formData.AddTypeCollectionProperties(vm.AdditionalColours, nameof(vm.AdditionalColours));

            var formContent = formData.ToArray();

            var idFormContent = await formContent.ElementAt(0).ReadAsStringAsync();

            idFormContent.Should().Be(vm.Id.ToString());

            var titleFormContent = await formContent.ElementAt(1).ReadAsStringAsync();

            titleFormContent.Should().Be(vm.Title.ToString());

            var isValidFormContent = await formContent.ElementAt(2).ReadAsStringAsync();

            isValidFormContent.Should().Be(vm.IsValid.ToString());

            var primaryColourIdFormContent = await formContent.ElementAt(3).ReadAsStringAsync();

            primaryColourIdFormContent.Should().Be(((int)vm.PrimaryColour.Id).ToString());

            var primaryColourNameFormContent = await formContent.ElementAt(4).ReadAsStringAsync();

            primaryColourNameFormContent.Should().Be(vm.PrimaryColour.Name.ToString());

            var additionalColours1IdFormContent = await formContent.ElementAt(5).ReadAsStringAsync();

            additionalColours1IdFormContent.Should().Be(((int)vm.AdditionalColours.First().Id).ToString());

            var additionalColours1NameFormContent = await formContent.ElementAt(6).ReadAsStringAsync();

            additionalColours1NameFormContent.Should().Be(vm.AdditionalColours.First().Name.ToString());
        }
コード例 #4
0
        public MainPage()
        {
            this.InitializeComponent();
            BasicViewModel basicViewModel = new BasicViewModel
            {
                Message = "Hello World"
            };

            basicViewModel.UpdateMessageCommand = new UpdateMessageCommand(basicViewModel);
            DataContext = basicViewModel;
        }
コード例 #5
0
 public ActionResult EditBasic(BasicViewModel Vmodel, HttpPostedFileBase[] files)
 {
     if (ModelState.IsValid)
     {
         Mapper.CreateMap <BasicViewModel, model>();
         var entity = Mapper.Map <BasicViewModel, model>(Vmodel);
         _articleService.Update(entity);
         addResources(Vmodel.id, files);
     }
     return(RedirectToAction("model", new { id = Vmodel.id }));
 }
コード例 #6
0
        /// <summary>
        /// 处理页面通用数据模型,并使用模型创建一个将视图呈现给响应的ViewResult对象。
        /// </summary>
        /// <param name="viewName"></param>
        /// <param name="masterName"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        protected ActionResult DynamicView(string viewName, string masterName, object model)
        {
            if (model == null)
            {
                var basicModel = new BasicViewModel();
                SetUpBasicViewModel(basicModel);
                model = basicModel;
            }

            return(View(viewName, masterName, model));
        }
コード例 #7
0
        public MainPage()
        {
            this.InitializeComponent();
            BasicViewModel model = new BasicViewModel
            {
                Message = "Move pointer over!"
            };

            model.StartCommand = new StartCommand(model);
            model.EndCommand   = new EndCommand(model);
            DataContext        = model;
        }
コード例 #8
0
ファイル: MainViewModel.cs プロジェクト: srodriguez511/Stocks
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(IStockProvider dataService)
        {
            _dataService = dataService;
            BVM          = new BasicViewModel(dataService);
            GVM          = new GroupViewModel(dataService);
            GHVM         = new GroupHistoryViewModel(dataService);

            var loStreamQuote = _dataService.StockQuoteStream.ObserveOnDispatcher()
                                .Scan((quoteA, quoteB) => StockQuote.MinPrice(quoteA, quoteB)).DistinctUntilChanged();
            var hiStreamQuote = _dataService.StockQuoteStream.ObserveOnDispatcher()
                                .Scan((quoteA, quoteB) => StockQuote.MaxPrice(quoteA, quoteB)).DistinctUntilChanged();

            loStreamQuote.Subscribe(quote => LoQuote = quote);
            hiStreamQuote.Subscribe(quote => HiQuote = quote);
        }
コード例 #9
0
ファイル: MainViewModel.cs プロジェクト: xyicheng/Stocks
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(IStockProvider dataService)
        {
            _dataService = dataService;
            BVM = new BasicViewModel(dataService);
            GVM = new GroupViewModel(dataService);
            GHVM = new GroupHistoryViewModel(dataService);

            var loStreamQuote = _dataService.StockQuoteStream.ObserveOnDispatcher()
                .Scan((quoteA, quoteB) => StockQuote.MinPrice(quoteA, quoteB)).DistinctUntilChanged();
            var hiStreamQuote = _dataService.StockQuoteStream.ObserveOnDispatcher()
                .Scan((quoteA, quoteB) => StockQuote.MaxPrice(quoteA, quoteB)).DistinctUntilChanged();

            loStreamQuote.Subscribe(quote => LoQuote = quote);
            hiStreamQuote.Subscribe(quote => HiQuote = quote);
        }
コード例 #10
0
        public ActionResult CreateBasic(BasicViewModel Vmodel, HttpPostedFileBase[] files)
        {
            int article_id = 0;

            if (ModelState.IsValid)
            {
                var customer = _customerService.getCustomerById(Vmodel.customer_id);
                if (customer == null)
                {
                    throw new InvalidOperationException("Cliente no encontrado");
                }
                Mapper.CreateMap <BasicViewModel, model>();
                var entity = Mapper.Map <BasicViewModel, model>(Vmodel);
                article_id = _articleService.Create(entity);
                addResources(article_id, files);
            }
            return(RedirectToAction("model", new { id = article_id }));
        }
コード例 #11
0
 public void Should_validate_complex_case()
 {
     var validator = new ConventionBasedValidator<ComplexViewModel>();
     var basicViewModel = new BasicViewModel
     {
         Required = "a",
         MinLength = "asdfa",
         MaxLength = "asdfjl",
         EmailAddress = "*****@*****.**"
     };
     var complexViewModel = new ComplexViewModel
     {
         BasicViewModel = basicViewModel,
         Required = "a",
         MinLength = "aasdf",
         MaxLength = "asfjkl",
         EmailAddress = "*****@*****.**"
     };
     validator.Validate(complexViewModel).IsValid.ShouldBeTrue();
     validator.Validate(complexViewModel).Errors.Count.ShouldEqual(0);
 }
コード例 #12
0
ファイル: FilterListView.xaml.cs プロジェクト: TRovnina/04Lab
 public FilterListView()
 {
     InitializeComponent();
     _filter     = new FilterListViewModel();
     DataContext = _filter;
 }
コード例 #13
0
 public void Should_validate_basic_case()
 {
     var validator = new ConventionBasedValidator<BasicViewModel>();
     var viewModel = new BasicViewModel
     {
         Required = "a",
         MinLength = "asdfa",
         MaxLength = "asdfkl",
         EmailAddress = "*****@*****.**"
     };
     validator.Validate(viewModel).IsValid.ShouldBeTrue();
     validator.Validate(viewModel).Errors.Count.ShouldEqual(0);
 }
コード例 #14
0
        public void InvokeWithGivenInvoker()
        {
            Action savedForLater = null;
            Action<Action> updateViewInvoker = a => { savedForLater = a; };
            Subject.UpdateView = updateViewInvoker;
            const string expected = "Some changed text";
            var viewModel = new BasicViewModel();
            var view = new BasicObject();
            Subject.Bind(viewModel, view);
            viewModel.BasicString = expected;
            Assert.That(view.BasicString, Is.EqualTo(default(string)));

            savedForLater();
            
            Assert.That(view.BasicString, Is.EqualTo(expected));
        }
コード例 #15
0
        public void UpdateSameNames()
        {
            const string expected = "Some changed text";
            var viewModel = new BasicViewModel();
            var view = new BasicObject();
            Subject.Bind(viewModel, view);

            viewModel.BasicString = expected;
            
            Assert.That(view.BasicString, Is.EqualTo(expected));
        }
コード例 #16
0
        /// <summary>
        /// 处理页面通用数据模型,并使用模型创建一个将视图呈现给响应的ViewResult对象。
        /// </summary>
        /// <returns>视图呈现的模型。</returns>
        protected ActionResult DynamicView()
        {
            var baseModel = new BasicViewModel();

            return(DynamicView(baseModel));
        }
コード例 #17
0
ファイル: ModulesView.xaml.cs プロジェクト: TRovnina/05Lab
 public ModulesView()
 {
     InitializeComponent();
     _modules    = new ModulesViewModel();
     DataContext = _modules;
 }
コード例 #18
0
        public void IgnorePropertiesWithPrivateSetter()
        {
            var viewModel = new BasicViewModel { BasicString = "foo" };
            var view = new BasicViewWithPrivateSetter();

            Subject.Bind(viewModel, view);

            Assert.That(view.BasicString, Is.EqualTo(default(string)));
        }
コード例 #19
0
 private IDictionary<string, object> GetBasicVariables()
 {
     var viewModel = new BasicViewModel
     {
         String1 = "Test1",
         Object1 = new BasicViewModel { String1 = "Test2" },
     };
     var names = new NameDictionary
     {
         { Engine.ContextKey, viewModel },
         { "$variable1", "Value1" },
     };
     return names;
 }
コード例 #20
0
ファイル: RelayCommand.cs プロジェクト: jetlee2008/ACLHandy
 public RelayCommand(BasicViewModel viewmodel, Action ex, Func<bool> canEx)
 {
     mvm = viewmodel;
     this.execute = ex;
     this.canExecute = canEx;
 }
コード例 #21
0
        public void IgnorePropertiesWithoutSetter()
        {
            const string expected = "Exp";
            var viewModel = new BasicViewModel { BasicString = "foo" };
            var view = new { BasicString = expected };

            Subject.Bind(viewModel, view);

            Assert.That(view.BasicString, Is.EqualTo(expected));
        }
コード例 #22
0
 public BasicWindow()
 {
     InitializeComponent();
     DataContext = new BasicViewModel(SourceBox, DestBox);
 }
コード例 #23
0
 //insert into database
 public void Post(BasicViewModel basicsetting)
 {
     _basicSettingService.CreateBasicSetting(basicsetting);
 }
コード例 #24
0
        public void HasPriorValue()
        {
            var expected = new SampleView();
            var viewModel = new BasicViewModel { BasicReference = expected };
            var view = new BasicObject { BasicReference = this};

            Subject.Bind(viewModel, view);

            Assert.That(view.BasicReference, Is.SameAs((expected)));
        }
コード例 #25
0
 public ComplexViewModel()
 {
     BasicViewModel = new BasicViewModel();
 }
コード例 #26
0
 public async Task <ChangingContextPage> PostDifferentModelAsync(BasicViewModel vm)
 {
     GetComponent <PageAsDifferentModel, BasicViewModel>().InputModel(vm);
     return(await NavigateToAsync <ChangingContextPage>(Content.QuerySelector("button[type=submit].different-model")));
 }
コード例 #27
0
 public void Should_invalidate_basic_case()
 {
     var validator = new ConventionBasedValidator<BasicViewModel>();
     var viewModel = new BasicViewModel
                         {
                             Required = null,
                             MinLength = "asdf",
                             MaxLength = "asdfjkl",
                             EmailAddress = "invalidEmail"
                         };
     validator.Validate(viewModel).IsValid.ShouldBeFalse();
     validator.Validate(viewModel).Errors.Count.ShouldEqual(4);
 }
コード例 #28
0
 public BasicPage()
 {
     InitializeComponent();
     BindingContext = new BasicViewModel();
 }
コード例 #29
0
 public EndCommand(BasicViewModel model)
 {
     _model = model;
 }
コード例 #30
0
 public void PropertyChangedWithoutPropertyInView()
 {
     var viewModel = new BasicViewModel();
     var view = new SampleView();
     Subject.Bind(viewModel, view);
     viewModel.BasicReference = this;
 }
コード例 #31
0
 public HomeController()
 {
     model          = new BasicViewModel();
     model.Page     = new Page();
     model.Settings = new List <Settings>();
 }
コード例 #32
0
 public CreatePersonView()
 {
     InitializeComponent();
     _createPerson = new CreatePersonViewModel();
     DataContext   = _createPerson;
 }
コード例 #33
0
 public ChangingContextPage PostDifferentModel(BasicViewModel vm)
 {
     GetComponent <PageAsDifferentModel>().Input(vm);
     return(Navigate.To <ChangingContextPage>(By.CssSelector("button[type=submit].different-model")));
 }
コード例 #34
0
 public ThreadsView()
 {
     InitializeComponent();
     _threads    = new ThreadsViewModel();
     DataContext = _threads;
 }
コード例 #35
0
 public BasicController()
 {
     basicViewModel = new BasicViewModel();
 }
コード例 #36
0
 public MainPageView()
 {
     InitializeComponent();
     _mainPage   = new MainPageViewModel();
     DataContext = _mainPage;
 }
コード例 #37
0
ファイル: BasicView.xaml.cs プロジェクト: marwahaha/Beethoven
 public BasicView()
 {
     DataContext = new BasicViewModel();
     InitializeComponent();
 }
コード例 #38
0
 public UpdateMessageCommand(BasicViewModel model)
 {
     _model = model;
 }