public ActionResult Create(BaseballCard baseballcard)
        {
            if (ModelState.IsValid)
            {
                baseballCardService.Create(baseballcard);
                baseballCardService.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(baseballcard);
        }
Example #2
0
        public List<BaseballCard> LoadFromFile(string filename)
        {
            BaseballCard card;
            List<BaseballCard> allCards = new List<BaseballCard>();

            if (File.Exists(filename))
            {
                using (FileStream file = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (var reader = new StreamReader(file))
                    {
                        while (!reader.EndOfStream)
                        {
                            string line = reader.ReadLine();
                            if (!String.IsNullOrEmpty(line))
                            {
                                card = new BaseballCard();

                                string[] lineArray = Regex.Split(line, ",");

                                try
                                {
                                    card.Player = lineArray[0];
                                    card.Team = lineArray[1];
                                    card.Cost = Convert.ToDecimal(lineArray[2]);
                                    allCards.Add(card);
                                }
                                catch (FormatException ex)
                                {
                                    Debug.WriteLine(ex.Message);
                                }
                            }
                        }
                    }
                }
                return SaveImport(allCards);
            }
            return null;
        }
 /// <summary>
 /// Updates BaseballCard in DBSet with information
 /// </summary>
 /// <param name="baseballCard">BaseballCard to update</param>
 public void Update(BaseballCard baseballCard)
 {
     base.Entry(baseballCard);
     SaveChanges();
 }
 /// <summary>
 /// Adds a new BaseballCard to DBSet<BaseballCard>
 /// </summary>
 /// <param name="baseballCard">BaseballCard to be added to the DBSet</param>
 public void Create(BaseballCard baseballCard)
 {
     cards.Add(baseballCard);
 }
        public void TestEditPostValidBaseballCard()
        {
            BaseballCardController controller = new BaseballCardController(mockCardRepository.Object);

            BaseballCard baseballCard = new BaseballCard() { BaseballCardId = 1, Player = "Heman has teh Powerz", Team = "shera" };

            RedirectToRouteResult result = controller.Edit(baseballCard) as RedirectToRouteResult;
            Assert.IsNotNull(result);

            BaseballCard bballCard = mockCardRepository.Object.GetAllCards()[1];
            Assert.AreEqual(bballCard.Player, baseballCard.Player);
        }
        public ActionResult Edit(BaseballCard baseballcard)
        {
            if (ModelState.IsValid)
            {
                BaseballCard EditedCard = baseballCardService.GetBaseballCard(baseballcard.BaseballCardId);

                EditedCard.Player = baseballcard.Player;
                EditedCard.Team = baseballcard.Team;
                EditedCard.Cost = baseballcard.Cost;
                baseballCardService.Update(EditedCard);
                baseballCardService.SaveChanges();
                return RedirectToAction("Index");
            }
            ModelState.AddModelError("error", "There has been an error, please try again or contact System Administrator.");
            return View(baseballcard);
        }