public async Task <ActionResult> AddCreditCard([FromBody] CreateCardInputModel creditCard) { creditCard.UserId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value; string cardNumberFormatted = creditCard.CardNumber.Replace(" ", string.Empty); cardNumberFormatted = string.Format("{0:0000 0000 0000 0000}", long.Parse(cardNumberFormatted)); if (this.creditCardsService.CardExists(cardNumberFormatted)) { this.TempData.Keep(); this.TempData[GlobalErrorMessageKey] = "This card already exists! Please try again!"; this.TempData.Keep(); } else { creditCard.CardNumber = cardNumberFormatted; await this.creditCardsService.CreateAsync(creditCard); this.TempData[GlobalSuccessMessageKey] = "Card successfully added!"; } this.TempData.Keep(); return(this.RedirectToAction("Payment")); }
public HttpResponse Add(CreateCardInputModel 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("Invalid name input.Name must be between 5 and 15 characters.")); } if (string.IsNullOrWhiteSpace(model.Image)) { return(this.Error("Invalid image input.")); } if (model.Attack < 0) { return(this.Error("Attack cannot be below zero.")); } if (model.Health <= 0) { return(this.Error("Health cannot be at or below zero.")); } if (string.IsNullOrWhiteSpace(model.Description) || model.Description.Length > 200) { return(this.Error("Invalid description input.Description cann't be above 200 characters.")); } this.cardsService.Create(model); return(this.Redirect("/Cards/All")); }
public HttpResponse Add(CreateCardInputModel input) { if (input.Name?.Length < 5 || input.Name?.Length > 20) { return(this.Redirect("/Cards/Add")); } if (string.IsNullOrWhiteSpace(input.Image)) { return(this.Redirect("/Cards/Add")); } if (input.Attack < 0) { return(this.Redirect("/Cards/Add")); } if (input.Health < 0) { return(this.Redirect("/Cards/Add")); } if (string.IsNullOrWhiteSpace(input.Description) || input.Description.Length > 200) { return(this.Redirect("/Cards/Add")); } this.cardsService.CreateCard(input.Name, input.Image, input.Keyword, input.Attack, input.Health, input.Description); var newlyCreatedCard = this.cardsService.ReturnNewlyCreatedCard(input.Name); this.cardsService.AddCardToUserCollection(newlyCreatedCard.Id, this.User); return(this.Redirect("/Cards/All")); }
public async Task <ActionResult> Create(int deckId, [FromBody] CreateCardInputModel input) { var success = await this.cardsService.CreateAsync(deckId, input.Term, input.Definition); if (!success) { return(this.BadRequest()); } return(this.Ok()); }
public async Task CreateAsync(CreateCardInputModel input) { var card = new CreditCard { UserId = input.UserId, CardNumber = input.CardNumber, ExpirationDate = input.ExpirationDate, }; await this.creditCardsRepository.AddAsync(card); await this.creditCardsRepository.SaveChangesAsync(); }
public HttpResponse Add(CreateCardInputModel 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.IsNullOrEmpty(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.IsNullOrEmpty(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.IsNullOrEmpty(model.Description) || model.Description.Length > 200) { return(this.Error("Description is required and its length should be at most 200 characters.")); } var userId = this.GetUserId(); var cardId = this.cardsService.Create(model.Name, model.Image, model.Keyword, model.Attack, model.Health, model.Description); this.cardsService.AddCardToUser(cardId, userId); return(this.Redirect("/Cards/All")); }
public void Create(CreateCardInputModel model) { var card = new Card { Name = model.Name, ImageUrl = model.Image, Keyword = model.Keyword, Attack = model.Attack, Health = model.Health, Description = model.Description }; this.dbContext.Cards.Add(card); this.dbContext.SaveChanges(); }
public async Task CreditCardExistenceCheckWorksCorrectly() { var user = new ClaimsPrincipal(new ClaimsIdentity( new Claim[] { new Claim(ClaimTypes.NameIdentifier, "TestValue"), new Claim(ClaimTypes.Name, "*****@*****.**"), })); CreateCardInputModel card = GetCardInModel(user.Identity.Name); await this.service.CreateAsync(card); Assert.True(this.service.CardExists("4567465745674561")); }
public async Task AddingCreditCardWorksCorrectly() { var user = new ClaimsPrincipal(new ClaimsIdentity( new Claim[] { new Claim(ClaimTypes.NameIdentifier, "TestValue"), new Claim(ClaimTypes.Name, "*****@*****.**"), })); CreateCardInputModel card = GetCardInModel(user.Identity.Name); await this.service.CreateAsync(card); Assert.Single(this.creditCards); }
public void CreateCard(CreateCardInputModel inputModel, string userId) { var newCard = new Card { Name = inputModel.Name, ImageUrl = inputModel.Image, Keyword = inputModel.Keyword, Attack = inputModel.Attack, Health = inputModel.Health, Description = inputModel.Description }; this.db.Cards.Add(newCard); this.db.UserCards.Add(new UserCard { Card = newCard, UserId = userId }); this.db.SaveChanges(); }
public async Task <IActionResult> Create(CreateCardInputModel input) { if (!ModelState.IsValid) { return(View(input)); } var user = await this.userManager.GetUserAsync(User); if (input.ChannelName == string.Empty) { ModelState.AddModelError("ChannelName", "Channel is invalid or can't create cards"); return(View(input)); } await this.cardService.CreateAsync(input, user.Id); return(RedirectToAction("Index", new { channelName = input.ChannelName })); }
public async Task CreateAsync(CreateCardInputModel input, string userId) { var channel = this.context.Channels .FirstOrDefault(x => x.Name == input.ChannelName); if (channel == null) { return; } var userChannel = this.context.UserChannels .FirstOrDefault(x => x.ChannelId == channel.Id && x.UserId == userId); if (userChannel == null) { return; } var card = new Card() { Name = input.Name, Type = input.Type, Image = input.Image, Description = input.Description, ChannelId = channel.Id, Attack = input.Attack, Defense = input.Defense, CreatorId = userId, }; if (userChannel.Role == ChannelUserRole.User) { card.Status = CardStatus.ForReview; } else { card.Status = CardStatus.Approved; } await this.context.Cards.AddAsync(card); await this.context.SaveChangesAsync(); }
public HttpResponse Add(CreateCardInputModel inputModel) { if (!this.IsUserSignedIn()) { return(this.Redirect("/Users/Login")); } if (inputModel.Name.Length < 5 || inputModel.Name.Length > 15) { return(this.Error("The name must be between 5 and 15 characters!")); } if (inputModel.Description.Length > 200) { return(this.Error("Description have 200 characters max length.")); } if (inputModel.Attack < 0 || inputModel.Health < 0) { return(this.Error("Attack and Health cannot be negative.")); } var userId = this.GetUserId(); this.cardService.CreateCard(inputModel, userId); return(this.Redirect("/Cards/All")); }