public virtual void Add(BoardMember member, IEnumerable<Skill> skills, IEnumerable<ServiceArea> serviceAreas)
        {
            using (var context = new SqlDataContext())
            {
                member.AvailableSkills.Clear();
                member.Interests.Clear();

                context.BoardMembers.Add(member);
                context.SaveChanges();

                if (skills != null && serviceAreas != null && member.AvailableSkills != null && member.Interests != null)
                {
                    member.AvailableSkills.Clear();
                    member.Interests.Clear();

                    var rawSkillIds = skills.Select(x => (int)x);
                    var rawServiceIds = serviceAreas.Select(x => (int)x);

                    var transformSkils = context.Skills.Where(x => rawSkillIds.Contains(x.SkillId)).ToList();
                    var transformAreas = context.ServiceAreas.Where(x => rawServiceIds.Contains(x.ServiceAreaId)).ToList();

                    transformSkils.ForEach(x => member.AvailableSkills.Add(x));
                    transformAreas.ForEach(x => member.Interests.Add(x));
                }

                context.SaveChanges();
            }
        }
        public virtual void Add(Charity charity)
        {
            using (var context = new SqlDataContext())
            {
                context.Charities.Add(charity);
                context.SaveChanges();
            }

            _searchRepository.UpdateSearchIndexForCharity(charity.CharityId);
        }
        public void CanCrudBoardMembers()
        {
            Database.SetInitializer<SqlDataContext>(null);

            var dataContext = new SqlDataContext();

            //Insert!
            var member = new BoardMember
            {
                FirstName = "bob",
                LastName = "smith",
                BirthDay = DateTime.Now,
                Employer = "wut.com",
                Title = "le title",
                Phone = "8765435467",
                Email = "*****@*****.**",
                Address1 = "123 Foo",
                Address2 = "Suite 5",
                City = "Dallas",
                State = "TX",
                PostalCode = "76543",
                MissionStatement = "To hate Ken"
                
            };
            dataContext.BoardMembers.Add(member);
            dataContext.SaveChanges();

            //Get
            var dude = dataContext.BoardMembers.Find(member.BoardMemberId);
            Assert.IsNotNull(dude);

            //Update
            dude.LastName = "JustinIsShort";
            dataContext.SaveChanges();
            dude = dataContext.BoardMembers.Find(member.BoardMemberId);
            Assert.AreEqual("JustinIsShort", dude.LastName, "Bad last name.");

            //Delete
            dataContext.BoardMembers.Remove(dude);
            dataContext.SaveChanges();
            dude = dataContext.BoardMembers.Find(member.BoardMemberId);
            Assert.IsNull(dude, "Did not delete.");
        }
        public virtual void Update(Charity updatedData, IEnumerable<Skill> neededSkills, IEnumerable<ServiceArea> neededAreas)
        {
            using (var context = new SqlDataContext())
            {
                var charity = context.Charities.First(x => x.CharityId == updatedData.CharityId);

                charity.Address1 = updatedData.Address1;
                charity.Address2 = updatedData.Address2;
                charity.City = updatedData.City;
                charity.Email = updatedData.Email;
                charity.Essay = updatedData.Essay;
                charity.FirstName = updatedData.FirstName;
                charity.LastName = updatedData.LastName;
                charity.OrganizationName = updatedData.OrganizationName;
                charity.Phone = updatedData.Phone;
                charity.PostalCode = updatedData.PostalCode;
                charity.State = updatedData.State;
                charity.Website = updatedData.Website;
                charity.YearsService = updatedData.YearsService;
                charity.IsSearchable = updatedData.IsSearchable;

                if (!string.IsNullOrWhiteSpace(updatedData.Password))
                    charity.Password = updatedData.Password;

                charity.NeededSkills.Clear();
                charity.NeededServiceAreas.Clear();

                var skillTransform = neededSkills.Select(x => (int)x);
                var areaTransform = neededAreas.Select(x => (int)x);

                var newSkills = context.Skills.Where(x => skillTransform.Contains(x.SkillId)).ToList();
                var newAreas = context.ServiceAreas.Where(x => areaTransform.Contains(x.ServiceAreaId)).ToList();

                newSkills.ForEach(x => charity.NeededSkills.Add(x));
                newAreas.ForEach(x => charity.NeededServiceAreas.Add(x));

                context.SaveChanges();
            }

            _searchRepository.UpdateSearchIndexForCharity(updatedData.CharityId);
        }
        public virtual void Update(BoardMember updatedMember, IEnumerable<Skill> skills, IEnumerable<ServiceArea> serviceAreas)
        {
            using (var context = new SqlDataContext())
            {
                var member = context.BoardMembers.First(x => x.BoardMemberId == updatedMember.BoardMemberId);

                member.Address1 = updatedMember.Address1;
                member.Address2 = updatedMember.Address2;
                member.City = updatedMember.City;
                member.Email = updatedMember.Email;
                member.Employer = updatedMember.Employer;
                member.FirstName = updatedMember.FirstName;
                member.LastName = updatedMember.LastName;
                member.Title = updatedMember.Title;
                member.Phone = updatedMember.Phone;
                member.PostalCode = updatedMember.PostalCode;
                member.State = updatedMember.State;
                member.Ethnicity = updatedMember.Ethnicity;
                member.Gender = updatedMember.Ethnicity;
                member.YearsService = updatedMember.YearsService;
                member.MissionStatement = updatedMember.MissionStatement;
                member.BirthDay = updatedMember.BirthDay;
                member.IsSearchable = updatedMember.IsSearchable;
                if (!String.IsNullOrWhiteSpace(updatedMember.Password))
                    member.Password = updatedMember.Password;

                if (skills != null && serviceAreas != null && member.AvailableSkills != null && member.Interests != null)
                {
                    member.AvailableSkills.Clear();
                    member.Interests.Clear();

                    var rawSkillIds = skills.Select(x => (int)x);
                    var rawServiceIds = serviceAreas.Select(x => (int)x);

                    var transformSkils = context.Skills.Where(x => rawSkillIds.Contains(x.SkillId)).ToList();
                    var transformAreas = context.ServiceAreas.Where(x => rawServiceIds.Contains(x.ServiceAreaId)).ToList();

                    transformSkils.ForEach(x => member.AvailableSkills.Add(x));
                    transformAreas.ForEach(x => member.Interests.Add(x));
                }

                context.SaveChanges();
            }
        }