Exemple #1
0
        public void AddChurch_Church_Tests(double lattitude, double longitude, string day1, int hour1, int minute1, string day2, int hour2, int minute2, string churchName)
        {
            _churchService.RemoveAllChurchesForTesting();
            var churchLoc = new Location {
                Latitude = lattitude, Longitude = longitude
            };
            var massTimes = new List <IMassTime>
            {
                new MassTime {
                    Day = Enum.Parse <DayOfWeek>(day1), Hour = hour1, Minute = minute1
                },
                new MassTime {
                    Day = Enum.Parse <DayOfWeek>(day2), Hour = hour2, Minute = minute2
                },
            };
            var expected = new Church {
                Coordinates = churchLoc, MassTimes = massTimes, Name = churchName
            };
            var actualListBefore = (List <Church>)_churchService.ReturnAllChurchesForTesting();

            _churchService.AddChurch(expected);

            var actualListAfter = (List <Church>)_churchService.ReturnAllChurchesForTesting();

            Assert.True(
                actualListAfter.Count == actualListBefore.Count + 1 &&
                actualListAfter.Find(c => c.Name == expected.Name)
                .MassTimes == expected.MassTimes);
        }
        public void ChurchRule_Is_Not_Satisfied_When_There_Are_More_Less_100_ResidencesAnd_In_Neighborhood()
        {
            IRoad road   = _settlement.Roads.First();
            var   church = new Church()
            {
                Position = new Point(50, 51)
            };

            var buildingPositions = road.GetPossibleBuildingPositions(new PossibleBuildingPositions(_settlement.Roads, _settlement.Fields));

            buildingPositions.Remove(church.Position);

            while (_settlement.Roads.SelectMany(g => g.Buildings).Count() < 10)
            {
                var position = buildingPositions[RandomProvider.Next(buildingPositions.Count)];
                var building = new Residence {
                    Position = position
                };
                building.Road = road;
                _settlement.AddBuildingToRoad(road, building);
            }

            Assert.AreEqual(0, church.CalculateFitness(new BuildingRule()
            {
                BuildingRoad     = road,
                Fields           = _settlement.Fields,
                Roads            = _settlement.Roads,
                SettlementCenter = _settlement.SettlementCenter
            }));
        }
Exemple #3
0
    public override int CalculateProduction(Tile tile)
    {
        List <Tile> tilesInRange   = tile.GetAllTilesAround(collectionRange);
        int         collectedFunds = baseProduction;

        foreach (var tempTile in tilesInRange)
        {
            if (tempTile.placedBuilding == null)
            {
                continue;
            }

            if (tempTile.placedBuilding is House)
            {
                House house = tempTile.placedBuilding as House;
                collectedFunds += house.CalculateProduction();
            }

            if (tempTile.placedBuilding is Church)
            {
                Church church = tempTile.placedBuilding as Church;
                collectedFunds += church.bonusForMarket;
            }
        }

        return(collectedFunds);
    }
        //[ValidateAntiForgeryToken]
        public ActionResult Create(Church church)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new NewChurchViewModel
                {
                    Church = church,
                    //MembershipTypes = _context.MembershipTypes.ToList()
                };

                return(View("ChurchForm", viewModel));
            }
            if (church.Id == 0)
            {
                _context.churches.Add(church);
            }
            else
            {
                var churchInDb = _context.churches.Single(c => c.Id == church.Id);
                churchInDb.Name = church.Name;
            }
            _context.SaveChanges();
            return(RedirectToAction("Index", "Church"));
            //  return View();
        }
Exemple #5
0
        public ActionResult Edit(Church church)
        {
            var dbChurch = db.Churches.Find(church.Id);

            dbChurch.Name    = church.Name;
            dbChurch.Address = church.Address;
            dbChurch.City    = church.City;
            dbChurch.State   = church.State;
            dbChurch.Country = church.Country;
            dbChurch.ZipCode = church.ZipCode;
            dbChurch.Phone   = church.Phone;
            dbChurch.Email   = church.Email;
            dbChurch.FbPage  = church.FbPage;
            if (ModelState.IsValid)
            {
                dbChurch.DateLastEdited = DateTime.Now;
                dbChurch.EditedBy       = Guid.Parse(Operator().Id);
                //db.Entry(church).State = EntityState.Modified;
                db.SaveChanges();
                ViewBag.Success = true;
                return(View(dbChurch));
            }
            else
            {
                ModelState.AddModelError("", "Something went wrong while saving");
            }
            return(View(church));
        }
