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))); }
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()); }
public MainPage() { this.InitializeComponent(); BasicViewModel basicViewModel = new BasicViewModel { Message = "Hello World" }; basicViewModel.UpdateMessageCommand = new UpdateMessageCommand(basicViewModel); DataContext = basicViewModel; }
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 })); }
/// <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)); }
public MainPage() { this.InitializeComponent(); BasicViewModel model = new BasicViewModel { Message = "Move pointer over!" }; model.StartCommand = new StartCommand(model); model.EndCommand = new EndCommand(model); DataContext = model; }
/// <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); }
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 })); }
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); }
public FilterListView() { InitializeComponent(); _filter = new FilterListViewModel(); DataContext = _filter; }
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); }
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)); }
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)); }
/// <summary> /// 处理页面通用数据模型,并使用模型创建一个将视图呈现给响应的ViewResult对象。 /// </summary> /// <returns>视图呈现的模型。</returns> protected ActionResult DynamicView() { var baseModel = new BasicViewModel(); return(DynamicView(baseModel)); }
public ModulesView() { InitializeComponent(); _modules = new ModulesViewModel(); DataContext = _modules; }
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))); }
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; }
public RelayCommand(BasicViewModel viewmodel, Action ex, Func<bool> canEx) { mvm = viewmodel; this.execute = ex; this.canExecute = canEx; }
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)); }
public BasicWindow() { InitializeComponent(); DataContext = new BasicViewModel(SourceBox, DestBox); }
//insert into database public void Post(BasicViewModel basicsetting) { _basicSettingService.CreateBasicSetting(basicsetting); }
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))); }
public ComplexViewModel() { BasicViewModel = new BasicViewModel(); }
public async Task <ChangingContextPage> PostDifferentModelAsync(BasicViewModel vm) { GetComponent <PageAsDifferentModel, BasicViewModel>().InputModel(vm); return(await NavigateToAsync <ChangingContextPage>(Content.QuerySelector("button[type=submit].different-model"))); }
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); }
public BasicPage() { InitializeComponent(); BindingContext = new BasicViewModel(); }
public EndCommand(BasicViewModel model) { _model = model; }
public void PropertyChangedWithoutPropertyInView() { var viewModel = new BasicViewModel(); var view = new SampleView(); Subject.Bind(viewModel, view); viewModel.BasicReference = this; }
public HomeController() { model = new BasicViewModel(); model.Page = new Page(); model.Settings = new List <Settings>(); }
public CreatePersonView() { InitializeComponent(); _createPerson = new CreatePersonViewModel(); DataContext = _createPerson; }
public ChangingContextPage PostDifferentModel(BasicViewModel vm) { GetComponent <PageAsDifferentModel>().Input(vm); return(Navigate.To <ChangingContextPage>(By.CssSelector("button[type=submit].different-model"))); }
public ThreadsView() { InitializeComponent(); _threads = new ThreadsViewModel(); DataContext = _threads; }
public BasicController() { basicViewModel = new BasicViewModel(); }
public MainPageView() { InitializeComponent(); _mainPage = new MainPageViewModel(); DataContext = _mainPage; }
public BasicView() { DataContext = new BasicViewModel(); InitializeComponent(); }
public UpdateMessageCommand(BasicViewModel model) { _model = model; }