コード例 #1
0
        public IActionResult Index()
        {
            CandyModel model = new CandyModel();

            model.CandyList = _CandyRepo.GetList();
            return(View(model));
        }
コード例 #2
0
        public IActionResult Create(CandyModel model)
        {
            Candy candy = new Candy();

            candy.productName = model.CandyName;
            _CandyRepo.Insert(candy);
            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public IActionResult Index()
        {
            CandyModel model = new CandyModel
            {
                CandyList = new List <Candy>(_candyRepo.GetList())
            };

            return(View(model));
        }
コード例 #4
0
        public IActionResult Index(CandyModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            _candyRepo.Insert(model.ProductName);

            return(RedirectToAction("Index"));
        }
コード例 #5
0
        public IActionResult Delete(CandyModel model)
        {
            int id   = -1;
            var repo = new CandyDBRepository();

            foreach (var candy in repo.GetList())
            {
                if (candy.ProductName == model.ProductName)
                {
                    id = candy.Id;
                    break;
                }
            }
            if (id != -1)
            {
                repo.Delete(id);
            }

            return(RedirectToAction("Index"));
        }
コード例 #6
0
 public IActionResult Insert(CandyModel model)
 {
     new CandyDBRepository().Insert(model.ProductName);
     return(RedirectToAction("Index"));
 }