Exemplo n.º 1
0
        public ActionResult Settings()
        {
            Person currentPerson = SecurityHelper.CheckCurrentUser(Session, Response, ViewBag);
            if (currentPerson == null)
            {
                return View("Login");
            }

            SettingsViewModel settings = new SettingsViewModel();
            ViewBag.GroupId = 0;
            if(currentPerson.HasPermission(common.Permissions.EditSettings))
            {
                settings = SettingsDataAccessor.FetchSettings(currentPerson);
                if (settings.GroupSettings != null)
                {
                    ViewBag.GroupId = settings.GroupSettings.GroupId;
                    ViewBag.GroupName = settings.GroupSettings.GroupName;
                }
            }
            return View(settings);
        }
Exemplo n.º 2
0
        public static SettingsViewModel FetchSettings(Person currentPerson)
        {
            using (oikonomosEntities context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                SettingsViewModel settings = new SettingsViewModel();
                settings.ChurchSettings = (from c in context.Churches
                                           where c.ChurchId == currentPerson.ChurchId
                                           select new ChurchSettingsViewModel
                                           {
                                               ChurchName = c.Name,
                                               OfficeEmail = c.OfficeEmail,
                                               OfficePhone = c.OfficePhone,
                                               SystemName = c.SiteHeader,
                                               UITheme = c.UITheme,
                                               Url = c.Url,
                                               AddressId = c.AddressId.HasValue ? c.AddressId.Value : 0,
                                               Address1 = c.Address.Line1,
                                               Address2 = c.Address.Line2,
                                               Address3 = c.Address.Line3,
                                               Address4 = c.Address.Line4,
                                               Lat = c.Address == null ? 0 : c.Address.Lat,
                                               Lng = c.Address == null ? 0 : c.Address.Long,
                                               AddressType = c.Address.AddressType,
                                               Province = c.Province,
                                               BulkSmsUsername = (from smsProv in c.ChurchSmsProviders where smsProv.SmsProviderId == (int)SmsProviders.BulkSmsSouthAfrica select smsProv.Username).FirstOrDefault(),
                                               BulkSmsPassword = (from smsProv in c.ChurchSmsProviders where smsProv.SmsProviderId == (int)SmsProviders.BulkSmsSouthAfrica select smsProv.Password).FirstOrDefault()
                                           }).FirstOrDefault();

                settings.GroupSettings = (from g in context.Groups
                                          where g.LeaderId == currentPerson.PersonId
                                          || g.AdministratorId == currentPerson.PersonId
                                          select new GroupDto
                                          {
                                              GroupId = g.GroupId,
                                              GroupName = g.Name,
                                              AddressId = g.AddressId.HasValue ? g.AddressId.Value : 0,
                                              Address1 = g.Address.Line1,
                                              Address2 = g.Address.Line2,
                                              Address3 = g.Address.Line3,
                                              Address4 = g.Address.Line4,
                                              AddressType = g.Address.AddressType
                                          }).FirstOrDefault();

                settings.OptionalFields = (from c in context.OptionalFields
                                           join cc in context.ChurchOptionalFields
                                           on c.OptionalFieldId equals cc.OptionalFieldId into churchOptionalFields
                                           from cc in churchOptionalFields.DefaultIfEmpty()
                                           where (cc.ChurchId == currentPerson.ChurchId || cc.ChurchId == null)
                                           select new OptionalFieldViewModel
                                           {
                                               ChurchOptionalFieldId = cc.ChurchOptionalFieldId == null ? 0 : cc.ChurchOptionalFieldId,
                                               OptionalFieldId = c.OptionalFieldId,
                                               Name = c.Name,
                                               Regex = c.Regex == null ? string.Empty : c.Regex,
                                               Display = cc.Visible == null ? true : cc.Visible
                                           }).ToList();

                settings.Sites = (from s in context.Sites
                                  where s.ChurchId == currentPerson.ChurchId
                                  select new SiteSettingsViewModel
                                  {
                                      Address1 = s.Address.Line1,
                                      Address2 = s.Address.Line2,
                                      Address3 = s.Address.Line3,
                                      Address4 = s.Address.Line4,
                                      Lat = s.Address == null ? 0 : s.Address.Lat,
                                      Lng = s.Address == null ? 0 : s.Address.Long,
                                      AddressId = s.AddressId.HasValue ? s.AddressId.Value : 0,
                                      AddressType = s.Address.AddressType,
                                      SiteId = s.SiteId,
                                      SiteName = s.Name
                                  }).ToList();

                settings.Roles = (from r in context.Roles
                                  where r.ChurchId == currentPerson.ChurchId
                                  select new RoleViewModel
                                  {
                                      RoleId = r.RoleId,
                                      Name = r.Name
                                  }).ToList();

                settings.RoleId = settings.Roles[0].RoleId;

                return settings;
            }
        }