public CardDTO CreateNewCard(string cardNumber, string cvv) { Card card; try { card = new Card(cardNumber, cvv); } catch (DomainException e) { throw new ApplicationException(e.Message); } _cardRepository.Add(card); return(MapCardToDTO(card)); }
public IHttpActionResult CreateNewCard(CreateCardViewModel vm) { if (!ModelState.IsValid) { return(BadRequest("Invalid View Model")); } try { var dbCardEntity = Mapper.Map <Card>(vm); int id = _cardRepository.Add(dbCardEntity); var createdDbCard = _cardRepository.GetById(id); return(Ok(createdDbCard)); } catch (Exception e) { _logger.Error("Could not create card. Exception Message: " + e.Message); return(BadRequest("Could not update card's status")); } }
public void CanAddCard() { var card = new Card { Name = "White Knight", CastingCost = "WW", Type = "Creature - Knight" }; ICardRepository repository = new CardRepository(); repository.Add(card); // use session to try to load the product); using (var session = _sessionFactory.OpenSession()) { var fromDb = session.Get <Card>(card.Id); // Test that the color was successfully inserted Assert.IsNotNull(fromDb); Assert.AreNotSame(card, fromDb); Assert.AreEqual(card.Name, fromDb.Name); Assert.AreEqual(card.CastingCost, fromDb.CastingCost); Assert.AreEqual(card.Type, fromDb.Type); } }
public static void Main() { var list = new List <Card>() { new Card() { SourceId = "Мельбурн", DestinationId = "Кельн" }, new Card() { SourceId = "Москва", DestinationId = "Париж" }, new Card() { SourceId = "Кельн", DestinationId = "Москва" } }; var repository = new CardRepository(); foreach (var card in list) { repository.Add(card); } var cards = repository.GetAll().ToArray(); Debug.Assert(cards.Length == 3); Debug.Assert(cards[0].SourceId == "Мельбурн"); Debug.Assert(cards[0].DestinationId == "Kельн"); Debug.Assert(cards[1].SourceId == "Kельн"); Debug.Assert(cards[1].DestinationId == "Москва"); Debug.Assert(cards[2].SourceId == "Москва"); Debug.Assert(cards[2].DestinationId == "Париж"); // The complexity of the sort algorithm would be measured as O(n + k) = O(n) }
public string AddCard(string type, string name) { cardRepository.Add(cardFactory.CreateCard(type, name)); return($"Successfully added card of type {type}Card with name: {name}"); }
public Card Post([FromBody] Card card) { return(db.Add(card)); }