Exemple #6
0
        static void Main(string[] args)
        {
            Cartier      cartier           = new Cartier("Rogerius");
            CapeCodStyle capeCodStyleHouse = new CapeCodStyle();
            School       school1           = new School();
            School       school2           = new School();
            Bloc         bloc   = new Bloc();
            Church       church = new Church();

            Console.Write("Houses: ");
            Console.WriteLine(House.count);
            Console.Write("Institutions: ");
            Console.WriteLine(Institution.count);
            Console.Write("All buildings: ");
            Console.WriteLine(Building.count);


            school1.StreetName      = "Str. Henri Coanda";
            school1.BlockNumber     = "Nr.17";
            school1.ApartmentNumber = "Ap.3";


            school2.StreetName  = "Str. Moscovei";
            school2.BlockNumber = "Nr.1";

            Console.WriteLine("The Address of School 1: " + school1.StreetName + " " + school1.BlockNumber + " ");
            Console.WriteLine("The Address of School Ady Endre: " + school2.StreetName + " " + school2.BlockNumber + " ");
        }
Exemple #7
0
 void Start()
 {
     current = 0;
     now     = 0;
     church  = new Church();
     field   = new Field();
 }
Exemple #8
0
        public ActionResult Create(Church church)
        {
            var ownerId  = Operator().OwnerGroupId;
            var churches = db.Churches.Where(x => x.OwnerGroupId == ownerId).ToList();

            if (churches != null)
            {
                var churchExist = db.Churches.Where(x => x.OwnerGroupId == ownerId).Count() > 0;
                if (churchExist)
                {
                    ModelState.AddModelError("", "You're only allowed to have 1 church");
                    return(RedirectToAction("Edit"));
                }
            }

            church.Id           = Guid.NewGuid();
            church.OwnerGroupId = Operator().OwnerGroupId;
            church.DateEntered  = DateTime.Now;
            church.EnteredBy    = Guid.Parse(Operator().Id);

            if (ModelState.IsValid)
            {
                db.Churches.Add(church);
                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }

            return(View(church));
        }
Exemple #9
0
        public IHttpActionResult Post(Church church)
        {
            try
            {
                if (church == null)
                {
                    return(BadRequest("church required"));
                }

                var result = _repository.Add(church);

                if (result.Status == RepositoryActionStatus.Created)
                {
                    return(Created(Request.RequestUri + "/" + result.Entity.id.ToString(), result.Entity));
                }

                return(BadRequest());
            }
            catch (Exception ex)
            {
                ErrorHelper.ProcessError(_logger, ex, nameof(Delete));

                return(InternalServerError());
            }
        }
