public MainWindowViewModel() { PeopleList.Add(new ListModel { Name = "小明", Age = 15 }); //添加行信息 PeopleList.Add(new ListModel { Name = "小王", Age = 14 }); peopleList.Add(new ListModel { Name = "小李", Age = 13 }); }
//ДОбавление персонажа public void AddPerson(string name, string personClass, int body, int mind, int spirit, out string errorMessage) { errorMessage = ""; //Првоерка, существует ли персонаж с таким именем Person exsistPerson = PeopleList.FirstOrDefault(p => p.Name == name); if (exsistPerson != null) { errorMessage = "Персонаж с таким именем уже существует"; return; } //Прочие проверки if (string.IsNullOrEmpty(name)) { errorMessage = "Имя не должно быть пустым"; return; } if (string.IsNullOrEmpty(personClass)) { errorMessage = "Класс не должен быть пустым"; return; } if (body < 5) { errorMessage = "Параметр body не должен быть меньше 5"; return; } if (mind < 5) { errorMessage = "Параметр mind не должен быть меньше пяти"; return; } if (spirit < 5) { errorMessage = "Парметр spirit не должен быть меньше пять"; return; } if (!(body + spirit + mind <= 20)) { errorMessage = "Сумма параметров body, mind, spirit не может превышать 20"; return; } //Создание персонажа, добавление в список, а также сохранение данного списка Person person = new Person(name, personClass, body, mind, spirit); PeopleList.Add(person); SaveLoadService.Save(PeopleList); }
private void CreateFillerData() { for (int i = 0; i < 3; i++) { var movie = CreateMovieWithoutRelatedInfo(); InitialMoviesInDb.Add(movie); var similar = new MovieSimilar { Movie = TestMovieSeededWithRelatedInfo, MovieId = TestMovieSeededWithRelatedInfo.Id, Similar = movie, SimilarId = movie.Id }; TestMovieSeededWithRelatedInfo.Similars.Add(similar); } for (int i = 0; i < 3; i++) { var person = CreatePersonWithoutRelatedInfo(); PeopleList.Add(person); TestMovieSeededWithRelatedInfo.ActorList.Add(new MovieActor { Movie = TestMovieSeededWithRelatedInfo, MovieId = TestMovieSeededWithRelatedInfo.Id, Person = person, PersonId = person.Id }); } for (int i = 0; i < 3; i++) { var person = CreatePersonWithoutRelatedInfo(); PeopleList.Add(person); TestMovieSeededWithRelatedInfo.DirectorList.Add(new MovieDirector { Movie = TestMovieSeededWithRelatedInfo, MovieId = TestMovieSeededWithRelatedInfo.Id, Person = person, PersonId = person.Id }); } for (int i = 0; i < 3; i++) { var person = CreatePersonWithoutRelatedInfo(); PeopleList.Add(person); TestMovieSeededWithRelatedInfo.WriterList.Add(new MovieWriter { Movie = TestMovieSeededWithRelatedInfo, MovieId = TestMovieSeededWithRelatedInfo.Id, Person = person, PersonId = person.Id }); } for (int i = 0; i < 3; i++) { var company = CreateCompanyWithoutRelatedInfo(); CompanyList.Add(company); TestMovieSeededWithRelatedInfo.CompanyList.Add(new MovieCompany { Movie = TestMovieSeededWithRelatedInfo, MovieId = TestMovieSeededWithRelatedInfo.Id, Company = company, CompanyId = company.Id }); } for (int i = 0; i < 3; i++) { var rating = fixture.Build <Rating>() .With(x => x.Movie, TestMovieSeededWithRelatedInfo) .With(x => x.MovieId, TestMovieSeededWithRelatedInfo.Id) .Create(); TestMovieSeededWithRelatedInfo.Ratings.Add(rating); } }
public void AddPerson(Person person) { PeopleList.Add(person); SaveChanges(); }
private void EventsUpdateTask() { if (UpdateHelper.Instance.EventsListAdditionHelper.Count != 0) { foreach (Event e in UpdateHelper.Instance.EventsListAdditionHelper) { if (!EventsList.Contains(e, new EventComparer())) { EventsList.Add(e); foreach (Person p in e.Participants) { Person foundPerson = PeopleList.First(pe => pe.JMBG.Equals(p.JMBG)); PeopleList.Remove(foundPerson); foundPerson.ScheduledEvents.Add(e); PeopleList.Add(foundPerson); //OPREZ } } } } if (UpdateHelper.Instance.EventsListRemovalHelper.Count != 0) { foreach (Event e in UpdateHelper.Instance.EventsListRemovalHelper) { if (EventsList.Contains(e, new EventComparer())) { Event foundEvent = EventsList.FirstOrDefault(ev => ev.EventId.Equals(e.EventId)); EventsList.Remove(foundEvent); foreach (Person p in e.Participants) { Person foundPerson = PeopleList.First(pe => pe.JMBG.Equals(p.JMBG)); PeopleList.Remove(foundPerson); foundPerson.ScheduledEvents = new List <Event>(foundPerson.ScheduledEvents.Where(ev => ev.EventId != e.EventId)); PeopleList.Add(foundPerson); } } } } if (UpdateHelper.Instance.EventsListModificationHelper.Count != 0) { foreach (Event e in UpdateHelper.Instance.EventsListModificationHelper) { if (EventsList.Contains(e, new EventComparer())) { Event foundEvent = EventsList.FirstOrDefault(ev => ev.EventId.Equals(e.EventId)); EventsList.Remove(foundEvent); EventsList.Add(e); foreach (Person p in e.Participants) { Person foundPerson = PeopleList.First(pe => pe.JMBG.Equals(p.JMBG)); PeopleList.Remove(foundPerson); foundPerson.ScheduledEvents = new List <Event>(foundPerson.ScheduledEvents.Where(ev => ev.EventId != e.EventId)); foundPerson.ScheduledEvents.Add(e); PeopleList.Add(foundPerson); } } } } if (++UpdateHelper.Instance.EventCounter >= UpdateHelper.Instance.Limit - 1) { UpdateHelper.Instance.EventsListAdditionHelper = new List <Event>(); UpdateHelper.Instance.EventsListRemovalHelper = new List <Event>(); UpdateHelper.Instance.EventsListModificationHelper = new List <Event>(); UpdateHelper.Instance.EventCounter = 0; } }
private void Form2_Click(object sender, EventArgs e) { PeopleList.Add(new People(firstNameTextBox.Text, lastNameTextBox.Text, middleNameTextBox.Text)); }