示例#1
0
        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="id">mission geography id</param>
        ///// <returns></returns>
        //public ActionResult MissionsNear(Guid id)
        //{
        //    MapDataRequests model = new MapDataRequests { Modes = MapModes.MissionDetails, Zoom = 11 };
        //    using (var ctx = GetContext())
        //    {
        //        var center = (from g in ctx.MissionGeography where g.Id == id select g).First().Geography;
        //        model.CenterLat = center.Lat.Value;
        //        model.CenterLong = center.Long.Value;

        //        model.Missions.AddRange(ctx.MissionsNearGeographyId(id, 2).Select(f => f.Value).AsEnumerable());
        //    }

        //    return BuildView("Related Missions", model);
        //}

        public ActionResult Index(Guid?mission)
        {
            var center = GeographyServices.GetDefaultLocation();

            MapDataRequests model = new MapDataRequests {
                CenterLat = center.Lat.Value, CenterLong = center.Long.Value, Zoom = 9
            };

            if (mission.HasValue)
            {
                model.Modes = MapModes.MissionDetails;
                model.Missions.Add(mission.Value);
            }
            else
            {
                model.Modes |= MapModes.MissionBrowser;
                model.Title  = "Mission History";
            }

            if (User.IsInRole("cdb.users"))
            {
                model.Title       = "";
                model.Modes      |= MapModes.MemberHouses;
                ViewData["units"] = UnitsController.GetUnitSelectList(this.db, null);
            }

            return(BuildView("Map", model));
        }
        public ActionResult FixupUnitMemberGroups(string id, string group, bool?commit)
        {
            if (!Permissions.IsUserOrLocal(Request))
            {
                Response.StatusCode = 403;
                return(CreateLoginRedirect());
            }
            string result = "";

            SarUnit unit = UnitsController.ResolveUnit(this.db.Units, id);

            if (string.IsNullOrEmpty(group))
            {
                group = UnitNameAsGroupName(unit.DisplayName) + ".members";
            }

            var unitMembers = (from m in this.db.UnitMemberships
                               where m.Unit.Id == unit.Id && m.EndTime == null && m.Status.GetsAccount
                               select m.Person).OrderBy(f => f.LastName).ThenBy(f => f.FirstName).Distinct().ToArray();

            var usersInGroup = Roles.GetUsersInRole(group).ToList();

            foreach (var member in unitMembers)
            {
                if (usersInGroup.Contains(member.Username))
                {
                    result += string.Format("{0} in group as {1}<br/>", member.FullName, member.Username);
                    usersInGroup.Remove(member.Username);
                }
                else
                {
                    result += string.Format("## {0} not in group. Should add {1}<br/>", member.FullName, member.Username);
                }
            }

            foreach (string username in usersInGroup)
            {
                result += string.Format("## suggest remove {0}<br/>", username);
            }

            //if (commit.HasValue && commit.Value)
            //{
            //        if (usersToAdd.Count > 0)
            //        {
            //            Roles.AddUsersToRole(usersToAdd.ToArray(), group);
            //        }

            //        if (usersToRemove.Count > 0)
            //        {
            //            Roles.RemoveUsersFromRole(usersToRemove.ToArray(), group);
            //        }
            //    }
            //}

            return(new ContentResult {
                ContentType = "text/html", Content = "Done.\n" + result
            });
        }
示例#3
0
        public DataActionResult GetMemberEmails(string id)
        {
            if (!Permissions.IsUser)
            {
                return(GetLoginError());
            }

            return(Data(UnitsController.GetMemberEmails(this.db, id)));
        }
        public ActionResult ReconcileActiveOnlyGroup(string group, string unit, string[] keep, bool?doit)
        {
            string msgs = string.Empty;

            doit = doit ?? false;

            //SarUnit withUnit = string.IsNullOrWhiteSpace(unit) ? null : UnitsController.ResolveUnit(ctx.Units, unit);

            var query = (from m in this.db.UnitMemberships where m.Status.IsActive && m.EndTime == null select m);

            if (!string.IsNullOrWhiteSpace(unit))
            {
                Guid unitId = UnitsController.ResolveUnit(this.db.Units, unit).Id;
                query = query.Where(f => f.Unit.Id == unitId);
            }
            List <string> desiredUsers  = query.Select(f => f.Person.Username ?? ("*" + f.Person.FirstName + " " + f.Person.LastName)).ToList();
            List <string> usersToRemove = new List <string>();
            List <string> forceKeep     = new List <string>();

            foreach (string user in Roles.GetUsersInRole(group))
            {
                if (desiredUsers.Contains(user))
                {
                    desiredUsers.Remove(user);
                }
                else if (keep != null && keep.Contains(user))
                {
                    forceKeep.Add(user);
                }
                else
                {
                    usersToRemove.Add(user);
                }
            }
            if (desiredUsers.Count > 1)
            {
                msgs += string.Join("\n", desiredUsers.Where(f => f[0] != '*').Select(f => "add " + f).ToArray());
                msgs += string.Join("\n", desiredUsers.Where(f => f[0] == '*').Select(f => "No username for active member " + f.Substring(1)).ToArray());
                if (doit.Value && desiredUsers.Count(f => f[0] != '*') > 0)
                {
                    Roles.AddUsersToRole(desiredUsers.Where(f => f[0] != '*').ToArray(), group);
                }
            }
            msgs += string.Join("\n", forceKeep.Select(f => "keeping " + f).ToArray());
            if (usersToRemove.Count > 1)
            {
                msgs += string.Join("\n", usersToRemove.Select(f => "remove " + f).ToArray());
                if (doit.Value)
                {
                    Roles.RemoveUsersFromRole(usersToRemove.ToArray(), group);
                }
            }
            return(new ContentResult {
                Content = msgs, ContentType = "text/plain"
            });
        }
示例#5
0
        public static MemberDetailView[] GetMemberEmails(IKcsarContext ctx, string id)
        {
            Guid unitId = UnitsController.ResolveUnit(ctx.Units, id).Id;

            Member[]           members = (from m in ctx.GetActiveMembers(unitId, DateTime.Now, "ContactNumbers", "Memberships.Unit", "Memberships.Status") select m).ToArray();
            MemberDetailView[] model   = members
                                         .Where(f => f.Memberships.Any(g => g.Unit.Id == unitId && g.Status.IsActive && g.Status.StatusName != "trainee") &&
                                                f.ContactNumbers.Count(g => g.Type == "email") > 0)
                                         .Select(m =>
                                                 new MemberDetailView
            {
                Id        = m.Id,
                FirstName = m.FirstName,
                LastName  = m.LastName,
                Contacts  = m.ContactNumbers.Where(f => f.Type == "email").Select(f => new MemberContactView {
                    Id = f.Id, Priority = f.Priority, Value = f.Value
                }).OrderBy(f => f.Priority).ToArray(),
                Units = m.Memberships.Where(f => f.Status.IsActive && (f.EndTime == null || f.EndTime > DateTime.Now)).Select(f => f.Unit.DisplayName).ToArray()
            })
                                         .ToArray();

            return(model);
        }