Пример #1
0
        public ActionResult View(int id)
        {
            SolarSystem system = null;

            ViewBag.Factions = new List <Faction>();
            using (var session = DB.Instance.GetSession())
            {
                system = session
                         .Include <SolarSystem, SolarSystemGroup>(x => x.Groups)
                         .Load <SolarSystem>(id);

                if (system.Groups != null && system.Groups.Count > 0)
                {
                    system.GroupIncludes = session.Load <SolarSystemGroup>(system.Groups.Select(x => "SolarSystemGroups/" + x)).ToList();
                }

                if (CommanderSystemGroups.Count > 0 && !system.Groups.Any(g => CommanderSystemGroups.Contains(g)))
                {
                    return(new HttpUnauthorizedResult());
                }

                ViewBag.Factions = session.Query <Faction>().Where(x => x.SolarSystems.Any(s => s.Id == id)).ToList();
            }
            return(View(system));
        }
Пример #2
0
        public ActionResult Edit(int?id)
        {
            SolarSystem system = new SolarSystem();

            ViewBag.SourceFactions = new List <Faction>();
            using (var session = DB.Instance.GetSession())
            {
                var groups = session.Query <SolarSystemGroup>().OrderBy(x => x.Name).ToList();
                if (CommanderSystemGroups.Count > 0)
                {
                    groups.RemoveAll(x => !CommanderSystemGroups.Contains(x.Id));
                }
                ViewBag.SourceGroups = groups;

                if (id.HasValue)
                {
                    system = session.Load <SolarSystem>(id.Value);
                    ViewBag.SourceFactions = session.Query <Faction>().Where(x => x.SolarSystems.Any(s => s.Id == id.Value)).ToList();
                }
            }
            return(View(system));
        }
Пример #3
0
        // GET: Home
        public ActionResult Index()
        {
            var view = new HomeView();

            using (var session = DB.Instance.GetSession())
            {
                //Latest comments
                view.Comments = session.Advanced.DocumentQuery <Comment>()
                                .Include("DocumentId")
                                .OrderByDescending(x => x.Date)
                                .Take(12)
                                .ToList();
                foreach (var comment in view.Comments)
                {
                    comment.Entity = session.Load <ICommentable>(comment.DocumentId);
                }

                if (!User.IsAnyRole("user,administrator"))
                {
                    view.Comments.RemoveAll(x => x.Entity == null || x.Entity is Task);
                }

                if (CommanderSystemGroups.Count > 0)
                {
                    var remove = new List <Comment>();
                    foreach (var comment in view.Comments)
                    {
                        if (comment.Entity is SolarSystem && !((SolarSystem)comment.Entity).Groups.Any(g => CommanderSystemGroups.Contains(g)))
                        {
                            remove.Add(comment);
                        }
                    }
                    view.Comments.RemoveAll(x => remove.Contains(x));
                }

                //Systems
                view.SolarSystems = session.Query <SolarSystem>()
                                    .Where(x => x.ActiveCommanders.Any(c => c.Id == CommanderId))
                                    .OrderBy(x => x.Name)
                                    .ToList();

                //Tasks
                view.MyTasks = session.Query <Task>()
                               .Where(x => x.AssignedCommanders.Any(c => c.Id == CommanderId))
                               .OrderByDescending(x => x.Priority)
                               .ThenByDescending(x => x.Date)
                               .ToList();
                view.NewTasks = session.Query <Task>()
                                .Where(x => x.Date >= DateTime.UtcNow.AddDays(-7) && x.Status != TaskStatus.Completed)
                                .OrderByDescending(x => x.Priority)
                                .ThenByDescending(x => x.Date)
                                .ToList()
                                .Except(view.MyTasks)
                                .ToList();
            }
            return(View(view));
        }
Пример #4
0
        public ActionResult Edit(int?id, SolarSystem input)
        {
            using (var session = DB.Instance.GetSession())
            {
                //Check if exists
                if (!id.HasValue)
                {
                    var existing = session.Query <SolarSystem>()
                                   .Where(x => x.Name == input.Name).ToList()
                                   .FirstOrDefault(x => x.Name.Equals(input.Name, StringComparison.CurrentCultureIgnoreCase));
                    if (existing != null)
                    {
                        return(RedirectToAction("Edit", new { status = "Solar system already exists" }));
                    }
                }

                //Group validation
                if (CommanderSystemGroups.Count > 0 && (input.Groups.Count == 0 || input.Groups.All(x => x == 0)))
                {
                    return(RedirectToAction("Edit", new { status = "You must select a group" }));
                }

                if (!id.HasValue)
                {
                    input.Updated = DateTime.UtcNow;
                    if (input.Groups.All(x => x == 0))
                    {
                        input.Groups = null;
                    }
                    session.Store(input);
                    session.SaveChanges();
                }
                else
                {
                    var system = session.Load <SolarSystem>(id);
                    system.Updated           = DateTime.UtcNow;
                    system.Name              = input.Name;
                    system.PopulationPrev    = system.Population;
                    system.Population        = input.Population;
                    system.SecurityPrev      = system.Security;
                    system.Security          = input.Security;
                    system.PowerPlayLeader   = input.PowerPlayLeader;
                    system.PowerPlayState    = input.PowerPlayState;
                    system.SyncFactionStatus = input.SyncFactionStatus;
                    if (system.Coordinates == null)
                    {
                        system.Coordinates = new Coordinate();
                    }
                    if (input.Groups.Count == 0 || input.Groups.All(x => x == 0))
                    {
                        input.Groups = null;
                    }
                    else
                    {
                        if (CommanderSystemGroups.Count > 0 && system.Groups != null && system.Groups.Count > 0)
                        {
                            //Remove groups this user might have changed, keep others
                            system.Groups.RemoveAll(x => CommanderSystemGroups.Contains(x));
                            //Add groups added by user
                            system.Groups.AddRange(input.Groups);
                        }
                        else
                        {
                            system.Groups = input.Groups;
                        }
                    }
                    system.Coordinates.X = input.Coordinates.X;
                    system.Coordinates.Y = input.Coordinates.Y;
                    system.Coordinates.Z = input.Coordinates.Z;
                    session.SaveChanges();
                }
            }

            if (id.HasValue)
            {
                return(RedirectToAction("View", "SolarSystem", new { id = id.Value }));
            }
            return(RedirectToAction("Edit", "SolarSystem", new { id = input.Id }));
        }
