public void TestLoadFromDatabase() { var alvm = new AddressListViewModel(); var address = new Address { FirstName = "Bob", LastName = "Newbie", Email = "*****@*****.**" }; using (var db = new MailerEntities()) { db.Addresses.Add(address); db.SaveChanges(); } alvm.LoadFromDatabase(); // Check that it was loaded. // Don't check that this is equal to 1, because there might be more // from the other tests Assert.IsTrue(alvm.AddressListItemViewModels.Count > 0); foreach (var addressListItemViewModel in alvm.AddressListItemViewModels) { addressListItemViewModel.Delete(); } }
public void TestExternalDeletion() { var alvm = new AddressListViewModel(); var address = new Address { FirstName = "Bob", LastName = "Newbie", Email = "*****@*****.**" }; using (var db = new MailerEntities()) { db.Addresses.Add(address); db.SaveChanges(); } var alivm1 = new AddressListItemViewModel(address); alvm.AddAddressListItemViewModel(alivm1); Assert.AreEqual(1, alvm.AddressListItemViewModels.Count); alivm1.Delete(); Assert.AreEqual(0, alvm.AddressListItemViewModels.Count); using (var db = new MailerEntities()) { // ensure that it was removed Assert.IsFalse(db.Addresses.Any(addr => addr.AddressID == address.AddressID)); } }
public void TestFilter() { var alvm = new AddressListViewModel(); var alivm1 = new AddressListItemViewModel(new Address { FirstName = "Bob", LastName = "Newbie", Email = "*****@*****.**" }); var alivm2 = new AddressListItemViewModel(new Address { FirstName = "Steve", LastName = "steverson", Email = "*****@*****.**" }); alvm.AddAddressListItemViewModel(alivm1); alvm.AddAddressListItemViewModel(alivm2); alvm.Filter = "newb"; Assert.AreSame(alivm1, alvm.AddressListItemViewModels.Single()); alvm.Filter = ""; Assert.AreEqual(2, alvm.AddressListItemViewModels.Count); alvm.Filter = "ERSON"; Assert.AreSame(alivm2, alvm.AddressListItemViewModels.Single()); alvm.Filter = "foo bar"; Assert.IsFalse(alvm.AddressListItemViewModels.Any()); }
public void TestSort() { var alvm = new AddressListViewModel(); var alivm1 = new AddressListItemViewModel(new Address { FirstName = "Bob", // lowercase to make sure case is ignored - steverson would go before newbie if it wasn't LastName = "newbie", Email = "*****@*****.**" }); var alivm2 = new AddressListItemViewModel(new Address { FirstName = "Steve", // lowercase to make sure case is ignored - steverson would go after newbie if it wasn't LastName = "Steverson", Email = "*****@*****.**" }); // Insert them in backwards sorted order (S before N) alvm.AddAddressListItemViewModel(alivm2); alvm.AddAddressListItemViewModel(alivm1); // Check that they were automatically sorted - Newbie comes before Steverson Assert.AreEqual(alivm1, alvm.AddressListItemViewModels[0]); Assert.AreEqual(alivm2, alvm.AddressListItemViewModels[1]); }
public IActionResult Delete(AddressListViewModel vm) { Address address = _addressService.GetSingle(a => a.AddressId == vm.AddressId); _addressService.Delete(address); return(RedirectToAction("Index", "Home")); }
public IActionResult List() { IEnumerable <Address> addList = _addressService.GetAll(); AddressListViewModel vm = new AddressListViewModel { Total = addList.Count(), Addresses = addList }; return(View(vm)); }
public IActionResult AddressContent() { ViewBag.ProvinceList = addressService.GetProvinc(); //var userid = User.FindFirst("userid").Value; AddressListViewModel model = new AddressListViewModel { //AddressList = addressService.GetUserAddresses(int.Parse(userid)) AddressList = addressService.GetUserAddresses(27) }; return(View(model)); }
// GET: /<controller>/ public IActionResult Index() { var model = new AddressListViewModel(); var addresses = _addressRepository.AllAddresses(User).ToList(); foreach (var address in addresses) { model.Addresses.Add(_mapper.Map <AddressViewModel>(address)); } return(View()); }
public ActionResult List() { var addressList = blObject.GetAddressList(); var model = new AddressListViewModel(); model.AddressList = addressList.Select(a => new AddressViewModel { Country = a.Country.Name, City = a.City, Street = a.Street, CanDelete = ...check user access here..., CanEdit = ...check user access here... });
public IActionResult AddressManagementPerKlant(string klantId, int envelopeId, bool fromPrint = false) { var model = new AddressListViewModel(); model.FromPrint = fromPrint; model.EnvelopeId = envelopeId; model.Addresses = new List <AddressViewModel>(); model.Addresses = _mapper.Map <List <AddressViewModel> >(_addressRepository.GetAddressesByKlantId(klantId).ToList()); foreach (var address in model.Addresses) { address.Land = _mapper.Map <CountryViewModel>(_countryRepository.GetById(address.LandId)); } return(View("AddressManagement", model)); }
private void MainWindow_Loaded(object sender, RoutedEventArgs e) { var mlvm = new MailingListViewModel(); mlvm.LoadFromDatabase(); MailingListDockPanel.DataContext = mlvm; var alvm = new AddressListViewModel(); alvm.LoadFromDatabase(); AddressDockPanel.DataContext = alvm; ComposePanel.DataContext = new MessageViewModel(); }
public ActionResult GetAddress(long?OrderId) { Customer customer = Session[Constants.SESSION_USER] as Customer; List <Address> addressList = _addressService.GetAddresses(customer.Id); AddressListViewModel addressListViewModel = new AddressListViewModel(); addressListViewModel.ProvinceList = _provinceRepository.GetProvince(); addressListViewModel.CityList = _cityRepository.GetCity(); addressListViewModel.AreaList = _areaRepository.GetArea(); addressListViewModel.AddressList = addressList; if (OrderId != null) { addressListViewModel.OrderId = (long)OrderId; } return(View("AddressList", addressListViewModel)); }
public void TestRemoval() { var alvm = new AddressListViewModel(); var address = new Address { FirstName = "Bob", LastName = "Newbie", Email = "*****@*****.**" }; var alivm1 = new AddressListItemViewModel(address); alvm.AddAddressListItemViewModel(alivm1); Assert.AreEqual(1, alvm.AddressListItemViewModels.Count); alvm.RemoveAddressListItemViewModel(alivm1); Assert.AreEqual(0, alvm.AddressListItemViewModels.Count); }
public IActionResult CreateAddress(AddressListViewModel model) { if (ModelState.IsValid) { UserAddress address = new UserAddress { CityId = model.Address.CityId, ProvincId = model.Address.ProvincId, FullName = model.Address.FullName, PostCode = model.Address.PostCode, PostalAddress = model.Address.PostalAddress, Phone = model.Address.Phone, UserId = 27 }; if (addressService.AddAddress(address)) { return(Json(true)); } } return(Json(false)); }
public IActionResult AddressManagement(string id) { var model = new AddressListViewModel(); model.Addresses = new List <AddressViewModel>(); if (string.IsNullOrEmpty(id)) { model.Addresses = _mapper.Map <List <AddressViewModel> >(_addressRepository.AllAddresses(User).ToList()); } else { model.Addresses = _mapper.Map <List <AddressViewModel> >(_addressRepository.AllAddresses(User).Where(x => x.KlantId == id).ToList()); model.KlantId = id; } if (!User.IsInRole("Klant")) { foreach (var address in model.Addresses) { address.Klant = _userManager.Users.FirstOrDefault(x => x.Id == address.KlantId); } } foreach (var address in model.Addresses) { address.Land = _mapper.Map <CountryViewModel>(_countryRepository.GetById(address.LandId)); } ViewBag.Klanten = _userManager.Users.Where(x => x.OndernemerId == User.FindFirstValue(ClaimTypes.NameIdentifier)).OrderBy(x => x.Naam).ToList() .Select(c => new SelectListItem() { Text = c.Naam, Value = c.Id.ToString() }) .ToList(); return(View(model)); }
public IActionResult EditAddress(AddressListViewModel model) { if (ModelState.IsValid) { //var userid = User.FindFirst("userid").Value; var address = addressService.GetUserAddressForEdit(27, model.Address.UserAddressId); address.CityId = model.Address.CityId; address.ProvincId = model.Address.ProvincId; address.FullName = model.Address.FullName; address.PostCode = model.Address.PostCode; address.PostalAddress = model.Address.PostalAddress; address.Phone = model.Address.Phone; address.UserId = 27; if (addressService.EditUserAddress(address)) { return(Json(true)); } } return(Json(false)); }