예제 #1
0
    public Person CreatePerson(string name, PeopleGroup peopleGroup) {
      var dmPerson = new DataModel.Person {
        Id = ACore.Db.GetNextIdFor<DataModel.Person>(),
        Name = name,
        PeopleGroupId = peopleGroup?.Id
      };

      ACore.Db.Insert(dmPerson);

      var vmPerson = new Person(dmPerson);
      AllPeople.Add(vmPerson);
      SetInPalce(vmPerson, true);
      return vmPerson;
    }
예제 #2
0
    public void NewOrRenamePerson(Person person, PeopleGroup peopleGroup, bool rename) {
      InputDialog inputDialog = new InputDialog {
        Owner = ACore.WMain,
        IconName = "appbar_people",
        Title = rename ? "Rename Person" : "New Person",
        Question = rename ? "Enter the new name of the person." : "Enter the name of the new person.",
        Answer = rename ? person.Title : string.Empty
      };

      inputDialog.BtnDialogOk.Click += delegate {
        if (rename && string.Compare(inputDialog.Answer, person.Title, StringComparison.OrdinalIgnoreCase) == 0) {
          inputDialog.DialogResult = true;
          return;
        }

        if (ACore.Db.People.SingleOrDefault(x => x.Name.Equals(inputDialog.Answer)) != null) {
          inputDialog.ShowErrorMessage("Person's name already exists!");
          return;
        }

        inputDialog.DialogResult = true;
      };

      inputDialog.TxtAnswer.SelectAll();

      if (inputDialog.ShowDialog() ?? true) {
        if (rename) {
          person.Title = inputDialog.Answer;
          person.Data.Name = inputDialog.Answer;
          ACore.Db.UpdateOnSubmit(person.Data);
          ACore.Db.SubmitChanges();
          SetInPalce(person, false);
        } else CreatePerson(inputDialog.Answer, peopleGroup);
      }
    }
예제 #3
0
    public void DeletePerson(Person person) {
      foreach (var mip in ACore.Db.MediaItemPeople.Where(x => x.PersonId == person.Id)) {
        ACore.Db.DeleteOnSubmit(mip);
      }

      ACore.Db.DeleteOnSubmit(person.Data);
      ACore.Db.SubmitChanges();

      if (person.PeopleGroupId == null) {
        Items.Remove(person);
      } else {
        Items.OfType<PeopleGroup>().Single(x => x.Id == person.PeopleGroupId).Items.Remove(person);
      }

      AllPeople.Remove(person);
    }
예제 #4
0
 public void MovePerson(Person person, PeopleGroup peopleGroup) {
   if (person.PeopleGroupId == null) {
     Items.Remove(person);
   } else {
     Items.OfType<PeopleGroup>().Single(x => x.Id == person.PeopleGroupId).Items.Remove(person);
   }
   var newGroupId = peopleGroup?.Id;
   person.PeopleGroupId = newGroupId;
   person.Data.PeopleGroupId = newGroupId;
   ACore.Db.UpdateOnSubmit(person.Data);
   ACore.Db.SubmitChanges();
   SetInPalce(person, true); //person is new in the group
 }
예제 #5
0
 public void SetInPalce(Person person, bool isNew) {
   var idx = ACore.Db.People.Where(x => x.PeopleGroupId == person.PeopleGroupId).OrderBy(x => x.Name).ToList().IndexOf(person.Data);
   if (person.PeopleGroupId == null) {
     idx += Items.OfType<PeopleGroup>().Count();
     if (isNew)
       Items.Insert(idx, person);
     else
       Items.Move(Items.IndexOf(person), idx);
   } else {
     var g = Items.OfType<PeopleGroup>().Single(x => x.Id == person.PeopleGroupId);
     if (isNew)
       g.Items.Insert(idx, person);
     else 
       g.Items.Move(g.Items.IndexOf(person), idx);
   }
 }