示例#1
0
文件: MapService.cs 项目: kamlys/Game
        public bool Add(MapDto map)
        {
            if (!_maps.GetAll().Any(i => i.Users.Login == map.Login) && map.Width >= 0 && map.Height >= 0)
            {
                _maps.Add(new Maps
                {
                    User_ID = _users.GetAll().First(i => i.Login == map.Login).ID,
                    Height = map.Height,
                    Width = map.Width
                });

                _unitOfWork.Commit();
                return true;
            }
            return false;
        }
示例#2
0
文件: MapService.cs 项目: kamlys/Game
        public bool Update(MapDto map)
        {
            if (map.Width >= 0 && map.Height >= 0)
            {
                foreach (var item in _maps.GetAll().Where(i => i.Map_ID == map.Map_ID))
                {
                    item.User_ID = _users.GetAll().First(i => i.Login == map.Login).ID;
                    item.Height = map.Height;
                    item.Width = map.Width;
                }

                _unitOfWork.Commit();
                return true;
            }
            return false;
        }
示例#3
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");
        }