public async Task UpdateTagsTest() { Deck deck = new Deck() { DeckId = 1, Title = "test", DefaultCardTemplateId = 1 }; CardTemplate template1 = new CardTemplate() { CardTemplateId = 1, Title = "test1" }; Card card = new Card() { CardId = 1, CardTemplateId = 1, DeckId = 1 }; ApiConnectorMock mock = CreateMockForInitialize(true, true, deck, card, new List <CardTemplate>() { template1 }); CardEditViewModel viewModel = new CardEditViewModel(navigationManagerMock, mock, new EntityChangeValidator <Card>()) { Id = 1, DeckId = 1 }; bool result = await viewModel.InitializeAsync(); Assert.IsTrue(result); Assert.AreEqual(0, viewModel.Tags.Count); viewModel.Tags.Add("tag1"); Assert.AreEqual("tag1", viewModel.Entity.Tags); viewModel.Tags.Add("tag2"); Assert.AreEqual("tag1,tag2", viewModel.Entity.Tags); viewModel.Tags.RemoveAt(0); Assert.AreEqual("tag2", viewModel.Entity.Tags); }
public BankCardEditTemplate( ImageBrush imageBrush, LinearGradientBrush background, Brush textForeground, Brush textBackground, string cardCode, string cardName, string cardDescription) { InitializeComponent(); var viewmodel = new CardEditViewModel(); CardName.DataContext = viewmodel; CardDescription.DataContext = viewmodel; CardCode = cardCode; Panel.Background = imageBrush; Card.Background = background; CardName.Foreground = textForeground; CardName.BorderBrush = textBackground; CardDescription.Foreground = textForeground; CardDescription.BorderBrush = textBackground; CardName.Text = CardNameValue = cardName; CardDescription.Text = CardDescriptionValue = cardDescription; }
public async Task CommandsAreInitializedCorrectlyTest() { Deck deck = new Deck() { DeckId = 1, Title = "test", DefaultCardTemplateId = 2 }; CardTemplate template1 = new CardTemplate() { CardTemplateId = 1, Title = "test" }; ApiConnectorMock mock = CreateMockForInitialize(false, true, deck, null, new List <CardTemplate>() { template1 }); CardEditViewModel viewModel = new CardEditViewModel(navigationManagerMock, mock, new EntityChangeValidator <Card>()); await viewModel.InitializeAsync(); Assert.IsNotNull(viewModel.ShowStatisticsCommand.CommandText); Assert.IsNotNull(viewModel.ShowStatisticsCommand.ToolTip); Assert.AreEqual("/Statistics", viewModel.ShowStatisticsCommand.TargetUri); Assert.IsTrue(viewModel.ShowStatisticsCommand.IsRelative); Assert.IsNotNull(viewModel.DeleteCommand.CommandText); Assert.IsNotNull(viewModel.DeleteCommand.ToolTip); Assert.IsNotNull(viewModel.SaveChangesCommand.CommandText); Assert.IsNotNull(viewModel.SaveChangesCommand.ToolTip); }
public async Task LoadsAvailableCardTemplatesOnInitializeTest() { Deck deck = new Deck() { DeckId = 1, Title = "test", DefaultCardTemplateId = 1 }; CardFieldDefinition field = new CardFieldDefinition() { CardTemplateId = 1, FieldId = 1, FieldName = "Field 1" }; CardTemplate template = new CardTemplate() { CardTemplateId = 1, Title = "test1" }; template.FieldDefinitions.Add(field); ApiConnectorMock mock = CreateMockForInitialize(false, true, deck, null, new List <CardTemplate>() { template }); CardEditViewModel viewModel = new CardEditViewModel(navigationManagerMock, mock, new EntityChangeValidator <Card>()); bool result = await viewModel.InitializeAsync(); Assert.IsTrue(result); Assert.AreEqual(1, viewModel.AvailableCardTemplates.Count); Assert.AreEqual("test1", viewModel.AvailableCardTemplates[0]); Assert.AreEqual(1, viewModel.CardTemplateId); Assert.AreEqual("test1", viewModel.CardTemplateTitle); Assert.AreEqual(1, viewModel.Entity.Fields.Count); Assert.AreEqual(1, viewModel.FieldValueProperties.Count); }
public async Task DoesValidateFieldValuePropertiesTest() { Deck deck = new Deck() { DeckId = 1, Title = "test", DefaultCardTemplateId = 1 }; CardFieldDefinition field = new CardFieldDefinition() { CardTemplateId = 1, FieldId = 1, FieldName = "Field 1", IsRequired = true }; CardTemplate template = new CardTemplate() { CardTemplateId = 1, Title = "test1" }; template.FieldDefinitions.Add(field); EntityChangeValidator <CardField> fieldChangeValidator = new EntityChangeValidator <CardField>(); fieldChangeValidator.Register(nameof(CardField.Value), new CardFieldValueValidator()); CardChangeValidator validator = new CardChangeValidator(fieldChangeValidator); ApiConnectorMock mock = CreateMockForInitialize(false, true, deck, null, new List <CardTemplate>() { template }); CardEditViewModel viewModel = new CardEditViewModel(navigationManagerMock, mock, validator); await viewModel.InitializeAsync(); viewModel.FieldValueProperties[0].Value = null; Assert.IsFalse(string.IsNullOrEmpty(viewModel.FieldValueProperties[0].ErrorText)); viewModel.FieldValueProperties[0].Value = "test"; Assert.IsTrue(string.IsNullOrEmpty(viewModel.FieldValueProperties[0].ErrorText)); }
public async Task DoesValidateCardTemplateTitlePropertyTest() { Deck deck = new Deck() { DeckId = 1, Title = "test", DefaultCardTemplateId = 2 }; CardTemplate template1 = new CardTemplate() { CardTemplateId = 1, Title = "test" }; ApiConnectorMock mock = CreateMockForInitialize(false, true, deck, null, new List <CardTemplate>() { template1 }); CardEditViewModel viewModel = new CardEditViewModel(navigationManagerMock, mock, new EntityChangeValidator <Card>()); await viewModel.InitializeAsync(); viewModel.CardTemplateTitleProperty.Value = null; Assert.IsFalse(string.IsNullOrEmpty(viewModel.CardTemplateTitleProperty.ErrorText)); mock = CreateMockForInitialize(false, true, deck, null, new List <CardTemplate>() { template1 }); viewModel = new CardEditViewModel(navigationManagerMock, mock, new EntityChangeValidator <Card>()); await viewModel.InitializeAsync(); viewModel.CardTemplateTitleProperty.Value = "test"; Assert.IsTrue(string.IsNullOrEmpty(viewModel.CardTemplateTitleProperty.ErrorText)); }
// Ação de Novo Cartão para o Cliente de Id passado como parâmetro public ActionResult New(int clientId) { //Busca pelo cliente com Id igual ao passado como parâmetro var client = _unitOfWork.Clients.SingleOrDefault(c => c.Id == clientId); //Caso não encontre o cliente retorna Not Found if (client == null) { return(HttpNotFound()); } //Pega todos os CardBrands(Bandeiras de Cartão) var cardbrand = _unitOfWork.CardBrands.GetAll(); //Pega todos os CardTypes(Tipos de Cartão) var cardtype = _unitOfWork.CardTypes.GetAll(); //Cria nova instância vazia de CardEditViewModel com um cartão vazio, vinculado ao cliente encontrado // e com as listas de CardBrands e CardTypes var viewModel = new CardEditViewModel { ClientName = client.Name, CardBrands = cardbrand, CardTypes = cardtype, Card = new Card { ClientId = client.Id } }; //Retorna a CardEditViewModel para a view CardForm(novo cartão ou edição de cartão) return(View("CardForm", viewModel)); }
public async Task CreateNewCardOnInitializeTest() { Deck deck = new Deck() { DeckId = 1, Title = "test", DefaultCardTemplateId = 2 }; CardTemplate template1 = new CardTemplate() { CardTemplateId = 1, Title = "test1" }; CardTemplate template2 = new CardTemplate() { CardTemplateId = 2, Title = "test2" }; ApiConnectorMock mock = CreateMockForInitialize(false, true, deck, null, new List <CardTemplate>() { template1, template2 }); CardEditViewModel viewModel = new CardEditViewModel(navigationManagerMock, mock, new EntityChangeValidator <Card>()); bool result = await viewModel.InitializeAsync(); Assert.IsTrue(result); Assert.IsNotNull(viewModel.Entity); //Load default template Assert.AreEqual(2, viewModel.CardTemplateId); Assert.AreEqual(2, viewModel.Entity.CardTemplateId); Assert.AreEqual("test2", viewModel.CardTemplateTitle); }
public async Task InitializeFailsForWrongDeckIdTest() { Deck deck = new Deck() { DeckId = 1, Title = "test", DefaultCardTemplateId = 2 }; CardTemplate template1 = new CardTemplate() { CardTemplateId = 1, Title = "test" }; ApiConnectorMock mock = CreateMockForInitialize(true, true, deck, new Card() { DeckId = 1 }, new List <CardTemplate>() { template1 }); CardEditViewModel viewModel = new CardEditViewModel(navigationManagerMock, mock, new EntityChangeValidator <Card>()) { Id = 1, DeckId = 2 }; bool result = await viewModel.InitializeAsync(); Assert.IsFalse(result); Assert.AreEqual(NotificationKind.ErrorNotification, notificationProviderMock.NotificationKind); Assert.IsFalse(string.IsNullOrEmpty(notificationProviderMock.Message)); }
public async Task CommandsEnabledTest() { CardTemplate template = new CardTemplate() { CardTemplateId = 1, Title = "test" }; Deck deck = new Deck() { DeckId = 1, Title = "test", DefaultCardTemplateId = 1 }; //New Entity ApiConnectorMock mock = CreateMockForInitialize(false, true, deck, null, new List <CardTemplate>() { template }); CardEditViewModel viewModel = new CardEditViewModel(navigationManagerMock, mock, new EntityChangeValidator <Card>()); await viewModel.InitializeAsync(); Assert.IsFalse(viewModel.ShowStatisticsCommand.IsEnabled); Assert.IsFalse(viewModel.DeleteCommand.IsEnabled); Assert.IsTrue(viewModel.SaveChangesCommand.IsEnabled); Assert.IsTrue(viewModel.CloseCommand.IsEnabled); //Existing entity Card card = new Card() { DeckId = 1, CardId = 1, Deck = deck }; mock = CreateMockForInitialize(true, true, deck, card, new List <CardTemplate>() { template }); viewModel = new CardEditViewModel(navigationManagerMock, mock, new EntityChangeValidator <Card>()) { Id = 1, DeckId = 1 }; await viewModel.InitializeAsync(); Assert.IsTrue(viewModel.ShowStatisticsCommand.IsEnabled); Assert.IsTrue(viewModel.DeleteCommand.IsEnabled); Assert.IsTrue(viewModel.SaveChangesCommand.IsEnabled); Assert.IsTrue(viewModel.CloseCommand.IsEnabled); }
public async Task LoadsAvailableCardTemplatesOnInitializeErrorTest() { Deck deck = new Deck() { DeckId = 1, Title = "test", DefaultCardTemplateId = 2 }; CardTemplate template1 = new CardTemplate() { CardTemplateId = 1, Title = "test" }; ApiConnectorMock mock = CreateMockForInitialize(false, false, deck, null, new List <CardTemplate>() { template1 }); CardEditViewModel viewModel = new CardEditViewModel(navigationManagerMock, mock, new EntityChangeValidator <Card>()); bool result = await viewModel.InitializeAsync(); Assert.IsFalse(result); Assert.AreEqual(0, viewModel.AvailableCardTemplates.Count); Assert.AreEqual(NotificationKind.ErrorNotification, notificationProviderMock.NotificationKind); Assert.AreEqual("test-error", notificationProviderMock.Message); }
public async Task ChangeCardTemplateUpdatesFieldsTest() { Deck deck = new Deck() { DeckId = 1, Title = "test", DefaultCardTemplateId = 1 }; CardTemplate template1 = new CardTemplate() { CardTemplateId = 1, Title = "test1" }; CardTemplate template2 = new CardTemplate() { CardTemplateId = 2, Title = "test2" }; template2.FieldDefinitions.Add(new CardFieldDefinition() { FieldId = 1, FieldName = "test" }); Card card = new Card() { CardId = 1, CardTemplateId = 1, DeckId = 1 }; ApiConnectorMock mock = CreateMockForInitialize(true, true, deck, card, new List <CardTemplate>() { template1, template2 }); CardEditViewModel viewModel = new CardEditViewModel(navigationManagerMock, mock, new EntityChangeValidator <Card>()) { Id = 1, DeckId = 1 }; bool result = await viewModel.InitializeAsync(); Assert.IsTrue(result); viewModel.CardTemplateId = template2.CardTemplateId; Assert.AreEqual(1, viewModel.Entity.Fields.Count); Assert.AreEqual(1, viewModel.FieldValueProperties.Count); }
public CardEditingController(CardEditViewModel vm) { m_viewModel = vm; m_viewModel.RegisterForNecessaryFieldsCheck(CheckNecessaryFields); m_viewModel.RegisterConfirmAction(SaveCardChanges); }
public ActionResult EditCardInfo(CardEditViewModel model) { try { var t = db.Cards.FirstOrDefault(s => s.ID == model.CardID); if (t == null) { return(Json(Comm.ToJsonResult("Error", "名片不存在"), JsonRequestBehavior.AllowGet)); } if (model.Name != null) { t.Name = model.Name; } if (model.Email != null) { if (string.Empty != model.Email.Trim() && !Reg.IsEmail(model.Email)) { return(Json(Comm.ToJsonResult("Error", "邮箱格式不正确"), JsonRequestBehavior.AllowGet)); } else { t.Email = model.Email; } } if (model.Mobile != null) { if (string.Empty != model.Mobile.Trim() && !Reg.IsMobile(model.Mobile)) { return(Json(Comm.ToJsonResult("Error", "手机号格式不正确"), JsonRequestBehavior.AllowGet)); } else { t.Mobile = model.Mobile; } } if (model.PhoneNumber != null) { if (string.Empty != model.PhoneNumber.Trim() && !Reg.IsPhone(model.PhoneNumber)) { return(Json(Comm.ToJsonResult("Error", "座机号码格式不正确"), JsonRequestBehavior.AllowGet)); } else { t.PhoneNumber = model.PhoneNumber; } } if (model.Position != null) { t.Position = model.Position; } if (model.Remark != null) { t.Remark = model.Remark; } if (model.WeChatCode != null) { t.WeChatCode = model.WeChatCode; } if (model.Avatar != null) { t.Avatar = model.Avatar; } if (model.Images != null) { t.Images = model.Images; } if (model.Video != null) { t.Video = model.Video; } if (model.Voice != null) { t.Voice = model.Voice; } if (model.Info != null) { t.Info = model.Info; } db.SaveChanges(); return(Json(Comm.ToJsonResult("Success", "成功"), JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(Comm.ToJsonResult("Error500", ex.Message), JsonRequestBehavior.AllowGet)); } }
public CardEditView(CardEditViewModel viewModel) : this() { setViewModel(viewModel); }
public void setViewModel(CardEditViewModel viewModel) { ViewModel = viewModel; DataContext = ViewModel; }
public CardEditWindow(CardEditViewModel vm) { InitializeComponent(); this.cardEditView.setViewModel(vm); }
public void Init() { sqlConnection = new SqlConnection(); var connectionString = @"data source=(LocalDb)\MSSQLLocalDB;initial catalog=Lascarizador.LascarizadorDbContext;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"; sqlBuilder = new SqlConnectionStringBuilder(connectionString); sqlConnection.ConnectionString = sqlBuilder.ConnectionString; _context = new LascarizadorDbContext(sqlConnection); _unitOfWork = new UnitOfWork(_context); clientsController = new ClientsController(); cardsController = new CardsController(); //Cria Cliente clientCPF = "00424704714"; client = new Client { CPF = clientCPF, CreditLimit = Convert.ToDecimal(100.00), Email = "*****@*****.**", Name = "Pedrita Flinstone", Saldo = 0 }; var clientEVM = new ClientEditViewModel { Client = client, CreditLimit = "100,00" }; var clientResult = clientsController.Save(clientEVM); var cardBrandId = Convert.ToByte(1); //bedrock_visa; cardBrandApiName = "bedrock_visa"; var cardType = Convert.ToByte(2); //tarja_magnetica cardPassword = "******"; //Encripta a senha e adiciona o Hash e o Salt ao dados do cartão var securedPassword = new SecuredPassword(cardPassword); var cardEVM = new CardEditViewModel { Card = new Card { CardBrandId = cardBrandId, CardHolderName = "PEDRITA FLINTSTONE", CardTypeId = cardType, Client = client, Cvv = 999, ExpirationDate = DateTime.Parse("2019/01/01"), HashPassword = securedPassword.Hash, HasPassword = true, IsBlocked = false, Number = "5555666677778888", Password = cardPassword, SaltPassword = securedPassword.Hash }, CardBrands = null, CardTypes = null, ClientName = null, ExpirationMonth = 01, ExpirationYear = 2019 }; var cardResult = cardsController.Save(cardEVM); }
// Ação de salvar dados de cartão (novo ou edição) public ActionResult Save(CardEditViewModel cardEditViewModel) { //Busca pelo cardtype(tipo de cartão) do cartão recebido como parâmetro var _cardType = _unitOfWork.CardTypes.Get(cardEditViewModel.Card.CardTypeId); //Se o tipo do cartão não disponibiliza senha... if (!_cardType.PasswordAvailable) { //... e o cartão está com a opção HasPassword(tem senha) marcada como true if (cardEditViewModel.Card.HasPassword || String.IsNullOrEmpty(cardEditViewModel.Card.Password)) { //Gera um erro no ModelState ModelState.AddModelError("", "Esse tipo de cartão não permite Senha."); } } else //Se o tipo do cartão disponibiliza senha... { //... e se o cartão está com opção HasPassword(tem senha) marcada como true... if (cardEditViewModel.Card.HasPassword) { //... e uma senha não foi informada ou uma senha vazia foi passada if (String.IsNullOrEmpty(cardEditViewModel.Card.Password)) { //Gera um erro no ModelState ModelState.AddModelError("", "A senha é exigida para esse tipo de cartão e não foi informada."); } } } //Se o cartão está com opção HasPassword(tem senha) marcada como false... if (!cardEditViewModel.Card.HasPassword) { //... e foi informada uma senha não vazia if (!(cardEditViewModel.Card.Password == null)) { //Gera um erro no ModelState ModelState.AddModelError("", "A senha não é exigida para esse tipo de cartão mas uma senha foi informada."); } } //Se ModelState não for válido if (!ModelState.IsValid) { //Pega todos os CardBrands(bandeiras de cartão) var cardBrand = _unitOfWork.CardBrands.GetAll(); //Pega todos os Cardtypes(tipos de cartão) var cardType = _unitOfWork.CardTypes.GetAll(); var client = _unitOfWork.Clients.Get(cardEditViewModel.Card.ClientId); //Caso exista algum problema, cria uma nova instância da CardEditViewModel com os CardBrands e os CardTypes // para retornar os dados para a view CardForm var editViewModel = new CardEditViewModel { Card = cardEditViewModel.Card, CardBrands = cardBrand, CardTypes = cardType, ClientName = client.Name, ExpirationMonth = cardEditViewModel.ExpirationMonth, ExpirationYear = cardEditViewModel.ExpirationYear }; //Retorna a CardEditViewModel para a view CardForm (novo cartão ou edição de cartão) return(View("CardForm", editViewModel)); } //Se o cartão for um cartão novo... if (cardEditViewModel.Card.Id == 0) { //Encripta a senha e adiciona o Hash e o Salt ao dados do cartão var securedPassword = new SecuredPassword(cardEditViewModel.Card.Password); cardEditViewModel.Card.HashPassword = securedPassword.Hash; cardEditViewModel.Card.SaltPassword = securedPassword.Salt; //Acerta ExpirationDate cardEditViewModel.Card.ExpirationDate = Convert.ToDateTime("01/" + Convert.ToString(cardEditViewModel.ExpirationMonth) + "/" + Convert.ToString(cardEditViewModel.ExpirationYear)); //Adiciona o cartão a base de dados _unitOfWork.Cards.Add(cardEditViewModel.Card); } //Se o cartão já existir e estiver sendo editado else { //Sobrepoe os dados novos aos antigos var cardInDb = _unitOfWork.Cards.Get(cardEditViewModel.Card.Id); cardInDb.CardBrandId = cardEditViewModel.Card.CardBrandId; cardInDb.CardHolderName = cardEditViewModel.Card.CardHolderName; cardInDb.CardTypeId = cardEditViewModel.Card.CardTypeId; cardInDb.Cvv = cardEditViewModel.Card.Cvv; cardInDb.ExpirationDate = Convert.ToDateTime("01/" + Convert.ToString(cardEditViewModel.ExpirationMonth) + "/" + Convert.ToString(cardEditViewModel.ExpirationYear)); // cardInDb.ExpirationDate = cardEditViewModel.Card.ExpirationDate; cardInDb.HasPassword = cardEditViewModel.Card.HasPassword; cardInDb.IsBlocked = cardEditViewModel.Card.IsBlocked; cardInDb.Number = cardEditViewModel.Card.Number; var securedPassword = new SecuredPassword(cardEditViewModel.Card.Password); cardInDb.Password = cardEditViewModel.Card.Password; cardInDb.HashPassword = securedPassword.Hash; cardInDb.SaltPassword = securedPassword.Salt; } _unitOfWork.Complete(); //Redireciona para a view Index(listagem de cartões) passando o Id do Cliente return(RedirectToAction("Index", new { clientId = cardEditViewModel.Card.ClientId })); }