Пример #5
0
        public ActionResult Index(int?page, SolarSystemIndexView.Form form)
        {
            page = page ?? 0;
            var view = new SolarSystemIndexView();

            using (var session = DB.Instance.GetSession())
            {
                //Query
                RavenQueryStatistics stats = null;
                var query = session.Query <SolarSystem_Query.Result, SolarSystem_Query>()
                            .Statistics(out stats)
                            .OrderBy(x => x.Name)
                            .Skip(page.Value * 35)
                            .Take(35);
                if (!String.IsNullOrEmpty(form.Query))
                {
                    query = query.Where(x => x.NamePartial == form.Query);
                }
                if (form.Economy != 0)
                {
                    var enumEconomy = (StationEconomy)Enum.Parse(typeof(StationEconomy), form.Economy.ToString());
                    query = query.Where(x => x.Economies.Any(e => e == enumEconomy));
                }
                if (form.Supply != 0)
                {
                    var enumSupply = (CommodityType)Enum.Parse(typeof(CommodityType), form.Supply.ToString());
                    query = query.Where(x => x.Supply.Any(s => s == enumSupply));
                }
                if (form.Demand != 0)
                {
                    var enumDemand = (CommodityType)Enum.Parse(typeof(CommodityType), form.Demand.ToString());
                    query = query.Where(x => x.Demand.Any(s => s == enumDemand));
                }
                if (form.PowerPlayLeader != 0)
                {
                    var enumLeader = (PowerPlayLeader)Enum.Parse(typeof(PowerPlayLeader), form.PowerPlayLeader.ToString());
                    query = query.Where(x => x.PowerPlayLeader == enumLeader);
                }
                if (form.PowerPlayState != 0)
                {
                    var enumState = (PowerPlayState)Enum.Parse(typeof(PowerPlayState), form.PowerPlayState.ToString());
                    query = query.Where(x => x.PowerPlayState == enumState);
                }
                if (form.Outfitting != 0)
                {
                    var enumOutfitting = (StationOutfitting)Enum.Parse(typeof(StationOutfitting), form.Outfitting.ToString());
                    query = query.Where(x => x.Outfitting.Any(s => s == enumOutfitting));
                }
                if (form.FactionId != 0)
                {
                    query = query.Where(x => x.Factions.Any(f => f == form.FactionId));
                }
                if (form.Group != 0)
                {
                    query = query.Where(x => x.Groups.Any(g => g == form.Group));
                }
                else if (CommanderSystemGroups.Count > 0)
                {
                    query = query.Where(x => x.Groups.In(CommanderSystemGroups));
                }

                switch (form.Status)
                {
                case 1:
                    query = query.Where(x => x.Attitude == FactionAttitude.Ally);
                    break;

                case 2:
                    query = query.Where(x => x.Attitude == FactionAttitude.Hostile);
                    break;

                case 3:
                    query = query.Where(x => x.Attitude != FactionAttitude.Hostile);
                    break;

                case 4:
                    query = query.Where(x => x.Attitude == FactionAttitude.Hostile && x.HasAlly);
                    break;
                }

                //Set up view
                view.SolarSystems = query.OfType <SolarSystem>().ToList();
                view.Query        = form;
                view.Pager        = new Pager
                {
                    Count    = stats.TotalResults,
                    Page     = page.Value,
                    PageSize = 35
                };

                //Select list item
                view.Statuses = new List <SelectListItem>
                {
                    new SelectListItem {
                        Text = "All statuses", Value = "0", Selected = form.Status == 0
                    },
                    new SelectListItem {
                        Text = "Allied", Value = "1", Selected = form.Status == 1
                    },
                    new SelectListItem {
                        Text = "Hostile", Value = "2", Selected = form.Status == 2
                    },
                    new SelectListItem {
                        Text = "Not hostile", Value = "3", Selected = form.Status == 3
                    },
                    new SelectListItem {
                        Text = "Allied faction not in control", Value = "4", Selected = form.Status == 4
                    }
                };

                //Groups
                var groups = session.Query <SolarSystemGroup>().OrderBy(x => x.Name).ToList();
                if (CommanderSystemGroups.Count > 0)
                {
                    groups.RemoveAll(x => !CommanderSystemGroups.Contains(x.Id));
                }
                groups.Insert(0, new SolarSystemGroup {
                    Id = 0, Name = "All"
                });
                view.Groups = new SelectList(groups, "Id", "Name", form.Group);

                return(View(view));
            }
        }