public async Task <IActionResult> Edit(int id, Person person, IFormFile?file) { if (id != person.PersonId) { return(NotFound()); } if (ModelState.IsValid) { if (file != null) { var fileName = UploadPicture(file); DeletePicture(person.Picture); person.Picture = fileName; } _context.Persons.Update(person); await _context.SaveChangesAsync(); return(RedirectToAction("PeopleInFamilyTree", "FamilyTrees", new { id = person.FamilyTreeId })); } var vm = new PersonsViewModel { Person = person, GenderSelectList = new SelectList(_context.Genders, "GenderId", "Name", person.GenderId) }; return(View(vm)); }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { this.InitializeComponent(); this.Suspending += this.OnSuspending; personsViewModel = new PersonsViewModel(); chargesViewModel = new ChargesViewModel(); }
public async Task <IActionResult> Create(int id, Person person, IFormFile?file) { if (ModelState.IsValid) { person.FamilyTreeId = id; if (file != null) { var fileName = UploadPicture(file); person.Picture = fileName; } else if (person.GenderId == 1) { person.Picture = "female-user-avatar.png"; } else if (person.GenderId == 2) { person.Picture = "male-user-avatar.png"; } _context.Add(person); await _context.SaveChangesAsync(); return(RedirectToAction("PeopleInFamilyTree", "FamilyTrees", new { id })); } var vm = new PersonsViewModel { GenderSelectList = new SelectList(_context.Genders, "GenderId", "Name", person.GenderId) }; return(View(vm)); }
public ActionResult Edit(PersonsViewModel person) { if (ModelState.IsValid) { var Myperson = db.Persons.Find(person.PersonId); Myperson.Name = person.Name; Myperson.Experience = person.Experience; Myperson.Contactno = person.Contactno; Myperson.Email = person.Email; foreach (var item in db.PersonToSkills) { if (item.PersonId == person.PersonId) { db.Entry(item).State = EntityState.Deleted; } } foreach (var item in person.Skills) { if (item.Checked) { db.PersonToSkills.Add(new PersonToSkill() { PersonId = person.PersonId, SkillId = item.Id }); } } db.SaveChanges(); return(RedirectToAction("Index")); } return(View(person)); }
//List<Person> myPersonList = new List<Person>(); public PersonList() { BindingContext = new PersonsViewModel(); ViewModel = new PersonsViewModel(); InitializeComponent(); //GetList(); //PersonListView.ItemsSource = myPersonList; }
public MainWindow() { PersonsViewModel persons = new PersonsViewModel(); DataContext = persons; InitializeComponent(); }
public ActionResult Index() { var model = new PersonsViewModel { FilterText = "" }; return(View(model)); }
public IActionResult People() { // Wk3 sort requirement personRepository.Persons.Sort((pers1, pers2) => pers1.Name.CompareTo(pers2.Name)); PersonsViewModel personsViewModel = new PersonsViewModel(); personsViewModel.Persons = personRepository.Persons; return(View("People", personsViewModel)); }
public ActionResult Index(PersonsViewModel viewModel) { if (!ModelState.IsValid) { // we have errors, return the view with messages return(View(viewModel)); } return(Content("success")); }
public AddCharges() { this.InitializeComponent(); chargesViewModel = (Application.Current as App).chargesViewModel; personsViewModel = (Application.Current as App).personsViewModel; this.DataContext = chargesViewModel; selectedPersons.DataContext = personsViewModel; }
public AddPeople() { this.InitializeComponent(); this.navigationHelper = new NavigationHelper(this); this.navigationHelper.LoadState += this.NavigationHelper_LoadState; this.navigationHelper.SaveState += this.NavigationHelper_SaveState; personsViewModel = ((App)Application.Current).personsViewModel; this.DataContext = personsViewModel; }
// GET: Persons public async Task <IActionResult> Index() { var vm = new PersonsViewModel { Persons = await _context.Persons .Include(p => p.Gender) .Include(p => p.FamilyTree) .ToListAsync() }; return(View(vm)); }
public MainWindow() { InitializeComponent(); persons = new PersonsViewModel(); RefreshMenu(); RefreshListBox(); persons.SelectedItemChanged += Persons_SelectedItemChanged; ((INotifyCollectionChanged)persons.Items).CollectionChanged += PersonsItems_CollectionChanged; persons.AddCommand.CanExecuteChanged += AddCommand_CanExecuteChanged; persons.RemoveCommand.CanExecuteChanged += RemoveCommand_CanExecuteChanged; }
// GET: Secretary/Edit/5 public ActionResult Edit(int id) { var user = _db.GetUserById(id); var model = new PersonsViewModel() { Email = user.Email, FirstName = user.UserDetails.FirstName, LastName = user.UserDetails.LastName, Roles = user.Roles == "Director" ? Roles.Director : user.Roles == "User" ? Roles.User : Roles.Secretary, Id = user.UserDetailsId }; return(View(model)); }
// GET: Persons/Create public IActionResult Create(int?id) { if (id == null) { return(NotFound()); } var vm = new PersonsViewModel { FamilyTreeId = id, GenderSelectList = new SelectList(_context.Genders, "GenderId", "Name"), }; return(View(vm)); }
/// <summary> /// Example of X.IPagedList /// </summary> /// <param name="page"></param> /// <param name="searchstring"></param> /// <returns></returns> public async Task <IActionResult> PagedList(int?page, string searchstring) { IPagedList <Person> personsList = _context.Persons.Where(p => searchstring == null || p.Name.Contains(searchstring)).AsNoTracking().ToPagedList(page ?? 1, 5); var model = new PersonsViewModel { PersonsList = personsList, Page = page ?? 1, SearchString = searchstring, }; return(View(model)); // return View(await PaginatedList<Person>.CreateAsync(persons/*_context.Persons.AsNoTracking()*/, page ?? 1, pageSize)); }
public PersonsViewModel person_View(int id_person) { PersonsViewModel result = new PersonsViewModel(); un_persons person = Person.GetById(id_person); if (person != null) { result.FirstName = person.FirstName; result.SirName = person.SirName; result.LastName = person.LastName; result.id_person = person.id_person; result.id_gender = person.id_gender; result.id_module = person.id_module; result.FirstName = person.FirstName; result.FirstName = person.FirstName; } return(result); }
// GET: Person/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Person person = db.Persons.Find(id); if (person == null) { return(HttpNotFound()); } var Results = from b in db.Skills select new { b.SkillId, b.Skills, Checked = ((from ab in db.PersonToSkills where (ab.PersonId == id) & (ab.SkillId == b.SkillId) select ab).Count() > 0) }; var MyViewModel = new PersonsViewModel(); MyViewModel.PersonId = id.Value; MyViewModel.Name = person.Name; MyViewModel.Experience = person.Experience; MyViewModel.Contactno = person.Contactno; MyViewModel.Email = person.Email; var MyCheckBoxList = new List <CheckBoxViewModel>(); foreach (var item in Results) { MyCheckBoxList.Add(new CheckBoxViewModel { Id = item.SkillId, Name = item.Skills, Checked = item.Checked }); } MyViewModel.Skills = MyCheckBoxList; return(View(MyViewModel)); }
public IActionResult People() { List <Person> persons = new List <Person>(); persons.Add(new Person() { Name = "Daniel Steel", Link = "https://www.biography.com/people/danielle-steel" }); persons.Add(new Person() { Name = "Tim Schafer", Link = " https://www.biography.com/people/tim-schafer" }); // Wk3 sort requirement persons.Sort((pers1, pers2) => pers1.Name.CompareTo(pers2.Name)); PersonsViewModel personsViewModel = new PersonsViewModel(); personsViewModel.Persons = persons; return(View("People", personsViewModel)); }
public IActionResult Index(PersonsViewModel personsViewParam) { PersonsViewModel personsViewModel; if (personsViewParam.NumberOfVictims > 0) { personsViewModel = personsViewParam; } else { personsViewModel = new PersonsViewModel() { NumberOfVictims = 2 } }; if (!personsViewModel.Calculate) { personsViewModel.Persons.Clear(); for (int i = 0; i < personsViewModel.NumberOfVictims; i++) { personsViewModel.Persons.Add(new PersonViewModel() { AgeOfDeath = 10, YearOfDeath = 12 }); } } else { var deathCalculator = new DeathCalculator(); personsViewModel.Result = deathCalculator.CalculateAveragePeopleKilledOnYearOfBirth(personsViewModel.Persons. Select(x => new Person() { AgeOfDeath = x.AgeOfDeath, YearOfDeath = x.YearOfDeath }).ToList()); } return(View(personsViewModel)); } }
// GET: Persons/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var person = await _context.Persons.FindAsync(id); if (person == null) { return(NotFound()); } var vm = new PersonsViewModel { Person = person, GenderSelectList = new SelectList(_context.Genders, "GenderId", "Name", person.GenderId) }; return(View(vm)); }
public ActionResult Edit(int id, PersonsViewModel model) { try { var user = new User() { Email = model.Email, Roles = model.Roles == Roles.Director ? "Director" : model.Roles == Roles.User ? "User" : "Secretary", UserDetails = new UserDetails() { FirstName = model.FirstName, LastName = model.LastName } }; _db.ModyfiUser(id, user); return(RedirectToAction("Index")); } catch { return(View()); } }
// GET: Persons/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } var vm = new PersonsViewModel { Person = await _context.Persons .Include(p => p.Gender) .Include(p => p.FamilyTree) .FirstOrDefaultAsync(m => m.PersonId == id) }; if (vm.Person == null) { return(NotFound()); } return(View(vm)); }
public ActionResult Create(PersonsViewModel model) { try { var password = string.Join("", Guid.NewGuid().ToString().Take(8)); var user = new User() { Email = model.Email, Password = password, Roles = model.Roles == Roles.Director?"Director": model.Roles == Roles.User ? "User":"******", UserDetails = new UserDetails() { FirstName = model.FirstName, LastName = model.LastName } }; _db.AddUser(user); return(RedirectToAction("Index")); } catch { return(View()); } }
public void RefreshPersonListTest() { #region Fill db var persons = new List <Person> { new Person { Id = 1, Pol = "мужской" }, new Person { Id = 2, Pol = "мужской" }, new Person { Id = 3, Pol = "мужской" }, new Person { Id = 4 }, //no docs }.AsQueryable(); var personDocs = new List <PersonDoc> { new PersonDoc { PersonId = 1, DocTypeId = DocConsts.ВоенныйБилет, FileName = "file" }, new PersonDoc { PersonId = 1, DocTypeId = DocConsts.Паспорт, FileName = "file" }, new PersonDoc { PersonId = 1, DocTypeId = DocConsts.Прописка, FileName = "file" }, new PersonDoc { PersonId = 2, DocTypeId = DocConsts.Паспорт, FileName = "file" }, new PersonDoc { PersonId = 2, DocTypeId = DocConsts.Прописка }, new PersonDoc { PersonId = 2, DocTypeId = DocConsts.ВоенныйБилет }, new PersonDoc { PersonId = 3, DocTypeId = DocConsts.Приписное1, FileName = "file" }, new PersonDoc { PersonId = 3, DocTypeId = DocConsts.Приписное2, FileName = "file" }, new PersonDoc { PersonId = 3, DocTypeId = DocConsts.Паспорт, FileName = "file" }, new PersonDoc { PersonId = 3, DocTypeId = DocConsts.Прописка, FileName = "file" }, }.AsQueryable(); SetUpMocks(persons, personDocs); #endregion var vm = new PersonsViewModel(); //var db=NinjectContext.Get<ProvodnikContext>(); //var docs = db.Persons.FirstOrDefault();//.PersonDocs; //var docsl = db.Persons.ToList(); vm.RefreshPersonList(); Assert.That(vm.PersonList.Count == 4); vm.ExtendedChecks.First(pp => pp.DocType == DocConsts.ВоенныйБилет).IsChecked = true; vm.RefreshPersonList(); var ids = vm.PersonList.Select(pp => pp.Id).ToArray(); CollectionAssert.AreEquivalent(ids, new int[] { 1, 3 }); vm.ExtendedChecks.First(pp => pp.DocType == DocConsts.ВоенныйБилет).IsChecked = false; vm.RefreshPersonList(); ids = vm.PersonList.Select(pp => pp.Id).ToArray(); CollectionAssert.AreEquivalent(ids, new int[] { 2 }); //Assert.That(docs.Count ==2); //Assert.Fail(); }
public MainWindow() { InitializeComponent(); personViewModel = new PersonsViewModel(); DataContext = personViewModel; }
public PersonsView() { this.Suggestions = new ObservableCollection <string>(); this.InitializeComponent(); ViewModel = new PersonsViewModel(); }
public PersonsUserControl() { InitializeComponent(); personsViewModel = new PersonsViewModel(); DataContext = personsViewModel; }
public PersonHandler(PersonsViewModel personsViewModel) { this.personsViewModel = personsViewModel; }
public PersonsView() { InitializeComponent(); BindingContext = new PersonsViewModel(); }
public MainWindow() { InitializeComponent(); DataContext = new PersonsViewModel(new MyDialogService(), new XmlFileService()); }
static PersonsViewModelCreator() { PersonsViewModel = new PersonsViewModel(PersonsCreator.Persons, CreatingMethod); }