예제 #1
0
        public ActionResult AddMap(MapViewModel mapModel)
        {
            List<string> errors;
            if (Session["val"] != null)
            {
                errors = ((string[])Session["val"]).ToList();
            }
            else
            {
                errors = new List<string>();
            }

            MapDto _mapDto = new MapDto();

            _mapDto.Login = mapModel.viewModel.User_Login;
            _mapDto.Height = mapModel.viewModel.Height;
            _mapDto.Width = mapModel.viewModel.Width;

            if (_mapService.Add(_mapDto))
            {
                errors.Add("Dodano mapę.");
            }
            else
            {
                errors.Add("Błąd. Spróbuj ponownie.");
            }
            Session["val"] = errors.ToArray<string>();

            return RedirectToAction("Admin");
        }
예제 #2
0
        public ActionResult _UserMap()
        {
            _productService.UpdateUserProduct(User.Identity.Name);
            MapViewModel vm = new MapViewModel();
            vm.Map = _mapService.GetMap(User.Identity.Name);
            var ub = _buildingsHelper.GetBuildings(User.Identity.Name);
            List<UserBuildingsViewModel> ubv = new List<UserBuildingsViewModel>();

            foreach (var a in ub)
            {
                if (!a.Owner)
                {
                    continue;
                }
                var building = _buildingsHelper.GetBuildings().Where(b => b.ID == a.Building_ID).First();
                var bTime = 0;
                if(a.Status == "budowa" || a.Status == "rozbudowa")
                {
                    bTime = building.BuildingTime;
                }
                else if (a.Status == "burzenie")
                {
                    bTime = building.DestructionTime;
                }
                ubv.Add(new UserBuildingsViewModel {
                    id = a.ID,
                    BuildingID = a.Building_ID,
                    level = a.Lvl,
                    name = building.Name,
                    x_left = a.X_pos,
                    x_right = a.X_pos + building.Width - 1,
                    y_top = a.Y_pos,
                    y_bottom = a.Y_pos + building.Height - 1,
                    ID = a.ID,
                    Status = a.Status,
                    BuildTime = bTime,
                    BuildDone = bTime - _buildingsHelper.BuildingTimeLeft(User.Identity.Name, a.ID),
                    Alias = building.Alias,
                    Color = a.Color,
                    DestPrice = (int)building.Dest_price,
                    CanDelete = a.CanDelete
                });
            }
            vm.UserBuildings = ubv;
            var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            vm.UserProducts = serializer.Serialize(_buildingsHelper.AddProductValue(User.Identity.Name));
            var abc = _buildingsHelper.ProductNames(User.Identity.Name);
            var names = serializer.Serialize(abc);
            vm.ProductNames = names;
            var buildingsArray = new int[ub.Count][];
            int i = 0;
            foreach(var a in ubv)
            {
                var building = new int[4] { a.x_left, a.x_right, a.y_top, a.y_bottom };
                buildingsArray[i] = building;
                i++;
            }
            if(buildingsArray != null)
            vm.BuildingsArray = serializer.Serialize(buildingsArray);
            return View(vm);
        }
예제 #3
0
        public ActionResult _MapList(int? Page_No)
        {
            MapViewModel mapModel = new MapViewModel();

            mapModel.listModel = _mapService.GetMaps().Select(x => new ItemMapViewModel
            {
                ID = x.Map_ID,
                User_ID = x.User_ID,
                User_Login = x.Login,
                Height = x.Height,
                Width = x.Width
            }).ToList();

            mapModel.allUser = _userService.GetUser().Select(x => x.Login).ToArray();

            return View(mapModel);
        }