Esempio n. 1
0
        public bool IsAddGameValid(AddGameBindingModel model)
        {
            if (model.Title.Length < 3 || model.Title.Length > 100 || !char.IsUpper(model.Title[0]))
            {
                return(false);
            }

            if (model.Price <= 0)
            {
                return(false);
            }

            if (model.Size <= 0)
            {
                return(false);
            }

            if (!model.VideoUrl.StartsWith("is https://www.youtube.com/watch?v="))
            {
                return(false);
            }
            if (!model.Thumbnail.StartsWith("http://"))
            {
                return(false);
            }

            if (model.Description.Length < 20)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
        public void Add(HttpResponse response, HttpSession session, AddGameBindingModel model)
        {
            if (!AuthenticationManager.IsAuthenticated(session.Id))
            {
                this.Redirect(response, "/users/register");
                return;
            }

            User activeUser = AuthenticationManager.GetAuthenticatedUser(session.Id);

            if (!activeUser.IsAdmin)
            {
                this.Redirect(response, "/home/index");
                return;
            }

            if (!this.service.IsAddGameValid(model))
            {
                this.Redirect(response, "/categories/add");
                return;
            }

            this.service.AddNewGame(model);
            this.Redirect(response, "/categories/all");
        }
        public void AddGame(AddGameBindingModel agbm)
        {
            var game = Mapper.Map <AddGameBindingModel, Game>(agbm);

            this.data.Games.InsertOrUpdate(game);
            this.data.SaveChanges();
        }
Esempio n. 4
0
        public bool IsAddGameViewModelValid(AddGameBindingModel bind)
        {
            if (bind.Title.Length > 100 && bind.Title.Length < 3)
            {
                return(false);
            }

            if (bind.Price < 0)
            {
                return(false);
            }

            if (bind.Size < 0)
            {
                return(false);
            }

            if (bind.Title.Length != 11)
            {
                return(false);
            }

            if (bind.Description.Length < 20)
            {
                return(false);
            }

            //if (bind.Thumbnail.StartsWith("http://"))
            //{
            //    return false;
            //}
            return(true);
        }
Esempio n. 5
0
        public bool VerifyAddGame(AddGameBindingModel bm)
        {
            if (!char.IsUpper(bm.Title[0]) || bm.Title.Length < 3 || bm.Title.Length > 100)
            {
                return(false);
            }
            if (bm.Price < 0 || bm.Size < 0)
            {
                return(false);
            }

            string trailerId = bm.Trailer.Substring(bm.Trailer.Length - 11);

            if (trailerId.Length != 11)
            {
                return(false);
            }
            if (!bm.Thumbnail.StartsWith("http://") && !bm.Thumbnail.StartsWith("https://"))
            {
                return(false);;
            }
            if (bm.Description.Length < 20)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 6
0
 public bool IsAddGameModelValid(AddGameBindingModel agbm)
 {
     if (!char.IsUpper(agbm.Title[0]) || (agbm.Title.Length < 3 && agbm.Title.Length > 100))
     {
         return(false);
     }
     if (agbm.Price <= 0)
     {
         return(false);
     }
     if (agbm.Size <= 0)
     {
         return(false);
     }
     if (agbm.Trailer.Length < 11)
     {
         return(false);
     }
     if (!agbm.ImageThumbnail.StartsWith("http://") && !agbm.ImageThumbnail.StartsWith("https://"))
     {
         return(false);
     }
     if (agbm.Description.Length < 20)
     {
         return(false);
     }
     return(true);
 }
Esempio n. 7
0
        public bool IsValidGame(AddGameBindingModel model)
        {
            if (!char.IsUpper(model.Title[0]) || model.Title.Length < 3 || model.Title.Length > 100)
            {
                return(false);
            }

            if (model.Price < 0.0m)
            {
                return(false);
            }

            if (model.Size < 0.0m)
            {
                return(false);
            }

            if (model.YouTubeId.Length != 11)
            {
                return(false);
            }

            if (model.Description.Length < 20)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 8
0
        public AddGameBindingModel GetAllBrandsAndGameTypes()
        {
            var brands = this.DbContext
                         .Brands
                         .Select(this.Mapper.Map <BrandConciseViewModel>)
                         .ToList();

            var gameTypes = this.DbContext
                            .GameTypes
                            .Select(this.Mapper.Map <GameTypeViewModel>)
                            .ToList();

            var brandsQuery = brands.Select(b => new SelectListItem()
            {
                Text = b.BrandName, Value = b.Id.ToString()
            });
            var gameTypesQuery = gameTypes.Select(b => new SelectListItem()
            {
                Text = b.GameTypeName, Value = b.Id.ToString()
            });

            var model = new AddGameBindingModel()
            {
                AllBrands    = brandsQuery.ToList(),
                AllGameTypes = gameTypesQuery.ToList()
            };

            return(model);
        }
Esempio n. 9
0
        public IActionResult Add(HttpSession session, HttpResponse response, AddGameBindingModel bm)
        {
            if (!this.service.VerifyAddGame(bm))
            {
                return(this.View());
            }
            this.service.AddGame(bm);

            Redirect(response, "/admin/games");
            return(null);
        }
Esempio n. 10
0
 public Game GetGameFromAddGameBind(AddGameBindingModel bind)
 {
     return(new Game()
     {
         Description = bind.Description,
         ImageThumbnail = bind.Thumbnail,
         Price = bind.Price,
         ReleaseDate = bind.ReleaseDate,
         Size = bind.Size,
         Title = bind.Title,
         Trailer = bind.Trailer,
     });
 }
Esempio n. 11
0
        public void AddNewGame(AddGameBindingModel model)
        {
            this.Context.Games.Add(new Game()
            {
                Description    = model.Description,
                ImageThumbnail = model.Thumbnail,
                Price          = model.Price,
                Size           = model.Size,
                Title          = model.Title,
                ReleaseDate    = model.ReleaseDate,
                VideoUrl       = model.VideoUrl.Substring(32, 11)
            });

            this.Context.SaveChanges();
        }
Esempio n. 12
0
        public void AddGame(AddGameBindingModel model)
        {
            this.uow.Games.Add(new Game
            {
                Description    = model.Description,
                ImageThumbnail = model.Thumbnail,
                Price          = model.Price,
                ReleaseDate    = model.ReleaseDate,
                Size           = model.Size,
                Title          = model.Title,
                Trailer        = model.YouTubeId
            });

            this.uow.SaveChanges();
        }
Esempio n. 13
0
        public IActionResult Add(AddGameBindingModel model, HttpResponse response, HttpSession session)
        {
            if (autenticator.HasLoggedInUser(session))
            {
                if (autenticator.IsLoggedUserAdmin(session))
                {
                    if (service.IsValidGame(model))
                    {
                        this.service.AddGame(model);
                        this.Redirect(response, "/manager/all");
                    }
                }
            }

            return(null);
        }
Esempio n. 14
0
        public void AddGame(AddGameBindingModel bm)
        {
            Game game = new Game()
            {
                Description    = bm.Description,
                ImageThumbnail = bm.Thumbnail,
                Price          = bm.Price,
                ReleaseDate    = bm.Releasedate,
                Size           = bm.Size,
                Title          = bm.Title,
                Trailer        = bm.Trailer.Substring(bm.Trailer.Length - 11)
            };

            this.data.Games.Add(game);
            this.data.Save();
        }
Esempio n. 15
0
 public IActionResult Add(HttpSession session, HttpResponse response, AddGameBindingModel agbm)
 {
     if (!this.service.AuthenticateUser(session))
     {
         this.Redirect(response, "/home/index");
         return(null);
     }
     if (this.service.VerifyGame(agbm))
     {
         this.service.AddGame(agbm);
         this.Redirect(response, "/games/all");
         return(null);
     }
     this.Redirect(response, "/games/add");
     return(null);
 }
Esempio n. 16
0
        public void Add(AddGameBindingModel model)
        {
            this.CheckIfNull(model);

            var game = new Game()
            {
                ImageUrl    = model.Thumbnail,
                Description = model.Description,
                Size        = model.Size,
                Price       = model.Price,
                ReleaseDate = model.ReleaseDate,
                Title       = model.Title,
                Trailer     = model.VideoUrl
            };

            this.Data.Games.Add(game);
            this.Data.SaveChanges();
        }
Esempio n. 17
0
        public IActionResult Newgame(AddGameBindingModel agbm, HttpResponse response, HttpSession session)
        {
            if (!IsAuthenticatedAsAdmin(session))
            {
                Redirect(response, "/home/homepage");
                return(null);
            }
            if (!service.IsAddGameModelValid(agbm))
            {
                Redirect(response, "/admin/newgame");
                return(null);
            }
            Game game = service.GetGameFromAddGameModel(agbm);

            service.AddGame(game);
            Redirect(response, "/admin/admingames");
            return(null);
        }
        public ActionResult Add(AddGameBindingModel model)
        {
            if (model == null || !this.ModelState.IsValid)
            {
                return this.View("Error");
            }

            var loggedUserId = this.User.Identity.GetUserId();

            var newGame = new Game
            {
                Title = model.Title,
                Description = model.Description,
                SystemRequirements = model.SystemRequirements,
                AuthorId = loggedUserId,
                GenreId = model.Genre
            };

            this.Data.Games.Add(newGame);

            foreach (var url in model.Urls)
            {
                Uri imagePath;
                if (Uri.TryCreate(url, UriKind.Absolute, out imagePath))
                {
                    var newImage = new Image
                    {
                        Url = url,
                        GameId = newGame.Id
                    };

                    newGame.Images.Add(newImage);
                    this.Data.Images.Add(newImage);
                }
                else
                {
                    return this.View("Error");
                }
            }

            this.Data.SaveChanges();

            return this.RedirectToAction("Details", "Games", new {gameTitle = newGame.Title});
        }
Esempio n. 19
0
        internal void AddGame(AddGameBindingModel bindingModel)
        {
            Game game = new Game()
            {
                Title = bindingModel.Title
                        .Substring(0, 1)
                        .ToUpper() + bindingModel.Title
                        .Substring(1, bindingModel.Title.Length - 1),
                Description    = bindingModel.Description,
                ImageThumbnail = bindingModel.ImageThumbnail,
                Trailer        = bindingModel.Trailer,
                Price          = bindingModel.Price,
                Size           = bindingModel.Size,
                ReleaseDate    = bindingModel.ReleaseDate
            };

            this.context.Games.Add(game);
            this.context.SaveChanges();
        }
Esempio n. 20
0
        public IActionResult Add(HttpResponse response, HttpSession session, AddGameBindingModel bind)
        {
            if (!AuthenticatedManager.IsAdmin(session.Id))
            {
                this.Redirect(response, "/user/login");
            }
            //validations for adding a game
            if (!this.service.IsAddGameViewModelValid(bind))
            {
                this.Redirect(response, "/game/add");
                return(null);
            }
            //add game to database
            Game game = this.service.GetGameFromAddGameBind(bind);

            this.service.AddGame(game);
            this.Redirect(response, "/game/managing");
            return(this.View());
        }
Esempio n. 21
0
        public async Task <IActionResult> AddGame(AddGameBindingModel model)
        {
            if (!this.ModelState.IsValid)
            {
                SetErrorMessage(CommonConstants.DangerMessage);

                return(this.AddGame());
            }

            int generatedId = await this.gameService.AddGameAsync(model);

            if (generatedId < 1)
            {
                SetErrorMessage(CommonConstants.DuplicateMessage);

                return(this.AddGame());
            }

            SetSuccessMessage(string.Format(CommonConstants.SuccessMessage, CommonConstants.GameSuffix));

            return(Redirect(string.Format(RedirectConstants.AdministratorAreaGameDetailsPage, generatedId)));
        }
Esempio n. 22
0
        public async Task <int> AddGameAsync(AddGameBindingModel model)
        {
            var checkForDuplicate = this.DbContext
                                    .Games
                                    .FirstOrDefault(x => x.GameName == model.GameName);

            if (checkForDuplicate != null)
            {
                return(ErrorId);
            }

            var game = this.Mapper.Map <Game>(model);

            var gameType = this.DbContext
                           .GameTypes
                           .FirstOrDefault(x => x.Id == model.GameTypeId);

            var brand = this.DbContext
                        .Brands
                        .FirstOrDefault(x => x.Id == model.BrandId);

            game.GameTypeId = gameType.Id;
            game.GameType   = gameType;

            game.BrandId = brand.Id;
            game.Brand   = brand;

            if (game.HighLightVideoURL.Contains(CommonConstants.OriginalVideoUrlPart))
            {
                game.HighLightVideoURL = ModifyVideoURL_Embeded.ModifyEmbed(game.HighLightVideoURL);
            }

            await this.DbContext.Games.AddAsync(game);

            await this.DbContext.SaveChangesAsync();

            return(game.Id);
        }
Esempio n. 23
0
        public IActionResult Add(AddGameBindingModel bindingModel, HttpSession session, HttpResponse response)
        {
            if (!this.loginManager.IsAuthenticated(session))
            {
                this.Redirect(response, "/home/login");
                return(null);
            }

            if (!this.loginManager.IfUserIsAdmin(session))
            {
                this.Redirect(response, "/home/index");
                return(null);
            }

            if (!this.adminService.IsValidAdd(bindingModel))
            {
                this.Redirect(response, "/admin/add");
                return(null);
            }

            this.adminService.AddGame(bindingModel);
            this.Redirect(response, "/admin/games");
            return(null);
        }
Esempio n. 24
0
        internal bool IsValidAdd(AddGameBindingModel bindingModel)
        {
            if (string.IsNullOrEmpty(bindingModel.Title) ||
                string.IsNullOrEmpty(bindingModel.Description) ||
                string.IsNullOrEmpty(bindingModel.ImageThumbnail) ||
                string.IsNullOrEmpty(bindingModel.Trailer) ||
                bindingModel.ReleaseDate == null ||
                bindingModel.Size < 0 || bindingModel.Price < 0)
            {
                return(false);
            }

            if (bindingModel.Title.Length < 3 ||
                bindingModel.Title.Length > 100)
            {
                return(false);
            }

            if (bindingModel.Trailer.Length != 11 ||
                bindingModel.Description.Length < 20)
            {
                return(false);
            }

            if (bindingModel.ImageThumbnail.Substring(0, 7) == "http://" ||
                bindingModel.ImageThumbnail.Substring(0, 8) == "https://")
            {
                return(true);
            }
            else
            {
                return(false);
            }

            return(true);
        }
 public bool VerifyGame(AddGameBindingModel agbm)
 {
     if (char.ToUpper(agbm.Title[0]) != agbm.Title[0] || (agbm.Title.Length < 3 || agbm.Title.Length > 100))
     {
         return(false);
     }
     if (agbm.Price < 0 || agbm.Size < 0)
     {
         return(false);
     }
     if (agbm.Trailer.Length != 11)
     {
         return(false);
     }
     if (!agbm.ImageUrl.StartsWith("http://") && !agbm.ImageUrl.StartsWith("https://"))
     {
         return(false);
     }
     if (agbm.Description.Length < 20)
     {
         return(false);
     }
     return(true);
 }
Esempio n. 26
0
        public IActionResult Add(AddGameBindingModel model)
        {
            this.service.Add(model);

            return(this.View());
        }
Esempio n. 27
0
 public Game GetGameFromAddGameModel(AddGameBindingModel agbm)
 {
     return(Mapper.Map <AddGameBindingModel, Game>(agbm));
 }