Exemple #10
0
        public static ObservableCollection <Church> GetChurchs()
        {
            churchList = new ObservableCollection <Church>();

            var church1 = new Church()
            {
                Name = "Church 1", PastorName = "Pr. 1", Phone = "123456"
            };
            var church2 = new Church()
            {
                Name = "Church 2", PastorName = "Pr. 2", Phone = "123456"
            };
            var church3 = new Church()
            {
                Name = "Church 3", PastorName = "Pr. 3", Phone = "123456"
            };
            var church4 = new Church()
            {
                Name = "Church 4", PastorName = "Pr. 4", Phone = "123456"
            };

            churchList.Add(church1);
            churchList.Add(church2);
            churchList.Add(church3);
            churchList.Add(church4);

            return(churchList);
        }
        private void SaveChurch_E(object obj)
        {
            //Check if the Church has already been added
            var Church = db.Churches.Where(i => i.Name == NewChurch.Name && i.Address == NewChurch.Address && i.Email == NewChurch.Email).FirstOrDefault();

            if (Church == null)//&& ValidateNewClient(NewClient)
            {
                NewChurch.Logo = Methods.GetImageBytes(imageName);
                db.Churches.Add(NewChurch);

                db.SaveChanges();
                NewChurch = new Church();
                refreshCs_E(null);
                // show messagebox to alert success;
                MessageBox.Show("Church Added Successfully", "Success !! ", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            else if (Church != null)
            {
                Error = this["Duplicate"];
            }
            else
            {
                Error = this["ProvideValues"];
            }

            // show Message Box  to alert failure
            MessageBox.Show("Church to Add Client", "Failure !! ", MessageBoxButton.OK, MessageBoxImage.Error);
        }
Exemple #12
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Church = await _context.Church
                     .Include(c => c.Address)
                     .Include(c => c.Alternate1)
                     .Include(c => c.Alternate2)
                     .Include(c => c.Alternate3)
                     .Include(c => c.Elder1)
                     .Include(c => c.Elder2)
                     .Include(c => c.Elder3)
                     .Include(c => c.Elder4)
                     .Include(c => c.Elder5)
                     .Include(c => c.SeniorMinister)
                     .Include(c => c.Trustee1)
                     .Include(c => c.Trustee2)
                     .Include(c => c.Trustee3)
                     .Include(c => c.YouthMinister).FirstOrDefaultAsync(m => m.Id == id);

            if (Church == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Exemple #13
0
        public async Task <IActionResult> EditChurch(Church church)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(church);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction($"{nameof(DetailsDistrict)}/{church.IdDistrict}"));
                }
                catch (DbUpdateException dbUpdateException)
                {
                    if (dbUpdateException.InnerException.Message.Contains("duplicate"))
                    {
                        ModelState.AddModelError(string.Empty, "There are a record with the same name.");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message);
                    }
                }
                catch (Exception exception)
                {
                    ModelState.AddModelError(string.Empty, exception.Message);
                }
            }
            return(View(church));
        }
        public ActionResult Save(Church church)
        {
            if (!ModelState.IsValid)
            {
                return(View("New", church));
            }



            if (church.Id == 0)
            {
                var newChurch = new Church
                {
                    Name         = church.Name,
                    PhoneNumber1 = church.PhoneNumber1,
                    PhoneNumber2 = church.PhoneNumber2
                };
                _context.Churches.Add(newChurch);
            }
            else
            {
                var existingChurch = _context.Churches.SingleOrDefault(c => c.Id == church.Id);

                existingChurch.Name         = church.Name;
                existingChurch.PhoneNumber1 = church.PhoneNumber1;
                existingChurch.PhoneNumber2 = church.PhoneNumber2;
            }


            _context.SaveChanges();

            return(RedirectToAction("Index"));
        }
Exemple #15
0
        public async Task <IActionResult> DeleteChurch(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Church church = await _context.Churches
                            .FirstOrDefaultAsync(m => m.Id == id);

            if (church == null)
            {
                return(NotFound());
            }

            District district = await _context.Districts.FirstOrDefaultAsync(d => d.Churches.FirstOrDefault(c => c.Id == church.Id) != null);

            try
            {
                _context.Churches.Remove(church);
                await _context.SaveChangesAsync();

                _flashMessage.Confirmation("The church was deleted.");
            }
            catch
            {
                _flashMessage.Danger("The church can't be deleted because it has related records.");
            }
            return(RedirectToAction($"{nameof(DetailsDistrict)}/{district.Id}"));
        }
 private async void SelectChurch(Church _church)
 {
     NavigationParameters navigationParameter = new NavigationParameters
     {
         { "church_detail", _church }
     };
     await _navigationService.NavigateAsync("church_detail", navigationParameter);
 }
Exemple #17
0
 public static string GetPhone(Church church)
 {
     if ((church.Address != null) && (string.IsNullOrEmpty(church.Address.Phone)))
     {
         return(Person.FixPhone(church.Address.Phone));
     }
     return("---");
 }
 void OnTriggerEnter(Collider other)
 {
     if (church == null && other.tag == "Temple")
     {
         church = other.GetComponent <Church> ();
         church.AddFollower();
     }
 }
