Beispiel #1
0
 //add parliament member to db only
 public bool AddMember(CustomPolitcian politcian)
 {
     if (politcian == null)
     {
         return(false);
     }
     else
     {
         if (politcian.Firstname == null || politcian.Lastname == null || politcian.Party == null)
         {
             return(false);
         }
         else
         {
             entities.Politician.Add(new Politician()
             {
                 firstname = politcian.Firstname,
                 lastname  = politcian.Lastname,
                 partyId   = entities.Party.Where(p => p.name.Equals(politcian.Party)).SingleOrDefault().id
             });
             entities.ContactInfo.Add(new ContactInfo()
             {
                 email        = politcian.Email,
                 phone        = politcian.Phone,
                 politicianId = entities.Politician.Last().id
             });
             return(true);
         }
     }
 }
Beispiel #2
0
        //Edit function for parliament members
        public string EditMember(CustomPolitcian politcian)
        {
            string     msg = "";
            Politician selectedPolitician = entities.Politician.Where(p => p.id == politcian.PoliticianId).SingleOrDefault();

            selectedPolitician.firstname = politcian.Firstname;
            selectedPolitician.lastname  = politcian.Lastname;
            selectedPolitician.partyId   = entities.Party.Where(p => p.name.Equals(politcian.Party)).SingleOrDefault().id;
            selectedPolitician.ContactInfo.SingleOrDefault().phone = politcian.Phone;
            selectedPolitician.ContactInfo.SingleOrDefault().email = politcian.Email;
            entities.SaveChanges();

            return(msg);
        }