Exemplo n.º 1
0
        public JsonResult UpdateResourceAllocations(UpdateResourcesViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false }, JsonRequestBehavior.DenyGet));
            }

            var ts = new TerritoryService();

            ts.UpdateResourceAllocations(this.UserContext.TerritoryId.Value, vm.WaterAllocation, vm.WoodAllocation
                                         , vm.FoodAllocation, vm.StoneAllocation, vm.OilAllocation, vm.IronAllocation);
            try
            {
                ts.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(Json(new { success = true }, JsonRequestBehavior.DenyGet));
        }
Exemplo n.º 2
0
        // GET: Dashboard
        public ActionResult Index()
        {
            var vm   = new DashboardViewModel();
            var terr = this.UserContext.Territory;

            vm.TerritoryName   = terr.Name;
            vm.OutskirtsAppeal = "Good";

            vm.Resources.Add(new ResourceSkinny {
                Name       = "Water",
                Count      = this.UserContext.Items.Single(x => x.ItemId == (int)ResourceTypes.Water).Quantity,
                Allocation = terr.WaterAllocation
            });
            vm.Resources.Add(new ResourceSkinny
            {
                Name       = "Food",
                Count      = this.UserContext.Items.Single(x => x.ItemId == (int)ResourceTypes.Food).Quantity,
                Allocation = terr.FoodAllocation
            });
            vm.Resources.Add(new ResourceSkinny
            {
                Name       = "Wood",
                Count      = this.UserContext.Items.Single(x => x.ItemId == (int)ResourceTypes.Wood).Quantity,
                Allocation = terr.WoodAllocation
            });
            vm.Resources.Add(new ResourceSkinny
            {
                Name       = "Stone",
                Count      = this.UserContext.Items.Single(x => x.ItemId == (int)ResourceTypes.Stone).Quantity,
                Allocation = terr.StoneAllocation
            });
            vm.Resources.Add(new ResourceSkinny
            {
                Name       = "Oil",
                Count      = this.UserContext.Items.Single(x => x.ItemId == (int)ResourceTypes.Oil).Quantity,
                Allocation = terr.OilAllocation
            });
            vm.Resources.Add(new ResourceSkinny
            {
                Name       = "Iron",
                Count      = this.UserContext.Items.Single(x => x.ItemId == (int)ResourceTypes.Iron).Quantity,
                Allocation = terr.IronAllocation
            });

            vm.CivilianPopulation = terr.CivilianPopulation;
            vm.TerritoryType      = terr.Type;
            vm.TerritoryX         = terr.X;
            vm.TerritoryY         = terr.Y;

            vm.Neighbors = TerritoryService.GetNeighbors(this.UserContext.Territory)
                           .Select(x => new TerritorySkinny
            {
                Direction     = x.Key,
                TerritoryId   = x.Value.TerritoryId,
                TerritoryName = x.Value.Name,
            }).ToList();

            vm.RecentAttacks = this.Context.AttackLogs
                               .Where(x => x.UserId == this.UserContext.Id)
                               .OrderByDescending(x => x.TimeOfAttack)
                               .Take(3)
                               .Select(x => new AttackLogSkinny
            {
                Message      = x.Message,
                WasAttacked  = x.WasAttacked,
                TimeOfAttack = x.TimeOfAttack,
            })
                               .ToList();

            // setup motd
            var storageAccount = CloudStorageAccount.Parse(System.Configuration.ConfigurationManager
                                                           .ConnectionStrings["StorageConnectionString"].ConnectionString);
            var tableClient = storageAccount.CreateCloudTableClient();
            var table       = tableClient.GetTableReference("motd");

            table.CreateIfNotExists();

            var query = new TableQuery <MessageOfTheDayEntity>()
                        .Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "motd"));

            var motd = table.ExecuteQuery(query)
                       .OrderByDescending(x => x.Posted)
                       .FirstOrDefault();

            if (motd != null)
            {
                vm.MOTD = new Views.MOTD.Models.MOTDViewModel
                {
                    Author  = motd.Author,
                    Message = motd.Message,
                    Posted  = motd.Posted,
                };
            }

            var ts = new TechnologyService();

            vm.CurrentlyReasearching = ts.GetCheckPendingResearch(this.UserContext.Id);
            ts.SaveChanges();

            return(View(vm));
        }