Exemple #19
0
        public ActionResult DeleteConfirmed(int id)
        {
            Church church = db.Churches.Find(id);

            db.Churches.Remove(church);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #20
0
 public ChurchViewModel(Church entity)
 {
     Contacts    = entity.Contacts.Select(c => new ContactViewModel(c)).ToList();
     WorshipDays = entity.WorshipDays.Select(w => new WorshipDayViewModel(w)).ToList();
     Longitude   = entity.Lng;
     Latitude    = entity.Lat;
     Comment     = entity.Comment;
     Id          = entity.Id;
 }
Exemple #21
0
        public static string GetMembershipStatus(Church church)
        {
            if ((church.MembershipStatus < 0) || (church.MembershipStatus >= CStat.Models.Church.ChurchLists.MemberStatList.Length))
            {
                return("---");
            }

            return(CStat.Models.Church.ChurchLists.MemberStatList[church.MembershipStatus].name);
        }
Exemple #22
0
        public IActionResult DeleteChurch(int ChurchId)
        {
            Church DeleteChurch = _context.Churches
                                  .FirstOrDefault(Chu => Chu.ChurchId == ChurchId);

            _context.Remove(DeleteChurch);
            _context.SaveChanges();
            return(RedirectToAction("AdminDash"));
        }
Exemple #23
0
 private void Initialize()
 {
     this.church        = null;
     this.pastoralTeam  = null;
     this.associateList = new List <AssociatePastor>();
     this.layPastors    = new List <LayPastor>();
     this.soulwinners   = new List <Soulwinner>();
     this.userId        = 0;
 }
Exemple #24
0
 public ActionResult Edit([Bind(Include = "Id,Name,Address,Decanate,Diocese")] Church church)
 {
     if (ModelState.IsValid)
     {
         db.Entry(church).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(church));
 }
Exemple #25
0
        public ActionResult DeleteConfirmed(long id)
        {
            db.Masses.RemoveRange(db.Masses.Where(m => m.ChurchId == id));
            db.Rules.RemoveRange(db.Rules.Where(r => r.ChurchId == id));
            Church church = db.Churches.Find(id);

            db.Churches.Remove(church);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #26
0
        public ActionResult DeleteConfirmed(Guid id)
        {
            return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));

            Church church = db.Churches.Find(id);

            db.Churches.Remove(church);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #27
0
        public IActionResult RemoveFromList(int ChurchId)
        {
            Church UpdateChurch = _context.Churches
                                  .FirstOrDefault(Chu => Chu.ChurchId == ChurchId);

            UpdateChurch.Accept    = false;
            UpdateChurch.UpdatedAt = DateTime.Now;
            _context.SaveChanges();
            return(RedirectToAction("AdminDash"));
        }
Exemple #28
0
        //
        // GET: /Church/Delete/5

        public ActionResult Delete(int id = 0)
        {
            Church church = db.Churches.Find(id);

            if (church == null)
            {
                return(HttpNotFound());
            }
            return(View(church));
        }
Exemple #29
0
 public ActionResult Edit(Church church)
 {
     if (ModelState.IsValid)
     {
         db.Entry(church).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(church));
 }
Exemple #30
0
        public ActionResult Create(Church church)
        {
            if (ModelState.IsValid)
            {
                db.Churches.Add(church);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(church));
        }
Exemple #31
0
        public static string SendWelcomeEmail(string firstname,
            string surname,
            Church church,
            string email,
            string password,
            bool isVisitor,
            bool includeUsernamePassword)
        {
            Guid guid = Guid.NewGuid();

            Task.Factory.StartNew(() => SendWelcomeEmailAsync(firstname,
                                                  surname,
                                                  church,
                                                  email,
                                                  password,
                                                  guid.ToString(),
                                                  isVisitor,
                                                  includeUsernamePassword));

            return guid.ToString();
        }
Language Modeling (Croft and Lafferty, 2003), phrases (Church and Hanks, 1990; Lewis, 1992), and so on.
Exemple #33
0
        private static void SendWelcomeEmailAsync(string firstname,
            string surname,
            Church church,
            string email,
            string password,
            string guid,
            bool isVisitor,
            bool includeUserNamePassword)
        {
            try
            {
                using (MailMessage message = new MailMessage())
                {
                    message.Subject = "Welcome to " + church.SiteHeader;
                    message.Body = GetWelcomeLetterBodyFromDataBase(
                        church.ChurchId,
                        firstname,
                        surname,
                        church.SiteHeader,
                        church.Name,
                        church.OfficePhone,
                        church.OfficeEmail,
                        church.Url,
                        email,
                        password,
                        guid.ToString(),
                        isVisitor,
                        includeUserNamePassword);

                    message.To.Add(email);
                    message.IsBodyHtml = true;

                    SendEmail(message, church.EmailLogin, church.EmailPassword, church.Name);
                }
            }

            catch
            {
                // handle exception here
                // Need to look at some kind of logging
            }
        }
        public static void CreateNewChurch(Person currentPerson, ChurchSettingsViewModel churchSettings)
        {
            if (currentPerson.HasPermission(common.Permissions.SystemAdministrator))
            {
                using (oikonomosEntities context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
                {
                    var newChurch = new Church();
                    context.AddToChurches(newChurch);
                    newChurch.Created = DateTime.Now;

                    PopulateChurchModel(churchSettings, newChurch);
                    newChurch.EmailLogin = "******";
                    newChurch.EmailPassword = "******";
                    PopulateChurchAddress(churchSettings, context, newChurch);
                    context.SaveChanges();

                    //Save Roles
                    var currentChurchRoles = context.Roles.Where(r => (r.ChurchId == currentPerson.ChurchId && r.Name != "System Administrator")).ToList();
                    foreach (var currentRole in currentChurchRoles)
                    {
                        var newChurchRole = new Role();
                        context.AddToRoles(newChurchRole);
                        newChurchRole.Created = DateTime.Now;
                        newChurchRole.Changed = DateTime.Now;
                        newChurchRole.Name = currentRole.Name;
                        newChurchRole.DisplayName = currentRole.DisplayName;
                        newChurchRole.ChurchId = newChurch.ChurchId;

                        foreach (var permission in currentRole.PermissionRoles)
                        {
                            var newRolePerm = new PermissionRole();
                            context.AddToPermissionRoles(newRolePerm);
                            newRolePerm.Created = DateTime.Now;
                            newRolePerm.Changed = DateTime.Now;
                            newRolePerm.PermissionId = permission.PermissionId;
                            newChurchRole.PermissionRoles.Add(newRolePerm);
                        }
                    }

                    context.SaveChanges();

                    //Update Role that can be set by any role
                    foreach (var currentRole in currentChurchRoles)
                    {
                        var newRole = context.Roles.Where(r => (r.ChurchId == newChurch.ChurchId && r.Name == currentRole.Name)).FirstOrDefault();
                        foreach (var roleToSet in currentRole.CanSetRoles)
                        {
                            if (roleToSet.Name != "System Administrator")
                            {
                                var newRoleToSet = context.Roles.FirstOrDefault(r => (r.ChurchId == newChurch.ChurchId && r.Name == roleToSet.Name));
                                newRole.CanSetRoles.Add(newRoleToSet);
                            }
                        }
                    }

                    context.SaveChanges();

                    var churchAdministrator              = new Person();
                    context.AddToPeople(churchAdministrator);
                    churchAdministrator.Created          = DateTime.Now;
                    churchAdministrator.Changed          = DateTime.Now;
                    churchAdministrator.Firstname        = churchSettings.ContactFirstname;
                    churchAdministrator.Church           = newChurch;
                    var churchAdministratorFamily        = new Family();
                    context.AddToFamilies(churchAdministratorFamily);
                    churchAdministratorFamily.FamilyName = churchSettings.ContactSurname;
                    churchAdministratorFamily.Created    = DateTime.Now;
                    churchAdministratorFamily.Changed    = DateTime.Now;
                    churchAdministrator.Family           = churchAdministratorFamily;

                    context.SaveChanges();

                    //Set the new persons role to administrator
                    churchAdministrator.RoleId = context.Roles.First(r => (r.ChurchId == newChurch.ChurchId && r.Name == "Church Administrator")).RoleId;
                    context.SaveChanges();

                    //Update Church Optional Fields
                    var churchOptionalFields = context.ChurchOptionalFields.Where(c=>c.ChurchId == currentPerson.ChurchId);
                    foreach (var co in churchOptionalFields)
                    {
                        var newCo = new ChurchOptionalField();
                        context.AddToChurchOptionalFields(newCo);
                        newCo.Created = DateTime.Now;
                        newCo.Changed = DateTime.Now;
                        newCo.ChurchId = newChurch.ChurchId;
                        newCo.OptionalFieldId = co.OptionalFieldId;
                        newCo.Visible = co.Visible;
                    }

                    context.SaveChanges();
                }
            }
        }
        private static void PopulateChurchAddress(ChurchSettingsViewModel churchSettings, oikonomosEntities context, Church churchToSave)
        {
            //Check to see if the address already exists
            var address = new Address();

            if (churchSettings.AddressId > 0)
            {
                address = (from a in context.Addresses
                           where a.AddressId == churchSettings.AddressId
                           select a).FirstOrDefault();

                if (address == null) //Should never happen, but just to be sure
                {
                    address = new Address();
                    address.Created = DateTime.Now;
                    churchSettings.AddressId = 0;
                }
            }
            else
            {
                address.Created = DateTime.Now;
            }

            address.Line1 = churchSettings.Address1 ?? string.Empty;
            address.Line2 = churchSettings.Address2 ?? string.Empty;
            address.Line3 = churchSettings.Address3 ?? string.Empty;
            address.Line4 = churchSettings.Address4 ?? string.Empty;
            address.AddressType = churchSettings.AddressType ?? string.Empty;
            address.Lat = churchSettings.Lat;
            address.Long = churchSettings.Lng;
            address.Changed = DateTime.Now;

            if (churchSettings.AddressId == 0)
            {
                context.Addresses.AddObject(address);
                churchToSave.Address = address;
            }
        }
 private static void PopulateChurchModel(ChurchSettingsViewModel churchSettings, Church churchToSave)
 {
     churchToSave.Changed = DateTime.Now;
     churchToSave.Name = churchSettings.ChurchName;
     churchToSave.OfficeEmail = churchSettings.OfficeEmail;
     churchToSave.OfficePhone = churchSettings.OfficePhone;
     churchToSave.SiteHeader = churchSettings.SystemName;
     churchToSave.UITheme = churchSettings.UITheme;
     churchToSave.Url = churchSettings.Url;
     churchToSave.Province = churchSettings.Province;
     churchToSave.BackgroundImage = "default.png";
     churchToSave.StatusId = (int)ChurchStatuses.Pending;
 }
        private static void SetupPermissions(oikonomosEntities context, Person currentPerson, Church church, bool sysAdmin)
        {
            currentPerson.Permissions = (from pr in context.PersonChurches
                                  join r in context.Roles
                                    on pr.RoleId equals r.RoleId
                                  join permissions in context.PermissionRoles
                                    on r.RoleId equals permissions.RoleId
                                  where pr.PersonId == currentPerson.PersonId
                                    && r.ChurchId == church.ChurchId
                                  select permissions.PermissionId)
                                  .ToList();

            if (sysAdmin) currentPerson.Permissions.Add((int)Permissions.SystemAdministrator);
            var surname = currentPerson.Family.FamilyName;
            currentPerson.Church = church;
            currentPerson.ChurchId = church.ChurchId;
            var personChurch = currentPerson.PersonChurches.FirstOrDefault(pc => pc.ChurchId == currentPerson.ChurchId);
            Role role = null;
            if (personChurch != null)
            {
                role = context.Roles.First(r=>r.RoleId==personChurch.RoleId);
            }
            else if(currentPerson.HasPermission(Permissions.SystemAdministrator))
            {
                role = context.Roles.FirstOrDefault(r => r.ChurchId == church.ChurchId && r.Name.Contains("Administrator"));
                if(role==null)
                    throw new ApplicationException("Cannot set role for new church");
            }
            else
            {
                throw new ApplicationException("Cannot set role for new church");
            }
            currentPerson.RoleId = role.RoleId;
            currentPerson.Role = role;
            var churchIds = (from p in currentPerson.PersonChurches select p.ChurchId).ToList();
            currentPerson.Churches = context.Churches.Where(c => churchIds.Contains(c.ChurchId)).ToList();
        }
 private static void SendVisitorWelcome(bool includeUsername,
     string firstname,
     string surname,
     Church church,
     string email,
     Person personToSave)
 {
     string password = string.Empty;
     if (includeUsername)
     {
         personToSave.Username = (firstname + surname).Replace(" ", string.Empty);  //TODO replace with a boolean saying welcome letter has been sent
         password = RandomPasswordGenerator.Generate(RandomPasswordOptions.AlphaNumeric);
         personToSave.PasswordHash = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "sha1");
     }
     personToSave.PublicId = Email.SendWelcomeEmail(firstname,
           surname,
           church,
           email,
           password,
           personToSave.HasPermission(Permissions.SendVisitorWelcomeLetter),
           includeUsername);
 }
 private static void SendEmails(PersonViewModel person, bool sendWelcomeEmail, Church church, Person personToSave)
 {
     if (sendWelcomeEmail && person.PersonId == 0 && personToSave.HasPermission(Permissions.SendWelcomeLetter) && personToSave.HasValidEmail())
     {
         SendVisitorWelcome(sendWelcomeEmail,
             person.Firstname,
             person.Surname,
             church,
             person.Email,
             personToSave);
     }
     else if (sendWelcomeEmail && personToSave.HasValidEmail() && personToSave.HasPermission(Permissions.Login))
     {
         SendEmailAndPassword(person.Firstname,
             person.Surname,
             church,
             person.Email,
             personToSave);
     }
 }
        private static void GetPersonToSaveEntity(PersonViewModel person, Person currentPerson, oikonomosEntities context, out bool sendWelcomeEmail, out Church church, out Person personToSave)
        {
            sendWelcomeEmail = false;

            //We need some settings from the Church table
            church = (from c in context.Churches
                      where c.ChurchId == currentPerson.ChurchId
                      select c).FirstOrDefault();

            personToSave = new Person();
            if (person.PersonId != 0)
            {
                personToSave = FetchPerson(person.PersonId, context, 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();
                    if (family == null)
                    {
                        personToSave.Family = new Family();
                        personToSave.Family.Created = DateTime.Now;
                    }
                    else
                    {
                        personToSave.Family = family;
                    }
                }
                else
                {
                    personToSave.Family = new Family();
                    personToSave.Family.Created = DateTime.Now;
                }
            }
            else
            {
                personToSave.Family = (from f in context.Families
                                       where f.FamilyId == person.FamilyId
                                       select f).FirstOrDefault();

                if (personToSave.Family == null)
                {
                    personToSave.Family = new Family();
                    personToSave.Family.Created = DateTime.Now;
                }
            }

            personToSave.Firstname = person.Firstname;
            personToSave.Family.FamilyName = person.Surname;
            personToSave.Email = person.Email;
            personToSave.DateOfBirth = person.DateOfBirth_Value;
        }
        private static void EmailGroupLeader(PersonViewModel person, Person currentPerson, oikonomosEntities context, Church church, Person personToSave, bool addedToNewGroup)
        {
            if (personToSave.HasPermission(Permissions.NotifyGroupLeaderOfVisit) && person.GroupId > 0)
            {
                bool sendEmailToGroupLeader = person.PersonId == 0;
                var personGroup = (from pg in context.PersonGroups
                                   where pg.PersonId == personToSave.PersonId
                                   select pg).FirstOrDefault();

                if (personGroup == null)
                    return;
                else if (addedToNewGroup)
                    sendEmailToGroupLeader = true;

                if (personGroup.Group.LeaderId == currentPerson.PersonId || personGroup.Group.AdministratorId == currentPerson.PersonId)
                    sendEmailToGroupLeader = false;  //This is the groupleader

                if (sendEmailToGroupLeader)
                {
                    //Send email to the home group leader
                    var group = (from g in context.Groups
                                 where g.GroupId == person.GroupId
                                 select g).FirstOrDefault();

                    if (group != null)
                    {
                        if (group.Leader != null && group.Leader.HasValidEmail() && group.LeaderId != currentPerson.PersonId)
                        {
                            Email.SendNewVisitorEmail(person, church, group.Leader.Firstname, group.Leader.Family.FamilyName, group.Leader.Email);
                        }
                        else if (group.Administrator != null && group.Administrator.HasValidEmail() && group.LeaderId != currentPerson.PersonId)
                        {
                            Email.SendNewVisitorEmail(person, church, group.Administrator.Firstname, group.Administrator.Family.FamilyName, group.Administrator.Email);
                        }
                    }
                }
            }
        }
Exemple #42
0
        private static void SendNewVisitorEmailAsync(PersonViewModel person, 
            Church church,
            string firstname,
            string surname,
            string email)
        {
            try
            {
                using (MailMessage message = new MailMessage())
                {
                    message.Subject = "A new visitor to " + church.Name + " has been added to your homegroup";
                    message.Body = GetNewVisitorEmailBody(firstname,
                                           surname,
                                           church.Name,
                                           person);

                    message.To.Add(email);
                    message.IsBodyHtml = true;

                    SendEmail(message, church.EmailLogin, church.EmailPassword, church.Name);
                }
            }
            catch
            {
                // handle exception here
                // Need to look at some kind of logging
            }
        }
        public static void CreateNewChurch(Person currentPerson, ChurchSettingsViewModel churchSettings)
        {
            if (!currentPerson.HasPermission(Permissions.SystemAdministrator)) return;
            using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                var newChurch = new Church();
                context.AddToChurches(newChurch);
                newChurch.Created = DateTime.Now;

                PopulateChurchModel(churchSettings, newChurch);
                newChurch.EmailLogin = "******";
                newChurch.EmailPassword = "******";
                newChurch.Country = "South Africa";
                PopulateChurchAddress(churchSettings, context, newChurch);
                context.SaveChanges();

                //Save Roles
                var currentChurchRoles = context.Roles.Where(r => (r.ChurchId == currentPerson.ChurchId && r.Name != "System Administrator")).ToList();
                foreach (var currentRole in currentChurchRoles)
                {
                    var newChurchRole = new Role();
                    context.AddToRoles(newChurchRole);
                    newChurchRole.Created = DateTime.Now;
                    newChurchRole.Changed = DateTime.Now;
                    newChurchRole.Name = currentRole.Name;
                    newChurchRole.DisplayName = currentRole.DisplayName;
                    newChurchRole.ChurchId = newChurch.ChurchId;

                    foreach (var permission in currentRole.PermissionRoles)
                    {
                        var newRolePerm = new PermissionRole();
                        context.AddToPermissionRoles(newRolePerm);
                        newRolePerm.Created = DateTime.Now;
                        newRolePerm.Changed = DateTime.Now;
                        newRolePerm.PermissionId = permission.PermissionId;
                        newChurchRole.PermissionRoles.Add(newRolePerm);
                    }
                }

                context.SaveChanges();

                //Update Role that can be set by any role
                foreach (var currentRole in currentChurchRoles)
                {
                    var newRole = context.Roles.FirstOrDefault(r => (r.ChurchId == newChurch.ChurchId && r.Name == currentRole.Name));
                    foreach (var newRoleToSet in from roleToSet in currentRole.CanSetRoles where roleToSet.Name != "System Administrator" select context.Roles.FirstOrDefault(r => (r.ChurchId == newChurch.ChurchId && r.Name == roleToSet.Name)))
                    {
                        newRole.CanSetRoles.Add(newRoleToSet);
                    }
                }

                context.SaveChanges();

                var personAddress = new Address {Created = DateTime.Now, Changed = DateTime.Now, Line1 = string.Empty, Line2=string.Empty, Line3=string.Empty, Line4 = string.Empty};
                context.AddToAddresses(personAddress);

                var churchAdministrator              = new Person();
                context.AddToPeople(churchAdministrator);
                churchAdministrator.Created          = DateTime.Now;
                churchAdministrator.Changed          = DateTime.Now;
                churchAdministrator.Firstname        = churchSettings.ContactFirstname;
                churchAdministrator.Church           = newChurch;
                churchAdministrator.Email            = churchSettings.OfficeEmail;
                var churchAdministratorFamily        = new Family();
                context.AddToFamilies(churchAdministratorFamily);
                churchAdministratorFamily.FamilyName = churchSettings.ContactSurname;
                churchAdministratorFamily.Created    = DateTime.Now;
                churchAdministratorFamily.Changed    = DateTime.Now;
                churchAdministrator.Family           = churchAdministratorFamily;
                churchAdministrator.Family.Address   = personAddress;

                context.SaveChanges();

                //Set the new persons role to administrator
                var personChurchRecord = new PersonChurch
                    {
                        Person = churchAdministrator,
                        Church = newChurch,
                        Role = context.Roles.First(r => (r.ChurchId == newChurch.ChurchId && r.Name == "Church Administrator"))
                    };

                context.AddToPersonChurches(personChurchRecord);
                context.SaveChanges();

                //Update Church Optional Fields
                var churchOptionalFields = context.ChurchOptionalFields.Where(c=>c.ChurchId == currentPerson.ChurchId);
                foreach (var co in churchOptionalFields)
                {
                    var newCo = new ChurchOptionalField();
                    context.AddToChurchOptionalFields(newCo);
                    newCo.Created = DateTime.Now;
                    newCo.Changed = DateTime.Now;
                    newCo.ChurchId = newChurch.ChurchId;
                    newCo.OptionalFieldId = co.OptionalFieldId;
                    newCo.Visible = co.Visible;
                }

                context.SaveChanges();
            }
        }
Exemple #44
0
 public static void SendNewVisitorEmail(PersonViewModel person, Church church, string firstname, string surname, string email)
 {
     Task.Factory.StartNew(() => SendNewVisitorEmailAsync(person, church, firstname, surname, email));
 }