Пример #1
0
        public static void AddPersonToGroup(int groupId, int personId)
        {
            using (oikonomosEntities context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                //First check to see if they are not already there
                var check = (from pg in context.PersonGroups
                             where pg.PersonId == personId
                             && pg.GroupId == groupId
                             select pg).FirstOrDefault();
                if (check == null)
                {
                    //Add them
                    PersonGroup personGroup = new PersonGroup();
                    context.PersonGroups.AddObject(personGroup);
                    personGroup.Created = DateTime.Now;
                    personGroup.Changed = DateTime.Now;
                    personGroup.PersonId = personId;
                    personGroup.GroupId = groupId;
                    personGroup.Joined = DateTime.Now;

                    context.SaveChanges();
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the PersonGroups EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPersonGroups(PersonGroup personGroup)
 {
     base.AddObject("PersonGroups", personGroup);
 }
Пример #3
0
 /// <summary>
 /// Create a new PersonGroup object.
 /// </summary>
 /// <param name="personGroupId">Initial value of the PersonGroupId property.</param>
 /// <param name="personId">Initial value of the PersonId property.</param>
 /// <param name="groupId">Initial value of the GroupId property.</param>
 /// <param name="joined">Initial value of the Joined property.</param>
 /// <param name="created">Initial value of the Created property.</param>
 /// <param name="changed">Initial value of the Changed property.</param>
 public static PersonGroup CreatePersonGroup(global::System.Int32 personGroupId, global::System.Int32 personId, global::System.Int32 groupId, global::System.DateTime joined, global::System.DateTime created, global::System.DateTime changed)
 {
     PersonGroup personGroup = new PersonGroup();
     personGroup.PersonGroupId = personGroupId;
     personGroup.PersonId = personId;
     personGroup.GroupId = groupId;
     personGroup.Joined = joined;
     personGroup.Created = created;
     personGroup.Changed = changed;
     return personGroup;
 }
Пример #4
0
        public Person UpdatePerson(PersonViewModel person, Person currentPerson, out bool sendWelcomeEmail, out Church church)
        {
            sendWelcomeEmail = false;

            //We need some settings from the Church table
            church = _churchRepository.GetChurch(currentPerson.ChurchId);

            var personToSave = new Person();
            if (person.PersonId != 0)
            {
                personToSave = FetchPerson(person.PersonId, currentPerson);
            }
            else
            {
                Context.AddToPeople(personToSave);
                personToSave.ChurchId = church.ChurchId;
                personToSave.Church = church;

                personToSave.Created = DateTime.Now;
                if (church.SendWelcome)
                {
                    sendWelcomeEmail = true;
                }

                if (person.GroupId > 0)
                {
                    var pg = new PersonGroup
                    {
                        GroupId = person.GroupId,
                        Person = personToSave,
                        Joined = DateTime.Now,
                        Created = DateTime.Now,
                        Changed = DateTime.Now
                    };
                    personToSave.PersonGroups.Add(pg);
                }
            }

            if (person.FamilyId == 0)
            {
                if (person.FindFamily)
                {
                    var family = (from f in Context.Families
                                  join p in Context.People
                                      on f.FamilyId equals p.FamilyId
                                  join g in Context.PersonGroups
                                      on p.PersonId equals g.PersonId
                                  where f.FamilyName == person.Surname
                                      && g.GroupId == person.GroupId
                                  select f).FirstOrDefault();
                    personToSave.Family = family ?? new Family {Created = DateTime.Now};
                }
                else
                {
                    personToSave.Family = new Family {Created = DateTime.Now};
                }
            }
            else
            {
                personToSave.Family = (from f in Context.Families
                                       where f.FamilyId == person.FamilyId
                                       select f).FirstOrDefault() ?? new Family {Created = DateTime.Now};
            }

            personToSave.Family.Changed = DateTime.Now;
            personToSave.Changed = DateTime.Now;

            personToSave.Firstname = person.Firstname;
            personToSave.Family.FamilyName = person.Surname;
            personToSave.Email = person.Email;
            personToSave.DateOfBirth = person.DateOfBirth_Value;
            Context.SaveChanges();

            return personToSave;
        }