Exemplo n.º 1
0
        public IActionResult <DeleteGameVM> Edit(
            HttpResponse response, HttpSession session, EditGameBM model)
        {
            if (!AuthenticationManager.IsAuthenticated(session))
            {
                this.Redirect(response, "/home/login");
                return(null);
            }

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

            if (!this.service.IsValidGameEditBM(model))
            {
                this.Redirect(response, "/game/edit");
                return(null);
            }

            this.service.UpdateGameFromBM(model);

            this.Redirect(response, "/game/admin");
            return(null);
        }
Exemplo n.º 2
0
        public void UpdateGameFromBM(EditGameBM model)
        {
            var game = this.Context.Games.Find(model.Id);

            if (game == null)
            {
                return;
            }

            game.Title          = model.Title;
            game.Description    = model.Description;
            game.Price          = model.Price;
            game.Size           = model.Size;
            game.ImageThumbnail = model.ImageThumbnail;
            game.Trailer        = model.Trailer;
            game.ReleaseDate    = model.ReleaseDate;

            this.Context.SaveChanges();
        }
Exemplo n.º 3
0
        public bool IsValidGameEditBM(EditGameBM model)
        {
            if (this.Context.Games.Find(model.Id) == null)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(model.Title) ||
                string.IsNullOrEmpty(model.Description) ||
                string.IsNullOrEmpty(model.ImageThumbnail) ||
                string.IsNullOrEmpty(model.Trailer) ||
                model.Price <= 0 ||
                model.Size <= 0)
            {
                return(false);
            }

            if (model.Title.Length > 100 ||
                model.Title.Length < 3 ||
                !model.Title[0].ToString().Equals(model.Title[0].ToString().ToUpper()))
            {
                return(false);
            }

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

            if (!Regex.IsMatch(model.ImageThumbnail, @"^(https:\/\/)|(http:\/\/).+$"))
            {
                return(false);
            }

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

            return(true);
        }