Пример #1
0
        public HttpResponse Add(AddCardInputModel model)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }
            if (model.Name.Length < 5 || model.Name.Length > 15 || string.IsNullOrEmpty(model.Name))
            {
                return(this.View(model));
            }
            if (model.Description.Length > 200 || string.IsNullOrEmpty(model.Description))
            {
                return(this.View(model));
            }
            if (string.IsNullOrEmpty(model.Image))
            {
                return(this.View(model));
            }
            if (string.IsNullOrEmpty(model.Keyword))
            {
                return(this.View(model));
            }
            if (model.Attack < 0)
            {
                return(this.View(model));
            }
            if (model.Health < 0)
            {
                return(this.View(model));
            }
            var userId = this.Request.SessionData["UserId"];
            var cardId = this.cardsService.AddCard(model, userId);

            return(this.Redirect("/Cards/All"));
        }
Пример #2
0
        public HttpResponse DoAdd(AddCardInputModel model)
        {
            if (!this.IsUserSignedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            if (this.Request.FormData["name"].Length < 5)
            {
                return(this.Error("Name should be at least 5 characters long."));
            }

            this.db.Cards.Add(new Card
            {
                Attack      = model.Attack,
                Health      = model.Health,
                Description = model.Description,
                Name        = model.Name,
                ImageUrl    = model.Image,
                Keyword     = model.Keyword
            });

            this.db.SaveChanges();

            return(this.Redirect("/Cards/All"));
        }
Пример #3
0
        public int AddCard(AddCardInputModel model, string userId)
        {
            var card = new Card
            {
                Name        = model.Name,
                Keyword     = model.Keyword,
                ImageUrl    = model.Image,
                Health      = model.Health,
                Attack      = model.Attack,
                Description = model.Description,
            };
            var user = this.db.Users.Find(userId);

            this.db.Cards.Add(card);
            this.db.SaveChanges();
            var userCard = new UserCard
            {
                CardId = card.Id,
                UserId = user.Id,
            };

            this.db.UsersCards.Add(userCard);
            this.db.SaveChanges();
            return(card.Id);
        }
Пример #4
0
        public HttpResponse Add(AddCardInputModel cardInputModel)
        {
            //Niki kaza da pravq tezi validacii dori i tuk v POST methodite, a ne samo v GET!!!!
            if (!this.IsUserSignedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            //var dbContext = new ApplicationDBContext(); //tova se iznacq kato vynshno dependency.

            //if (this.Request.FormData["name"].Length < 5) //veche rabotq s modela i zatowa pisha taka:
            if (string.IsNullOrEmpty(cardInputModel.Name) || cardInputModel.Name.Length < 5 || cardInputModel.Name.Length > 15)
            {
                return(this.Error($"{nameof(cardInputModel.Name)} should be between 5 and 15 characters long."));
            }

            if (string.IsNullOrWhiteSpace(cardInputModel.Image))
            {
                return(this.Error("Image url is required."));
            }

            //taka proverqwam dali mi e validen uri na image, ne me interesuva resultata ot TryCreate, zatova go davam v _:
            if (!Uri.TryCreate(cardInputModel.Image, UriKind.Absolute, out _))
            {
                return(this.Error("Image url is nto correct."));
            }

            if (string.IsNullOrWhiteSpace(cardInputModel.Keyword))
            {
                return(this.Error("Keyword is required."));
            }

            if (cardInputModel.Attack < 0)
            {
                return(this.Error("Attack shoud be non-negative integer."));
            }

            if (cardInputModel.Health < 0)
            {
                return(this.Error("Health shoud be non-negative integer."));
            }

            if (string.IsNullOrWhiteSpace(cardInputModel.Description) || cardInputModel.Description.Length > 200)
            {
                return(this.Error("Description is required and its length must be at most 200 characters."));
            }

            var cardId = this.cardsService.AddCard(cardInputModel);

            this.cardsService.AddCardToUserCollection(this.GetUserId(), cardId);

            return(this.Redirect("/Cards/All"));

            //var viewModel = new DoAddViewModel
            //{
            //    Attack = card.Attack,
            //    Health = card.Health,
            //};
            //return this.View(viewModel);
        }
Пример #5
0
        public void Add(AddCardInputModel inputModel, string userId)
        {
            if (this.db.Cards.Any(c => c.Name == inputModel.Name))
            {
                return;
            }

            var newCard = new Card
            {
                Name        = inputModel.Name,
                ImageUrl    = inputModel.Image,
                Description = inputModel.Description,
                Keyword     = inputModel.Keyword,
                Attack      = inputModel.Attack,
                Health      = inputModel.Health,
            };

            this.db.Cards.Add(newCard);
            this.db.UserCards.Add(new UserCard
            {
                Card   = newCard,
                UserId = userId
            });

            this.db.SaveChanges();
        }
Пример #6
0
        public HttpResponse DoAdd(AddCardInputModel model)
        {
            if (!IsUserSignedIn())
            {
                return(Redirect("/users/login"));
            }

            if (model.Name.Length < 5)
            {
                return(Error("Name should be at least 5 characters long."));
            }

            db.Cards.Add(new Card
            {
                Attack      = model.Attack,
                Health      = model.Health,
                Description = model.Description,
                Name        = model.Name,
                ImageUrl    = model.Image,
                Keyword     = model.Keyword,
            });

            db.SaveChanges();

            var viewModel = new DoAddViewModel
            {
                Attack = model.Attack,
                Health = model.Health,
            };

            return(View(viewModel));
        }
Пример #7
0
        public HttpResponse Add(AddCardInputModel model)
        {
            if (!IsUserSignedIn())
            {
                return(Redirect("/Users/Login"));
            }

            //var dbContext = new ApplicationDbContext(); The dependency inversion principle is not observed! All we need, must be filled in the constructor!

            if (string.IsNullOrEmpty(model.Name) || model.Name.Length < 5 || model.Name.Length > 15)
            {
                return(Error("Name should be between 5 and 15 character long."));
            }

            if (string.IsNullOrWhiteSpace(model.Image))
            {
                return(Error("The image is required."));
            }

            if (!Uri.TryCreate(model.Image, UriKind.Absolute, out _))
            {
                return(Error("Image url is not valid."));
            }

            if (string.IsNullOrWhiteSpace(model.Keyword))
            {
                return(Error("The Keyword is required."));
            }

            if (model.Attack < 0)
            {
                return(Error("Attack must be positive number."));
            }

            if (model.Health < 0)
            {
                return(Error("Health must be positive number."));
            }

            if (string.IsNullOrWhiteSpace(model.Description) ||
                model.Description.Length > 200)
            {
                return(Error("Description must be between 1 and 200 characters."));
            }

            var cardId = cardService.AddCard(model);

            var userId = GetUserId();

            cardService.AddCardToCollection(cardId, userId);

            return(Redirect("/Cards/All"));
        }
Пример #8
0
        public HttpResponse Add(AddCardInputModel model)
        {
            if (!this.IsUserSignedIn())
            {
                return(this.Redirect("/"));
            }

            if (string.IsNullOrEmpty(model.Name) ||
                model.Name.Length < 5 ||
                model.Name.Length > 15)
            {
                return(this.Error("Name should be between 5 and 15 characters long."));
            }

            if (string.IsNullOrWhiteSpace(model.Image))
            {
                return(this.Error("The image is required."));
            }

            if (!Uri.TryCreate(model.Image, UriKind.Absolute, out _))
            {
                return(this.Error("Image url should be valid."));
            }

            if (string.IsNullOrWhiteSpace(model.Keyword))
            {
                return(this.Error("Keyword is required"));
            }

            if (model.Attack < 0)
            {
                return(this.Error("Attack should be non-negative integer."));
            }

            if (model.Health < 0)
            {
                return(this.Error("Health should be non-negative integer."));
            }

            if (string.IsNullOrWhiteSpace(model.Description) || model.Description.Length > 200)
            {
                return(this.Error("Description is required and its length should be at most 200 characters"));
            }

            var cardId = this.cardService.AddCard(model);

            var userId = this.GetUserId();

            this.cardService.AddCardToUserCollection(userId, cardId);

            return(this.Redirect("/Cards/All"));
        }
Пример #9
0
        public HttpResponse Add(AddCardInputModel input)
        {
            if (!this.IsUserSignedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            if (string.IsNullOrWhiteSpace(input.Name) || input.Name.Length < 5 || input.Name.Length > 15)
            {
                return(this.Redirect("/Cards/Add"));
            }

            if (string.IsNullOrWhiteSpace(input.Image))
            {
                return(this.Redirect("/Cards/Add"));
            }

            if (string.IsNullOrWhiteSpace(input.Keyword))
            {
                return(this.Redirect("/Cards/Add"));
            }

            if (string.IsNullOrWhiteSpace(input.Description) || input.Description.Length > 200)
            {
                return(this.Redirect("/Cards/Add"));
            }

            if (input.Attack < 0)
            {
                return(this.Redirect("/Cards/Add"));
            }

            if (input.Health < 0)
            {
                return(this.Redirect("/Cards/Add"));
            }

            if (!Uri.TryCreate(input.Image, UriKind.Absolute, out _))
            {
                return(this.Redirect("/Cards/Add"));
            }

            var cardId = this.cardsService.AddCard(input.Name, input.Description, input.Keyword, input.Image, input.Attack, input.Health);

            var userId = this.GetUserId();

            this.cardsService.AddToCollection(cardId, userId);

            return(this.Redirect("/Cards/All"));
        }
Пример #10
0
        public HttpResponse Add(AddCardInputModel model)
        {
            if (!IsUserSignIn())
            {
                return(Error("You don't have permission to access this page."));
                //return Redirect("/Users/Login");
            }

            if (string.IsNullOrWhiteSpace(model.Name) || (model.Name.Length < 5 ||
                                                          model.Name.Length > 15))
            {
                return(Error("Name should be between 5 and 15 characters long."));
            }

            if (string.IsNullOrWhiteSpace(model.Image))
            {
                return(Error("The image is required!"));
            }

            if (!Uri.TryCreate(model.Image, UriKind.Absolute, out _))
            {
                return(Error("Image url should be valied."));
            }

            if (string.IsNullOrWhiteSpace(model.Keyword))
            {
                return(Error("The Keyword is required!"));
            }

            if (model.Attack < 0)
            {
                return(Error("Atack should be non-negative integer."));
            }

            if (model.Health < 0)
            {
                return(Error("Health should be non-negative integer."));
            }

            if (string.IsNullOrWhiteSpace(model.Description) && model.Description.Length > 200)
            {
                return(Error("The Description is required and its length should be at most 200 characters"));
            }

            var cardId = this.cardsService.AddCard(model);

            return(AddToCollection(cardId));

            //return Redirect("/Cards/All");
        }
Пример #11
0
        public HttpResponse Add(AddCardInputModel model)
        {
            if (!IsUserSignedIn())
            {
                return(Redirect("/users/login"));
            }

            if (string.IsNullOrEmpty(model.Name) || model.Name.Length < 5 || model.Name.Length > 15)
            {
                return(Error("Name should be between 5 and 15 characters long."));
            }

            if (string.IsNullOrWhiteSpace(model.Image))
            {
                return(Error("The image is required!"));
            }

            if (string.IsNullOrWhiteSpace(model.Keyword))
            {
                return(Error("Keyword is required."));
            }

            if (model.Attack < 0)
            {
                return(Error("Attack should be non-negative integer."));
            }

            if (model.Health < 0)
            {
                return(Error("Health should be non-negative integer."));
            }

            if (string.IsNullOrWhiteSpace(model.Description) || model.Description.Length > 200)
            {
                return(Error("Description is required and its length should be at most 200 characters."));
            }

            var cardId = cardsService.AddCard(model);
            var userId = GetUserId();

            cardsService.AddCardToUserCollection(userId, cardId);

            var viewModel = new DoAddViewModel
            {
                Attack = model.Attack,
                Health = model.Health,
            };

            return(View(viewModel));
        }
Пример #12
0
        public HttpResponse Add(AddCardInputModel input)
        {
            if (!this.IsUserSignedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            if (string.IsNullOrWhiteSpace(input.Name) || input.Name.Length < 5 || input.Name.Length > 15)
            {
                return(this.Error("Name should be between 5 and 15 characters long!"));
            }

            if (string.IsNullOrWhiteSpace(input.Image))
            {
                return(this.Error("Image is required!"));
            }

            if (!Uri.TryCreate(input.Image, UriKind.Absolute, out _))
            {
                return(this.Error("Image url is invalid!"));
            }

            if (string.IsNullOrWhiteSpace(input.Keyword))
            {
                return(this.Error("Keyword is required!"));
            }

            if (input.Attack < 0)
            {
                return(this.Error("Attack should be positive number!"));
            }

            if (input.Health < 0)
            {
                return(this.Error("Health should be positive number!"));
            }

            if (string.IsNullOrWhiteSpace(input.Description) || input.Description.Length > 200)
            {
                return(this.Error("Description is required! Max 200 symbols alowed."));
            }

            var cardId = this.cardService.AddCard(input);

            var userId = this.GetUserId();

            this.cardService.AddCardToUserCollection(userId, cardId);
            return(this.Redirect("/Cards/All"));
        }
Пример #13
0
        public HttpResponse Add(AddCardInputModel model)
        {
            if (!this.IsUserSignedIn())
            {
                return(this.Redirect("/users/login"));
            }

            if (string.IsNullOrEmpty(model.Name) || model.Name.Length < 5 || model.Name.Length > 15)
            {
                return(this.Error("Name should be between 5 and 15 characters long."));
            }

            if (string.IsNullOrWhiteSpace(model.Image))
            {
                return(this.Error("ImageUrl is required."));
            }

            if (!Uri.TryCreate(model.Image, UriKind.Absolute, out _))
            {
                return(this.Error("Url is not valid"));
            }

            if (string.IsNullOrWhiteSpace(model.Keyword))
            {
                return(this.Error("Keyword is required."));
            }

            if (model.Attack < 0)
            {
                return(this.Error("Attack should be non negative integer"));
            }

            if (model.Health < 0)
            {
                return(this.Error("Health should be non negative integer"));
            }

            if (string.IsNullOrWhiteSpace(model.Description) || model.Description.Length > 200)
            {
                return(this.Error("Description should be between 1 and 200 characters long."));
            }

            var cardId = this.cardsService.AddCard(model);

            this.cardsService.AddCardToUserCollection(this.GetUserId(), cardId);

            return(this.Redirect("/cards/all"));
        }
        public HttpResponse Add(AddCardInputModel model)
        {
            if (!this.IsUserSignedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            if (string.IsNullOrWhiteSpace(model.Name) || model.Name.Length < 5 || model.Name.Length > 15)
            {
                return(this.Error("Name is reequired and should be between 5 and 15 characters!"));
            }

            if (string.IsNullOrWhiteSpace(model.Image))
            {
                return(this.Error("ImageUrl is required!"));
            }

            if (!Uri.TryCreate(model.Image, UriKind.Absolute, out _))
            {
                return(this.Error("Image url should be valid."));
            }

            if (string.IsNullOrWhiteSpace(model.Keyword))
            {
                return(this.Error("Keyword is required!"));
            }

            if (model.Attack < 0)
            {
                return(this.Error("Attack must be positive number!"));
            }

            if (model.Health < 0)
            {
                return(this.Error("Health must be positive number!"));
            }

            if (string.IsNullOrWhiteSpace(model.Description))
            {
                return(this.Error("Description is required and should be less than 200 characters!"));
            }

            int cardId = this.cardsService.AddCard(model);

            this.AddToCollection(cardId);

            return(this.Redirect("/Cards/All"));
        }
Пример #15
0
        public int AddCard(AddCardInputModel inputModel)
        {
            var card = new Card
            {
                Attack      = inputModel.Attack,
                Description = inputModel.Description,
                Health      = inputModel.Health,
                ImageUrl    = inputModel.Image,
                Keyword     = inputModel.Keyword,
                Name        = inputModel.Name,
            };

            this.db.Cards.Add(card);
            this.db.SaveChanges();
            return(card.Id);
        }
Пример #16
0
        public int AddCard(AddCardInputModel input)
        {
            var card = new Card
            {
                Attack      = input.Attack,
                Health      = input.Health,
                Description = input.Description,
                Name        = input.Name,
                ImageUrl    = input.Image,
                Keyword     = input.Keyword,
            };

            db.Cards.Add(card);
            db.SaveChanges();

            return(card.Id);
        }
        public int AddCard(AddCardInputModel input)
        {
            Card card = new Card
            {
                Name        = input.Name,
                ImageUrl    = input.Image,
                Keyword     = input.Keyword,
                Description = input.Description,
                Attack      = input.Attack,
                Health      = input.Health
            };

            this.dbContext.Cards.Add(card);
            this.dbContext.SaveChanges();

            return(card.Id);
        }
Пример #18
0
        public int AddCard(AddCardInputModel model)
        {
            var card = new Card
            {
                Attack      = model.Attack,
                Health      = model.Health,
                Description = model.Description,
                Name        = model.Name,
                ImageUrl    = model.Image,
                Keyword     = model.Keyword,
            };

            db.Cards.Add(card);
            db.SaveChanges();

            return(card.Id);
        }
Пример #19
0
        public HttpResponse Add(AddCardInputModel inputModel)
        {
            if (inputModel.Name.Length < 5 || inputModel.Name.Length > 15)
            {
                return(this.Error("Invalid card name."));
            }

            if (string.IsNullOrWhiteSpace(inputModel.Image))
            {
                return(this.Error("Invalid Image."));
            }

            if (string.IsNullOrWhiteSpace(inputModel.Keyword))
            {
                return(this.Error("Invalid Keyword."));
            }

            if (inputModel.Attack < 0)
            {
                return(this.Error("Attack doesn't can be negative value."));
            }

            if (inputModel.Health < 0)
            {
                return(this.Error("Health doesn't can be negative value."));
            }

            if (inputModel.Description.Length > 200)
            {
                return(this.Error("Description cannot be very long length."));
            }

            var userId = this.GetUserId();

            this.cardsService.Add(inputModel, userId);
            return(this.Redirect("/Cards/All"));
        }